add interface
This commit is contained in:
@@ -979,45 +979,49 @@ void process_received_message(string mac, string id,const char* data, size_t len
|
||||
|
||||
//调试用
|
||||
// 若是 .cfg,先查看并打印内容(限长)
|
||||
{
|
||||
auto dot = file_path.find_last_of('.');
|
||||
std::string ext = (dot == std::string::npos) ? "" : file_path.substr(dot);
|
||||
// 转小写比较
|
||||
for (auto& c : ext) c = static_cast<char>(std::tolower(static_cast<unsigned char>(c)));
|
||||
if (ext == ".cfg") {
|
||||
std::ifstream fin(file_path, std::ios::binary);
|
||||
if (!fin) {
|
||||
std::cerr << "[CFG] open failed: " << file_path << " (" << std::strerror(errno) << ")\n";
|
||||
} else {
|
||||
// 读取前 8KB 作为预览,避免日志过大
|
||||
constexpr size_t kMaxPreview = 8 * 1024;
|
||||
std::string buf;
|
||||
buf.resize(kMaxPreview);
|
||||
fin.read(&buf[0], static_cast<std::streamsize>(kMaxPreview));
|
||||
std::streamsize got = fin.gcount();
|
||||
buf.resize(static_cast<size_t>(got));
|
||||
|
||||
std::cout << "================ [CFG PREVIEW BEGIN] ================\n";
|
||||
std::cout << "path=" << file_path << ", size=" << file_data.size()
|
||||
<< " bytes, preview=" << got << " bytes\n";
|
||||
// 直接打印文本预览;如果包含不可见字符,会按原样输出
|
||||
std::cout.write(buf.data(), static_cast<std::streamsize>(buf.size()));
|
||||
if (static_cast<size_t>(got) == kMaxPreview && fin.peek() != EOF) {
|
||||
std::cout << "\n...[truncated]\n";
|
||||
}
|
||||
std::cout << "\n================ [CFG PREVIEW END] ==================\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
{
|
||||
auto dot = file_path.find_last_of('.');
|
||||
std::string ext = (dot == std::string::npos) ? "" : file_path.substr(dot);
|
||||
// 转小写比较
|
||||
for (auto& c : ext) c = static_cast<char>(std::tolower(static_cast<unsigned char>(c)));
|
||||
if (ext == ".cfg") {
|
||||
std::ifstream fin(file_path, std::ios::binary);
|
||||
if (!fin) {
|
||||
std::cerr << "[CFG] open failed: " << file_path << " (" << std::strerror(errno) << ")\n";
|
||||
} else {
|
||||
// 读取前 8KB 作为预览,避免日志过大
|
||||
constexpr size_t kMaxPreview = 8 * 1024;
|
||||
std::string buf;
|
||||
buf.resize(kMaxPreview);
|
||||
fin.read(&buf[0], static_cast<std::streamsize>(kMaxPreview));
|
||||
std::streamsize got = fin.gcount();
|
||||
buf.resize(static_cast<size_t>(got));
|
||||
|
||||
std::cout << "================ [CFG PREVIEW BEGIN] ================\n";
|
||||
std::cout << "path=" << file_path << ", size=" << file_data.size()
|
||||
<< " bytes, preview=" << got << " bytes\n";
|
||||
// 直接打印文本预览;如果包含不可见字符,会按原样输出
|
||||
std::cout.write(buf.data(), static_cast<std::streamsize>(buf.size()));
|
||||
if (static_cast<size_t>(got) == kMaxPreview && fin.peek() != EOF) {
|
||||
std::cout << "\n...[truncated]\n";
|
||||
}
|
||||
std::cout << "\n================ [CFG PREVIEW END] ==================\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//使用接口上送文件lnk20250826
|
||||
std::string filename;
|
||||
//SendFileWebAuto(id, file_path, file_path, filename);//如果是补招文件的下载,下载后也是直接上传,这样单纯补招波形也可以保证传文件
|
||||
std::cout << "File download success wait for upload: " << filename << std::endl;
|
||||
|
||||
//通知文件上传
|
||||
on_device_response_minimal(static_cast<int>(ResponseCode::OK), id, 0, static_cast<int>(DeviceState::READING_FILEDATA));
|
||||
if(SendFileWebAuto(id, file_path, file_path, filename)){//如果是补招文件的下载则不会在这边上送
|
||||
std::cout << "File upload success: " << filename << std::endl;
|
||||
|
||||
//通知文件上传
|
||||
on_device_response_minimal(static_cast<int>(ResponseCode::OK), id, 0, static_cast<int>(DeviceState::READING_FILEDATA));
|
||||
}
|
||||
else{
|
||||
on_device_response_minimal(static_cast<int>(ResponseCode::BAD_REQUEST), id, 0, static_cast<int>(DeviceState::READING_FILEDATA));
|
||||
std::cerr << "File download success but upload failed: " << filename << std::endl;
|
||||
}
|
||||
}
|
||||
else {
|
||||
on_device_response_minimal(static_cast<int>(ResponseCode::INTERNAL_ERROR), id, 0, static_cast<int>(DeviceState::READING_FILEDATA));
|
||||
|
||||
Reference in New Issue
Block a user