|
|
@@ -152,6 +152,42 @@ void DealHttpPost(const httplib::Request& req, httplib::Response& res)
|
|
|
if (json) free(json);
|
|
|
}
|
|
|
|
|
|
+void DealHttpPut(const httplib::Request& req, httplib::Response& res)
|
|
|
+{
|
|
|
+ int code = 500;
|
|
|
+ auto start = chrono::steady_clock::now();
|
|
|
+ auto token = req.get_header_value("token");
|
|
|
+ if (token.length() == 0 || token.empty())
|
|
|
+ token = req.get_header_value("Authorization");
|
|
|
+ char* json = nullptr;
|
|
|
+ size_t json_len = 0;
|
|
|
+ SPDLOG_INFO("[HTTP][POST][START] {}:{} {} body:{}", req.remote_addr, req.remote_port, req.path, req.body);
|
|
|
+ try
|
|
|
+ {
|
|
|
+ if (token.empty())
|
|
|
+ {
|
|
|
+ code = 401;
|
|
|
+ }
|
|
|
+ if (req.path.find("/data/zzjno") != -1)
|
|
|
+ code = DealPutChangeZzjno(req.body.c_str(), req.body.length(), token, &json, &json_len);
|
|
|
+ else
|
|
|
+ code = 405;
|
|
|
+ }
|
|
|
+ catch (...)
|
|
|
+ {
|
|
|
+ code = 500;
|
|
|
+ }
|
|
|
+ if (json)
|
|
|
+ res.set_content(json, "application/json");
|
|
|
+
|
|
|
+ auto cost = chrono::duration_cast<chrono::milliseconds>(chrono::steady_clock::now() - start).count();
|
|
|
+ SPDLOG_INFO("[HTTP][POST][END] code:{} COST:{} {}:{} {} body:{}", code, cost, req.remote_addr, req.remote_port, req.path, req.body);
|
|
|
+ res.set_header("cost", to_string(cost) + " ms");
|
|
|
+ res.status = code;
|
|
|
+
|
|
|
+ if (json) free(json);
|
|
|
+}
|
|
|
+
|
|
|
int DealPostSvgData(const httplib::Request& req, const string token, httplib::Response& res)
|
|
|
{
|
|
|
if (token.find("AAAAAAAA") == -1) return 403;
|
|
|
@@ -2344,6 +2380,29 @@ int DealGetResistData(const httplib::Request& req, const string token, char** js
|
|
|
return 200;
|
|
|
}
|
|
|
|
|
|
+int DealPutChangeZzjno(const char* body_ptr, const size_t body_len, const string token, char** json, size_t* json_len)
|
|
|
+{
|
|
|
+ int code = 400;
|
|
|
+ string msg;
|
|
|
+ auto req_doc = yyjson_read(body_ptr, body_len, 0);
|
|
|
+ if (req_doc == nullptr) return 400;
|
|
|
+ auto req_root = yyjson_doc_get_root(req_doc);
|
|
|
+ do
|
|
|
+ {
|
|
|
+ auto mo = yyjson_get_str(yyjson_obj_get(req_root, "mo"));
|
|
|
+ auto mp = yyjson_get_str(yyjson_obj_get(req_root, "mp"));
|
|
|
+ auto newNumber = yyjson_get_int(yyjson_obj_get(req_root, "newNumber"));
|
|
|
+ if (mo == nullptr || mp == nullptr || newNumber == 0) break;
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ code = 200;
|
|
|
+ } while (false);
|
|
|
+
|
|
|
+ return code;
|
|
|
+}
|
|
|
+
|
|
|
//int DealGetRetentionData(const httplib::Request& req, const string token, char** json, size_t* json_len)
|
|
|
//{
|
|
|
// string mo = req.get_param_value("mo");
|