Return error if path not exists when sending image and file.

This commit is contained in:
Changhua 2024-02-19 20:08:22 +08:00
parent 6bc96c58d2
commit aa3703e9f5

View File

@ -2,6 +2,7 @@
#include <chrono>
#include <condition_variable>
#include <filesystem>
#include <memory>
#include <mutex>
#include <queue>
@ -37,6 +38,8 @@
#define BASE_URL "tcp://0.0.0.0"
#define G_BUF_SIZE (16 * 1024 * 1024)
namespace fs = std::filesystem;
extern int IsLogin(void); // Defined in spy.cpp
bool gIsListening = false;
@ -251,6 +254,9 @@ bool func_send_img(char *path, char *receiver, uint8_t *out, size_t *len)
if ((path == NULL) || (receiver == NULL)) {
LOG_ERROR("Empty path or receiver.");
rsp.msg.status = -1;
} else if (!fs::exists(path)) {
LOG_ERROR("Path does not exists: {}", path);
rsp.msg.status = -2;
} else {
SendImageMessage(receiver, path);
rsp.msg.status = 0;
@ -275,6 +281,9 @@ bool func_send_file(char *path, char *receiver, uint8_t *out, size_t *len)
if ((path == NULL) || (receiver == NULL)) {
LOG_ERROR("Empty path or receiver.");
rsp.msg.status = -1;
} else if (!fs::exists(path)) {
LOG_ERROR("Path does not exists: {}", path);
rsp.msg.status = -2;
} else {
SendImageMessage(receiver, path);
rsp.msg.status = 0;