From bb28fab565509893cb02e637f2b721851dad33f0 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Sat, 20 Dec 2025 23:05:18 +0100 Subject: Add playlist POST endpoint. --- src/lib/http_server.cc | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/src/lib/http_server.cc b/src/lib/http_server.cc index f1c1a3e19..594f581d9 100644 --- a/src/lib/http_server.cc +++ b/src/lib/http_server.cc @@ -37,6 +37,7 @@ using std::runtime_error; using std::shared_ptr; using std::string; using std::vector; +using boost::optional; Response Response::ERROR_404 = { 404, "Error 404

Error 404

"}; @@ -141,6 +142,35 @@ HTTPServer::post(string const& url, string const& body) auto response = Response(303); response.add_header("Location", "/"); return response; + } else if (boost::algorithm::starts_with(url, "/api/v1/playlist/")) { + vector parts; + boost::algorithm::split(parts, url, boost::is_any_of("/")); + if (parts.size() != 6) { + return Response::ERROR_404; + } + ShowPlaylistList list; + auto playlist_id = list.get_show_playlist_id(parts[4]); + if (!playlist_id) { + return Response::ERROR_404; + } + nlohmann::json details = nlohmann::json::parse(body); + if (parts[5] == "insert") { + auto content = ShowPlaylistContentStore::instance()->get(details["uuid"]); + if (!content) { + return Response::ERROR_404; + } + list.insert_entry(*playlist_id, ShowPlaylistEntry(content, {}), details["index"]); + } else if (parts[5] == "move") { + list.move_entry(*playlist_id, details["old_index"], details["new_index"]); + } else if (parts[5] == "rename") { + if (auto playlist = list.show_playlist(*playlist_id)) { + playlist->set_name(details["name"]); + list.update_show_playlist(*playlist_id, *playlist); + } + } else { + return Response::ERROR_404; + } + return Response(200); } else { return Response::ERROR_404; } -- cgit v1.2.3