release / go (push) Successful in 2m7s
release / web (push) Successful in 1m25s
release / govulncheck (push) Successful in 21s
release / integration (push) Successful in 4m30s
release / android (push) Successful in 4m39s
release / Build signed APK (push) Successful in 5m10s
release / Attach APK to the Release (tag releases only) (push) Skipped
release / Build + push container image (push) Successful in 29s
release / Verify release artifacts (tag releases only) (push) Skipped
- Module path: github.com/Fabled-Sword/minstrel, in go.mod, every import and the Dockerfile's version ldflags. - buildinfo.ProjectURL, the contact outside services see in Minstrel's User-Agent: https://github.com/Fabled-Sword/minstrel. - README's compose example pulls ghcr.io/fabled-sword/minstrel:latest. - docs/security.md sends problem reports to the GitHub issues. - The demo-library stack builds Minstrel from the checkout, since :dev is not published to GHCR. - hygiene.go's same-site example uses example.com names. The workbench CI (.gitea/, ci/, export-ignored) still builds and publishes :dev to the private registry. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
143 lines
4.1 KiB
Go
143 lines
4.1 KiB
Go
package subsonic
|
|
|
|
import (
|
|
"net/http"
|
|
"strings"
|
|
|
|
"github.com/Fabled-Sword/minstrel/internal/db/dbq"
|
|
)
|
|
|
|
// Genre is one entry of getGenres. In XML the name is the element's text.
|
|
type Genre struct {
|
|
Value string `json:"value" xml:",chardata"`
|
|
SongCount int `json:"songCount" xml:"songCount,attr"`
|
|
AlbumCount int `json:"albumCount" xml:"albumCount,attr"`
|
|
}
|
|
|
|
type GenresContainer struct {
|
|
Genres []Genre `json:"genre" xml:"genre"`
|
|
}
|
|
|
|
type GenresResponse struct {
|
|
Envelope
|
|
Genres GenresContainer `json:"genres" xml:"genres"`
|
|
}
|
|
|
|
type SongsByGenreContainer struct {
|
|
Songs []SongRef `json:"song" xml:"song"`
|
|
}
|
|
|
|
type SongsByGenreResponse struct {
|
|
Envelope
|
|
SongsByGenre SongsByGenreContainer `json:"songsByGenre" xml:"songsByGenre"`
|
|
}
|
|
|
|
// getGenres lists the library's genres as the web app's genre index does: a
|
|
// tag of several genres ("Rock;Pop") counts toward each, missing files count
|
|
// toward none, and the genres with the most songs come first.
|
|
func (b *browseHandlers) getGenres(w http.ResponseWriter, r *http.Request) {
|
|
rows, err := dbq.New(b.pool).ListGenresWithCount(r.Context())
|
|
if err != nil {
|
|
WriteFail(w, r, ErrGeneric, "Failed to load genres")
|
|
return
|
|
}
|
|
genres := make([]Genre, 0, len(rows))
|
|
for _, row := range rows {
|
|
genres = append(genres, Genre{
|
|
Value: row.Genre, SongCount: int(row.TrackCount), AlbumCount: int(row.AlbumCount),
|
|
})
|
|
}
|
|
Write(w, r, GenresResponse{
|
|
Envelope: NewEnvelope("ok"),
|
|
Genres: GenresContainer{Genres: genres},
|
|
})
|
|
}
|
|
|
|
// getSongsByGenre pages one genre's songs, album by album in track order.
|
|
// The listener's quarantined songs are left out, since an app asks for these
|
|
// to play them. count defaults to 10 and is at most 500, as in the spec.
|
|
func (b *browseHandlers) getSongsByGenre(w http.ResponseWriter, r *http.Request) {
|
|
params := r.URL.Query()
|
|
genre := params.Get("genre")
|
|
if genre == "" {
|
|
WriteFail(w, r, ErrMissingParameter, "Missing required parameter: genre")
|
|
return
|
|
}
|
|
user, ok := requireUser(w, r)
|
|
if !ok {
|
|
return
|
|
}
|
|
count := clampInt(atoiDefault(params.Get("count"), 10), 1, 500)
|
|
offset := max(atoiDefault(params.Get("offset"), 0), 0)
|
|
|
|
q := dbq.New(b.pool)
|
|
rows, err := q.ListTracksByGenre(r.Context(), dbq.ListTracksByGenreParams{
|
|
Genre: genre, UserID: user.ID, Lim: int32(count), Off: int32(offset),
|
|
})
|
|
if err != nil {
|
|
WriteFail(w, r, ErrGeneric, "Failed to load songs")
|
|
return
|
|
}
|
|
tracks := make([]dbq.Track, len(rows))
|
|
for i, row := range rows {
|
|
tracks[i] = row.Track
|
|
}
|
|
songs, err := songRefs(r.Context(), q, tracks)
|
|
if err != nil {
|
|
WriteFail(w, r, ErrGeneric, "Failed to load songs")
|
|
return
|
|
}
|
|
Write(w, r, SongsByGenreResponse{
|
|
Envelope: NewEnvelope("ok"),
|
|
SongsByGenre: SongsByGenreContainer{Songs: songs},
|
|
})
|
|
}
|
|
|
|
type TopSongsContainer struct {
|
|
Songs []SongRef `json:"song" xml:"song"`
|
|
}
|
|
|
|
type TopSongsResponse struct {
|
|
Envelope
|
|
TopSongs TopSongsContainer `json:"topSongs" xml:"topSongs"`
|
|
}
|
|
|
|
// getTopSongs returns an artist's most played songs on this server, then the
|
|
// most liked, then the rest in album order (ListTopTracksForArtistName). The
|
|
// app names the artist rather than giving an id. count defaults to 50 and is
|
|
// at most 500.
|
|
func (b *browseHandlers) getTopSongs(w http.ResponseWriter, r *http.Request) {
|
|
params := r.URL.Query()
|
|
artist := strings.TrimSpace(params.Get("artist"))
|
|
if artist == "" {
|
|
WriteFail(w, r, ErrMissingParameter, "Missing required parameter: artist")
|
|
return
|
|
}
|
|
user, ok := requireUser(w, r)
|
|
if !ok {
|
|
return
|
|
}
|
|
count := clampInt(atoiDefault(params.Get("count"), 50), 1, 500)
|
|
q := dbq.New(b.pool)
|
|
rows, err := q.ListTopTracksForArtistName(r.Context(), dbq.ListTopTracksForArtistNameParams{
|
|
ArtistName: artist, UserID: user.ID, Lim: int32(count),
|
|
})
|
|
if err != nil {
|
|
WriteFail(w, r, ErrGeneric, "Failed to load top songs")
|
|
return
|
|
}
|
|
tracks := make([]dbq.Track, len(rows))
|
|
for i, row := range rows {
|
|
tracks[i] = row.Track
|
|
}
|
|
songs, err := songRefs(r.Context(), q, tracks)
|
|
if err != nil {
|
|
WriteFail(w, r, ErrGeneric, "Failed to load top songs")
|
|
return
|
|
}
|
|
Write(w, r, TopSongsResponse{
|
|
Envelope: NewEnvelope("ok"),
|
|
TopSongs: TopSongsContainer{Songs: songs},
|
|
})
|
|
}
|