diff options
| author | Joel Klinghed <the_jk@spawned.biz> | 2025-10-22 23:40:59 +0200 |
|---|---|---|
| committer | Joel Klinghed <the_jk@spawned.biz> | 2025-10-22 23:47:20 +0200 |
| commit | 2d7b7c84cd843b75ca7131549f99d0671dfe3268 (patch) | |
| tree | 76b9aab0ca4a47401a5ba8779fe7e5eea6837696 | |
| parent | 00dc057ea5d9244f1df9457a316fd193c54dbfb0 (diff) | |
server: Add play/pause actions for /api/v1/device/address
| -rw-r--r-- | src/server.cc | 27 |
1 files 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"); } } } |
