Files
TermorServer/internal/subsonic/service.go
benya 35abd27473 feat: add sqlite-backed auth and library services
Bootstrap SQLite on server startup with embedded migrations and development seed data. Replace placeholder auth and library responses with database-backed services, bearer sessions, and repository-driven API handlers.
2026-04-02 22:22:38 +03:00

66 lines
1.5 KiB
Go

package subsonic
import "github.com/benya/temporserv/internal/library"
type Envelope struct {
SubsonicResponse Response `json:"subsonic-response"`
}
type Response struct {
Status string `json:"status"`
Version string `json:"version"`
Type string `json:"type"`
Server string `json:"serverVersion"`
OpenAPI bool `json:"openSubsonic"`
Artists []ArtistRef `json:"artists,omitempty"`
RandomSong []SongRef `json:"randomSongs,omitempty"`
}
type ArtistRef struct {
ID string `json:"id"`
Name string `json:"name"`
}
type SongRef struct {
ID string `json:"id"`
Title string `json:"title"`
Album string `json:"album"`
Artist string `json:"artist"`
}
func PingResponse() Envelope {
return Envelope{
SubsonicResponse: Response{
Status: "ok",
Version: "1.16.1",
Type: "temporserv",
Server: "0.1.0",
OpenAPI: true,
},
}
}
func ArtistsResponse(artists []library.Artist) Envelope {
response := PingResponse()
for _, artist := range artists {
response.SubsonicResponse.Artists = append(response.SubsonicResponse.Artists, ArtistRef{
ID: artist.ID,
Name: artist.Name,
})
}
return response
}
func RandomSongsResponse(tracks []library.Track) Envelope {
response := PingResponse()
for _, track := range tracks {
response.SubsonicResponse.RandomSong = append(response.SubsonicResponse.RandomSong, SongRef{
ID: track.ID,
Title: track.Title,
Album: track.AlbumTitle,
Artist: track.ArtistName,
})
}
return response
}