From 2d7b7c84cd843b75ca7131549f99d0671dfe3268 Mon Sep 17 00:00:00 2001 From: Joel Klinghed Date: Wed, 22 Oct 2025 23:40:59 +0200 Subject: server: Add play/pause actions for /api/v1/device/address --- src/server.cc | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/src/server.cc b/src/server.cc index 9b556b0..ab3e12a 100644 --- a/src/server.cc +++ b/src/server.cc @@ -80,7 +80,7 @@ class HttpServerDelegate : public http::Server::Delegate { } if (path.starts_with("device/")) { - if (request.method() != "GET") { + if (request.method() != "POST" && request.method() != "GET") { return http::Response::status(http::StatusCode::kMethodNotAllowed); } @@ -90,9 +90,28 @@ class HttpServerDelegate : public http::Server::Delegate { if (adapter) { for (auto* device : adapter->devices()) { if (device->address() == address) { - json_writer_->clear(); - write_device(*device); - return http::Response::content(json_tmp_, *json_mimetype_); + if (request.method() == "GET") { + json_writer_->clear(); + write_device(*device); + return http::Response::content(json_tmp_, *json_mimetype_); + } + + auto* player = device->player(); + if (request.body() == "play") { + if (player) { + player->play(); + return status_ok(); + } + return status_error("Bad state"); + } + if (request.body() == "pause") { + if (player) { + player->pause(); + return status_ok(); + } + return status_error("Bad state"); + } + return status_error("Unknown action"); } } } -- cgit v1.2.3-70-g09d2