From 8533efde9d16a5d6e2b879c61cb579a97f501b40 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Sat, 14 Dec 2024 22:07:03 +0100 Subject: WIP: add content support to the HTTP API. --- src/lib/http_server.cc | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/lib/http_server.cc b/src/lib/http_server.cc index 47e62d336..61264df14 100644 --- a/src/lib/http_server.cc +++ b/src/lib/http_server.cc @@ -157,6 +157,28 @@ HTTPServer::get(string const& url) } } return Response::ERROR_404; + } else if (url == "/api/v1/content") { + nlohmann::json json; + for (auto i: ContentStore::instance()->all()) { + json.push_back(SPLEntry(i).as_json()); + } + auto response = Response(200, json.dump()); + response.set_type(Response::Type::JSON); + return response; + } else if (boost::algorithm::starts_with(url, "/api/v1/content/")) { + vector parts; + boost::algorithm::split(parts, url, boost::is_any_of("/")); + if (parts.size() != 5) { + return Response::ERROR_404; + } + auto content = ContentStore::instance()->get(parts[4]); + if (!content) { + return Response::ERROR_404; + } + auto json = SPLEntry(content).as_json(); + auto response = Response(200, json.dump()); + response.set_type(Response::Type::JSON); + return response; } else { LOG_HTTP("404 %1", url); return Response::ERROR_404; -- cgit v1.2.3