修复bug

This commit is contained in:
2026-08-09 19:33:53 +08:00
parent b9a86e0e6b
commit 892cb881d2
2 changed files with 43 additions and 9 deletions
@@ -2,6 +2,9 @@
#include "../Data_Source/Database.h"
#include <iomanip>
#include <sstream>
// https://wiki.jetvision.de/wiki/Radarcape:Software_Features#Aircraft_List_JSON_Service
struct Aircraft_List_JSON_Service_O {
size_t times; //自定义添加出现的次数 用于显示的优先级
@@ -56,7 +59,7 @@ struct Aircraft_List_JSON_Service_O {
RET<size_t> nocl; // Number of sensors providing data aircraft
RET<std::string> tq; // Time quality of this entry
static Psc::JSON view_model() {
static Psc::JSON build_view_model() {
auto columns = Psc::JSON::array();
const auto add_column = [&columns](const char* key, const char* label, const char* type,
const char* default_sort_order = nullptr,
@@ -149,6 +152,35 @@ struct Aircraft_List_JSON_Service_O {
return model;
}
static constexpr std::uint32_t view_model_schema_version = 1;
static const std::string& view_model_schema_hash() {
static const std::string hash = [] {
auto model = build_view_model();
model.append({"schema_version", view_model_schema_version});
const auto serialized = model.to_json_string();
std::uint64_t value = 14695981039346656037ull;
for(const unsigned char byte : serialized) {
value ^= byte;
value *= 1099511628211ull;
}
std::ostringstream stream;
stream << std::hex << std::setfill('0') << std::setw(16) << value;
return stream.str();
}();
return hash;
}
static const Psc::JSON& view_model() {
static const Psc::JSON model = [] {
auto value = build_view_model();
value.append({"schema_version", view_model_schema_version});
value.append({"schema_hash", view_model_schema_hash()});
return value;
}();
return model;
}
Psc::JSON toJson() {
auto ret = Psc::JSON::object();
ADD_Json(times);
+10 -8
View File
@@ -606,6 +606,7 @@ void database_server(Global *g) {
CHECK_JSON_PARAM
auto g = Global::instance();
const auto include_model = params.try_get_bool("include_model").value_or(false);
const auto client_schema_hash = params.try_get_string("schema_hash").value_or("");
HTTP_REQUIRE_VALUE(data_source_key,
params.try_get_string("data_source_key"))
std::shared_ptr<Data_Source> db;
@@ -635,16 +636,17 @@ void database_server(Global *g) {
{
Scope_Timer timer("aircraft_list.json_serialization",
g->http_monitor_config.slow_scope_threshold_ms);
if (include_model) {
auto data = JSON::object();
data.append({"items", std::move(ret)});
auto response = JSON::object();
auto data = JSON::object();
data.append({"items", std::move(ret)});
auto response = JSON::object();
const auto& schema_hash = Aircraft_List_JSON_Service_O::view_model_schema_hash();
response.append({"schema_version", Aircraft_List_JSON_Service_O::view_model_schema_version});
response.append({"schema_hash", schema_hash});
if (include_model || client_schema_hash != schema_hash) {
response.append({"model", Aircraft_List_JSON_Service_O::view_model()});
response.append({"data", std::move(data)});
body = response.to_json_string();
} else {
body = warp(ret).to_json_string();
}
response.append({"data", std::move(data)});
body = response.to_json_string();
}
res->setBody(body);
});