add function map viewer
Some checks failed
Test / test (push) Has been cancelled

This commit is contained in:
2026-06-20 10:53:49 +07:00
parent a6cf06d7eb
commit 819323f8c8
22 changed files with 3332 additions and 67 deletions

View File

@@ -153,6 +153,29 @@ void ApiServer::registerMediaRoutes(httplib::Server& svr)
res.body = updated ? updated->dump() : nlohmann::json::object().dump();
});
svr.Get(R"(/api/maps/([^/]+)/yaml$)", [this](const httplib::Request& req, httplib::Response& res) {
HttpUtil::addCors(res);
const std::string id = req.matches[1];
const auto path = map_store_.yamlPath(id);
if (!path)
return HttpUtil::jsonError(res, 404, "map yaml not found");
res.set_header("Content-Type", "text/yaml; charset=utf-8");
res.body = FileUtil::readBinary(*path);
});
svr.Post(R"(/api/maps/([^/]+)/yaml$)", [this](const httplib::Request& req, httplib::Response& res) {
HttpUtil::addCors(res);
const std::string id = req.matches[1];
if (req.body.empty())
return HttpUtil::jsonError(res, 400, "yaml body is required");
std::string err;
if (!map_store_.saveYamlFile(id, req.body, err))
return HttpUtil::jsonError(res, 400, err);
const auto updated = map_store_.find(id);
res.set_header("Content-Type", "application/json; charset=utf-8");
res.body = updated ? updated->dump() : nlohmann::json::object().dump();
});
svr.Get("/api/sounds", [this](const httplib::Request&, httplib::Response& res) {
HttpUtil::addCors(res);
res.set_header("Content-Type", "application/json; charset=utf-8");