ini file support and cover art

This commit is contained in:
2026-08-27 13:33:34 +02:00
parent 744a2815f1
commit 84891adb89
13 changed files with 422 additions and 79 deletions
+31 -2
View File
@@ -10,6 +10,7 @@
web-server/http
web-server/http/json
web-server/servlet-env
"library.rkt"
"player.rkt")
(provide serve-player)
@@ -33,6 +34,12 @@
(hasheq 'error (exn-message exception))
#:code 400))
(define (agent-error-response exception)
(json-response
(hasheq 'error (exn-message exception)
'code "agent-not-authorized")
#:code 403))
(define (request-jsexpr request)
(let ((body (request-post-data/raw request)))
(if (and body (positive? (bytes-length body)))
@@ -57,7 +64,8 @@
(define (agent-register-handler request)
(with-handlers
((exn:fail? error-response))
((exn:fail:agent-denied? agent-error-response)
(exn:fail? error-response))
(json-response
(player-agent-register!
current-player
@@ -65,7 +73,8 @@
(define (agent-poll-handler request)
(with-handlers
((exn:fail? error-response))
((exn:fail:agent-denied? agent-error-response)
(exn:fail? error-response))
(json-response
(player-agent-poll!
current-player
@@ -95,6 +104,25 @@
(hasheq 'error "media token is invalid or expired")
#:code 404))))
(define (artwork-handler _request artwork-id)
(let ((value (player-track-artwork current-player artwork-id)))
(if value
(response/output
(λ (output)
(write-bytes (artwork-data value) output))
#:mime-type
(string->bytes/utf-8 (artwork-mime-type value))
#:headers
(list
(header #"Content-Length"
(string->bytes/utf-8
(number->string
(bytes-length (artwork-data value)))))
(header #"Cache-Control" #"private, max-age=3600")))
(json-response
(hasheq 'error "track artwork is unavailable")
#:code 404))))
(define-values (dispatch _url)
(dispatch-rules
[("api" "state") #:method "get" state-handler]
@@ -104,6 +132,7 @@
[("api" "agent" "media" (string-arg) (string-arg))
#:method "get"
agent-media-handler]
[("api" "artwork" (string-arg)) #:method "get" artwork-handler]
[("api" "command" (string-arg))
#:method "post"
command-handler]))