From 892cb881d2fd2a24e6b527eab21883d9bb1bdcd4 Mon Sep 17 00:00:00 2001 From: wyc <1104749580@qq.com> Date: Sun, 9 Aug 2026 19:33:53 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dbug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Local_Server/Aircraft/aircraftlist_json.h | 34 ++++++++++++++++++- module/Local_Server/Data_Source/Database.cpp | 18 +++++----- 2 files changed, 43 insertions(+), 9 deletions(-) diff --git a/module/Local_Server/Aircraft/aircraftlist_json.h b/module/Local_Server/Aircraft/aircraftlist_json.h index 123e1f1..9a95aab 100644 --- a/module/Local_Server/Aircraft/aircraftlist_json.h +++ b/module/Local_Server/Aircraft/aircraftlist_json.h @@ -2,6 +2,9 @@ #include "../Data_Source/Database.h" +#include +#include + // 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 nocl; // Number of sensors providing data aircraft RET 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); diff --git a/module/Local_Server/Data_Source/Database.cpp b/module/Local_Server/Data_Source/Database.cpp index a384e18..b0c2fb3 100644 --- a/module/Local_Server/Data_Source/Database.cpp +++ b/module/Local_Server/Data_Source/Database.cpp @@ -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 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); });