diff options
| author | Carl Hetherington <cth@carlh.net> | 2025-12-20 23:11:01 +0100 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2026-02-16 01:20:38 +0100 |
| commit | 9e4bb14580be7959098d7141c68452908f44c1ae (patch) | |
| tree | ba1e43b4d699dec0f50a21529791cfa28a334fac | |
| parent | e91ae40d666e44702e8f15fea72a158b96ff66c8 (diff) | |
Add playlist GET endpoint.
| -rw-r--r-- | src/lib/http_server.cc | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/src/lib/http_server.cc b/src/lib/http_server.cc index cdb1981ca..1797b025c 100644 --- a/src/lib/http_server.cc +++ b/src/lib/http_server.cc @@ -137,6 +137,30 @@ HTTPServer::get(string const& url) auto response = Response(200, json.dump()); response.set_type(Response::Type::JSON); return response; + } else if (boost::algorithm::starts_with(url, "/api/v1/playlist/")) { + vector<string> parts; + boost::algorithm::split(parts, url, boost::is_any_of("/")); + if (parts.size() != 5) { + return Response::ERROR_404; + } + ShowPlaylistList list; + auto playlist_id = list.get_show_playlist_id(parts[4]); + if (!playlist_id) { + return Response::ERROR_404; + } + auto playlist = list.show_playlist(*playlist_id); + if (!playlist) { + return Response::ERROR_404; + } + nlohmann::json json = playlist->as_json(); + json["content"] = nlohmann::json::array(); + auto entries = list.entries(parts[4]); + for (auto entry: list.entries(parts[4])) { + json["content"].push_back(entry.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; |
