From 360e94484b151f747a12233fe5278457146acfe8 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Sun, 30 Nov 2025 23:01:00 +0100 Subject: Add content GET endpoint. --- src/lib/http_server.cc | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/lib/http_server.cc b/src/lib/http_server.cc index 1797b025c..4d1823bc4 100644 --- a/src/lib/http_server.cc +++ b/src/lib/http_server.cc @@ -24,6 +24,7 @@ #include "dcpomatic_socket.h" #include "http_server.h" #include "show_playlist.h" +#include "show_playlist_content_store.h" #include "show_playlist_list.h" #include "util.h" #include "variant.h" @@ -161,6 +162,30 @@ HTTPServer::get(string const& url) auto response = Response(200, json.dump()); response.set_type(Response::Type::JSON); return response; + } else if (url == "/api/v1/content") { + nlohmann::json json; + for (auto i: ShowPlaylistContentStore::instance()->all()) { + /* XXX: converting to JSON this way feels a bit grotty */ + json.push_back(ShowPlaylistEntry(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 = ShowPlaylistContentStore::instance()->get(parts[4]); + if (!content) { + return Response::ERROR_404; + } + /* XXX: converting to JSON this way feels a bit grotty */ + auto json = ShowPlaylistEntry(content, {}).as_json(); + auto response = Response(200, json.dump()); + response.set_type(Response::Type::JSON); + return response; } else { LOG_HTTP("404 {}", url); return Response::ERROR_404; -- cgit v1.2.3