优化了 还是卡

This commit is contained in:
2026-08-25 20:43:33 +08:00
parent 5437b1b267
commit 4f3430e3ad
40 changed files with 1575 additions and 760 deletions
+16 -3
View File
@@ -3,6 +3,7 @@
#include "Gallery_WebSocket.hpp"
#include "Graph_WebSocket.hpp"
#include "Gallery_Plots.hpp"
#include "Page_Session.hpp"
#include <drogon/drogon.h>
#include <nlohmann/json.hpp>
#include <algorithm>
@@ -175,24 +176,36 @@ int run_web_server(std::uint16_t port, const std::filesystem::path& asset_root)
};
add_media_groups("2d", std::move(gallery_2d));
add_media_groups("3d", std::move(gallery_3d));
auto page_session = std::make_shared<Page_Session>();
auto resolve_plot = [plots](std::string_view id) { return find_plot(*plots, id); };
auto websocket = std::make_shared<Graph_WebSocket_Controller>(resolve_plot);
auto websocket = std::make_shared<Graph_WebSocket_Controller>(
resolve_plot, page_session);
auto gallery_websocket = std::make_shared<Gallery_WebSocket_Controller>(
[gallery_streams](std::string_view id) {
const auto found = gallery_streams->find(std::string{id});
return found == gallery_streams->end() ? nullptr : found->second;
});
}, page_session);
auto& app = drogon::app();
app.registerHandler("/page/session", [page_session](
const drogon::HttpRequestPtr&,
std::function<void(const drogon::HttpResponsePtr&)>&& callback) {
callback(json_response({
{"protocol", "aethera.page.session"},
{"version", 1},
{"token", page_session->begin_page()}}));
}, {drogon::Post});
app.registerHandler("/plot", [plots, plot_media](const drogon::HttpRequestPtr&,
std::function<void(const drogon::HttpResponsePtr&)>&& callback) {
nlohmann::json result = nlohmann::json::array();
for (const auto& [id, plot] : *plots) {
static_cast<void>(plot);
const auto& media = plot_media->at(id);
result.push_back({
{"id", id}, {"title", id}, {"category", "Plots"}, {"description", ""},
{"dimension", id.starts_with("datoviz_") ? "3D" : "2D"}, {"websocket", "/ws/plot/" + id},
{"media", plot_media->at(id)},
{"media", media},
{"schema", "/plot/" + id + "/schema"},
{"diagnostics", "/plot/" + id + "/diagnostics"},
{"taskflow", "/plot/" + id + "/taskflow"}});