add:添加可以直接send文件而非必须提交一个任务文件。

This commit is contained in:
taynpg 2025-03-28 22:56:23 +08:00
parent 4c4eaf8734
commit 6559569f38
2 changed files with 81 additions and 1 deletions

View File

@ -126,6 +126,10 @@ void CClient::run(const std::string& ip, const std::string& port, const std::str
request_update_list(param);
continue;
}
if (scmd == "Send" || scmd == "send") {
send_files(param);
continue;
}
if (scmd == "Down" || scmd == "down") {
down_task(param);
continue;
@ -195,7 +199,6 @@ bool CClient::down_task(const std::string& param)
bool CClient::up_task(const std::string& param)
{
{
std::lock_guard<std::mutex> lock(mutex_);
for (const auto& item : up_) {
@ -263,6 +266,82 @@ bool CClient::cancel_task()
return send_frame(buf.get());
}
bool CClient::send_files(const std::string& param)
{
auto tvec = COfStr::split(param, " ");
if (tvec.size() < 3) {
TLOGE("{} invalid param format [{}]", __FUNCTION__, param);
return false;
}
int index = std::stoi(tvec[0]);
std::string list_file = tvec[1];
std::string pur = tvec[2];
if (downloading_) {
TLOGW("Have Task Downloading, Please wait.....");
return false;
}
if (!task_list_.count(index)) {
TLOGE("No Index Found {}.", index);
return false;
}
const auto& sr = task_list_[index];
if (sr->id == own_id_) {
TLOGW("You can't send file to yourself!!!");
return false;
}
// 校验格式是否正确
auto vec = COfStr::split(list_file, "|");
bool valid = true;
int line = 1;
std::unordered_map<int, std::string> mre{};
std::string handled_content;
for (const auto& item : vec) {
std::string hitem = COfStr::trim(item);
if (hitem.empty()) {
continue;
}
auto real_path = COfPath::to_full(hitem);
if (!fs::exists(real_path)) {
TLOGE("file {} not exist.", real_path);
valid = false;
break;
}
TLOGI("--->check pass {}:{}", line, real_path);
mre[line++] = real_path + "|" + pur;
}
if (!valid) {
TLOGE("Judge File Not Passed.");
return false;
}
auto handel_ret = handle_user_select(mre);
if (handel_ret.empty()) {
TLOGE("handle_user_select not pass, abort action!");
return false;
}
#if defined(_WIN32)
handel_ret = CCodec::ansi_to_u8(handel_ret);
#endif
list_file_ = "auto_list";
std::shared_ptr<CFrameBuffer> buf = std::make_shared<CFrameBuffer>();
buf->type_ = TYPE_REQUEST_UPDATE_LIST;
buf->data_ = new char[handel_ret.size() + 1]();
buf->len_ = std::snprintf(buf->data_, handel_ret.size() + 1, "%s", handel_ret.c_str());
buf->tid_ = task_list_[index]->id;
if (!send_frame(buf.get())) {
TLOGE("Send Failed {}", __LINE__);
return false;
}
return true;
}
bool CClient::down_one_file(const std::string& id, const std::string& file, const std::string& local_dir)
{
std::string back_file(file);

View File

@ -51,6 +51,7 @@ public:
bool down_task(const std::string& param);
bool up_task(const std::string& param);
bool cancel_task();
bool send_files(const std::string& param);
bool down_one_file(const std::string& id, const std::string& file, const std::string& local_dir = "");
void report_trans_ret(TransState state, const std::string& key = "");
bool request_update_list(const std::string& param);