feat: add scan status and cover art endpoints
Track scanner status for the web API and Subsonic-compatible scan endpoints, add authenticated cover art serving, and wire album artwork into the web UI. Keep Subsonic auth limited to legacy password mode for now so behavior stays honest with the current bcrypt-based user storage.
This commit is contained in:
@@ -1,6 +1,11 @@
|
||||
package subsonic
|
||||
|
||||
import "github.com/benya/temporserv/internal/library"
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/benya/temporserv/internal/library"
|
||||
"github.com/benya/temporserv/internal/scanner"
|
||||
)
|
||||
|
||||
type Envelope struct {
|
||||
SubsonicResponse Response `json:"subsonic-response"`
|
||||
@@ -14,6 +19,8 @@ type Response struct {
|
||||
OpenAPI bool `json:"openSubsonic"`
|
||||
Artists []ArtistRef `json:"artists,omitempty"`
|
||||
RandomSong []SongRef `json:"randomSongs,omitempty"`
|
||||
ScanStatus *ScanStatus `json:"scanStatus,omitempty"`
|
||||
Error *ErrorRef `json:"error,omitempty"`
|
||||
}
|
||||
|
||||
type ArtistRef struct {
|
||||
@@ -28,6 +35,20 @@ type SongRef struct {
|
||||
Artist string `json:"artist"`
|
||||
}
|
||||
|
||||
type ScanStatus struct {
|
||||
Scanning bool `json:"scanning"`
|
||||
Count int `json:"count"`
|
||||
FolderCount int `json:"folderCount"`
|
||||
LastError string `json:"lastError,omitempty"`
|
||||
StartedAt string `json:"startedAt,omitempty"`
|
||||
FinishedAt string `json:"finishedAt,omitempty"`
|
||||
}
|
||||
|
||||
type ErrorRef struct {
|
||||
Code int `json:"code"`
|
||||
Message string `json:"message"`
|
||||
}
|
||||
|
||||
func PingResponse() Envelope {
|
||||
return Envelope{
|
||||
SubsonicResponse: Response{
|
||||
@@ -63,3 +84,33 @@ func RandomSongsResponse(tracks []library.Track) Envelope {
|
||||
}
|
||||
return response
|
||||
}
|
||||
|
||||
func ScanStatusResponse(status scanner.Status) Envelope {
|
||||
response := PingResponse()
|
||||
response.SubsonicResponse.ScanStatus = &ScanStatus{
|
||||
Scanning: status.Scanning,
|
||||
Count: status.Tracks,
|
||||
FolderCount: status.Albums,
|
||||
LastError: status.LastError,
|
||||
StartedAt: formatTime(status.StartedAt),
|
||||
FinishedAt: formatTime(status.FinishedAt),
|
||||
}
|
||||
return response
|
||||
}
|
||||
|
||||
func ErrorResponse(code int, message string) Envelope {
|
||||
response := PingResponse()
|
||||
response.SubsonicResponse.Status = "failed"
|
||||
response.SubsonicResponse.Error = &ErrorRef{
|
||||
Code: code,
|
||||
Message: message,
|
||||
}
|
||||
return response
|
||||
}
|
||||
|
||||
func formatTime(value time.Time) string {
|
||||
if value.IsZero() {
|
||||
return ""
|
||||
}
|
||||
return value.Format(time.RFC3339)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user