|
@@ -8,6 +8,7 @@
|
|
|
FileServer::FileServer(QObject *parent)
|
|
FileServer::FileServer(QObject *parent)
|
|
|
: QObject{parent}
|
|
: QObject{parent}
|
|
|
{
|
|
{
|
|
|
|
|
+ moveToThread(&m_thread);
|
|
|
connect(&m_thread, &QThread::started, this, &FileServer::run_hhttp_sever);
|
|
connect(&m_thread, &QThread::started, this, &FileServer::run_hhttp_sever);
|
|
|
run("0.0.0.0", 18000);
|
|
run("0.0.0.0", 18000);
|
|
|
}
|
|
}
|
|
@@ -64,11 +65,11 @@ void FileServer::run_hhttp_sever()
|
|
|
|
|
|
|
|
// 画面配置文件更新接口
|
|
// 画面配置文件更新接口
|
|
|
m_server.Post("/update/monitor", [&](const httplib::Request &req, httplib::Response &res, const httplib::ContentReader &content_reader) {
|
|
m_server.Post("/update/monitor", [&](const httplib::Request &req, httplib::Response &res, const httplib::ContentReader &content_reader) {
|
|
|
|
|
+ QJsonDocument doc;
|
|
|
if (req.is_multipart_form_data()) {
|
|
if (req.is_multipart_form_data()) {
|
|
|
// NOTE: `content_reader` is blocking until every form data field is read
|
|
// NOTE: `content_reader` is blocking until every form data field is read
|
|
|
// This approach allows streaming processing of large files
|
|
// This approach allows streaming processing of large files
|
|
|
std::vector<httplib::FormData> items;
|
|
std::vector<httplib::FormData> items;
|
|
|
- QJsonDocument doc;
|
|
|
|
|
content_reader(
|
|
content_reader(
|
|
|
[&](const httplib::FormData &item) {
|
|
[&](const httplib::FormData &item) {
|
|
|
items.push_back(item);
|
|
items.push_back(item);
|
|
@@ -112,7 +113,7 @@ void FileServer::run_hhttp_sever()
|
|
|
ofs.write(item.content.data(), item.content.size());
|
|
ofs.write(item.content.data(), item.content.size());
|
|
|
ofs.close();
|
|
ofs.close();
|
|
|
LOG_INFO("monitor configure file successfully update");
|
|
LOG_INFO("monitor configure file successfully update");
|
|
|
- emit monitorConfigureUpdate();
|
|
|
|
|
|
|
+ emit monitorConfigureUpdate(filename);
|
|
|
|
|
|
|
|
QJsonObject obj = {
|
|
QJsonObject obj = {
|
|
|
{"message", QString("'File successfully update")}
|
|
{"message", QString("'File successfully update")}
|
|
@@ -124,11 +125,19 @@ void FileServer::run_hhttp_sever()
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
} else {
|
|
} else {
|
|
|
- std::string body;
|
|
|
|
|
- content_reader([&](const char *data, size_t data_length) {
|
|
|
|
|
- body.append(data, data_length);
|
|
|
|
|
- return true;
|
|
|
|
|
- });
|
|
|
|
|
|
|
+ // std::string body;
|
|
|
|
|
+ // content_reader([&](const char *data, size_t data_length) {
|
|
|
|
|
+ // body.append(data, data_length);
|
|
|
|
|
+ // return true;
|
|
|
|
|
+ // });
|
|
|
|
|
+
|
|
|
|
|
+ QJsonObject obj = {
|
|
|
|
|
+ {"message", QString("File error")}
|
|
|
|
|
+ };
|
|
|
|
|
+ doc.setObject(obj);
|
|
|
|
|
+
|
|
|
|
|
+ res.status = httplib::StatusCode::BadRequest_400;
|
|
|
|
|
+ res.set_content(doc.toJson().data(), "application/json");
|
|
|
}
|
|
}
|
|
|
});
|
|
});
|
|
|
|
|
|