Added OSC
Some checks failed
CI / Native Windows Build And Tests (push) Failing after 7s
CI / React UI Build (push) Has been cancelled
CI / Windows Release Package (push) Has been cancelled

This commit is contained in:
2026-05-03 12:17:03 +10:00
parent 1b56ede462
commit 254d4cd070
14 changed files with 499 additions and 0 deletions

View File

@@ -66,6 +66,8 @@ std::string GuessContentType(const std::filesystem::path& assetPath)
return "image/x-icon";
if (extension == ".map")
return "application/json";
if (extension == ".md")
return "text/markdown";
return "text/html";
}
}
@@ -255,6 +257,10 @@ ControlServer::HttpResponse ControlServer::ServeGetRequest(const HttpRequest& re
if (request.path == "/docs" || request.path == "/docs/")
return ServeSwaggerDocs();
const std::string docsPrefix = "/docs/";
if (request.path.rfind(docsPrefix, 0) == 0)
return ServeDocsAsset(request.path.substr(docsPrefix.size()));
if (request.path.size() > 1)
{
const HttpResponse assetResponse = ServeUiAsset(request.path.substr(1));
@@ -274,6 +280,19 @@ ControlServer::HttpResponse ControlServer::ServeUiAsset(const std::string& relat
: HttpResponse{ "200 OK", contentType, body };
}
ControlServer::HttpResponse ControlServer::ServeDocsAsset(const std::string& relativePath) const
{
const std::filesystem::path sanitizedPath = std::filesystem::path(relativePath).lexically_normal();
if (!IsSafeUiPath(sanitizedPath))
return { "404 Not Found", "text/plain", "Not Found" };
const std::filesystem::path docsPath = mDocsRoot / sanitizedPath;
const std::string body = LoadTextFile(docsPath);
return body.empty()
? HttpResponse{ "404 Not Found", "text/plain", "Not Found" }
: HttpResponse{ "200 OK", GuessContentType(docsPath), body };
}
ControlServer::HttpResponse ControlServer::ServeOpenApiSpec() const
{
const std::filesystem::path specPath = mDocsRoot / "openapi.yaml";