This commit is contained in:
@@ -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");
|
||||
|
||||
Reference in New Issue
Block a user