release / go (push) Failing after 1m15s
release / web (push) Successful in 1m18s
release / govulncheck (push) Successful in 21s
release / integration (push) Successful in 3m57s
release / Attach APK to the Release (tag releases only) (push) Canceled after 0s
release / Build + push container image (push) Canceled after 0s
release / Verify release artifacts (tag releases only) (push) Canceled after 0s
release / android (push) Canceled after 4m33s
release / Build signed APK (push) Canceled after 4m9s
The last Subsonic methods apps call that Minstrel didn't answer: - getScanStatus counts the songs whose files are present and says whether a scan is running; startScan, for an admin, starts the scan the web app's Rescan starts, and answers "scanning" straight away since the scan records itself a moment later. - getArtistInfo and getArtistInfo2 give the artist's MusicBrainz id and the artists in this library that sound like them, from an artist, album or song id; getAlbumInfo and getAlbumInfo2 give the album's MusicBrainz id. Minstrel fetches no biographies or outside images, so none are sent. - getLyrics (by artist and title) and getLyricsBySongId (OpenSubsonic songLyrics, now declared) read lyrics when asked: a .lrc file beside the song gives timed lyrics, otherwise the song's own lyrics tag. - setRating accepts a rating and keeps none: a like is Minstrel's only rating, and a low rating is never read as a dislike. - getUsers lists every user, for an admin only. ArtistRef no longer fixes its XML element name, so it can appear as similarArtist; every field holding it names the element. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
95 lines
2.6 KiB
Go
95 lines
2.6 KiB
Go
package subsonic
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"net/http"
|
|
|
|
"github.com/jackc/pgx/v5"
|
|
|
|
"git.fabledsword.com/bvandeusen/minstrel/internal/db/dbq"
|
|
)
|
|
|
|
// StartScan starts a library scan in the background, the same scan as the
|
|
// admin's Rescan in the web app. started is false when one is already
|
|
// running.
|
|
type StartScan func(ctx context.Context) (started bool, err error)
|
|
|
|
// ScanStatus is the body of getScanStatus and startScan. Count is the songs
|
|
// whose files are present; LastScan, from OpenSubsonic, is when the latest
|
|
// scan finished.
|
|
type ScanStatus struct {
|
|
Scanning bool `json:"scanning" xml:"scanning,attr"`
|
|
Count int64 `json:"count" xml:"count,attr"`
|
|
LastScan string `json:"lastScan,omitempty" xml:"lastScan,attr,omitempty"`
|
|
}
|
|
|
|
type ScanStatusResponse struct {
|
|
Envelope
|
|
ScanStatus ScanStatus `json:"scanStatus" xml:"scanStatus"`
|
|
}
|
|
|
|
type scanHandlers struct {
|
|
pool dbq.DBTX
|
|
start StartScan
|
|
}
|
|
|
|
// status reads whether a scan is running from the latest scan run.
|
|
func (s *scanHandlers) status(ctx context.Context) (ScanStatus, error) {
|
|
q := dbq.New(s.pool)
|
|
count, err := q.CountPlayableTracks(ctx)
|
|
if err != nil {
|
|
return ScanStatus{}, err
|
|
}
|
|
st := ScanStatus{Count: count}
|
|
run, err := q.GetLatestScanRun(ctx)
|
|
if errors.Is(err, pgx.ErrNoRows) {
|
|
return st, nil
|
|
}
|
|
if err != nil {
|
|
return ScanStatus{}, err
|
|
}
|
|
st.Scanning = !run.FinishedAt.Valid
|
|
st.LastScan = timestamptzToRFC3339(run.FinishedAt)
|
|
return st, nil
|
|
}
|
|
|
|
func (s *scanHandlers) getScanStatus(w http.ResponseWriter, r *http.Request) {
|
|
st, err := s.status(r.Context())
|
|
if err != nil {
|
|
WriteFail(w, r, ErrGeneric, "Failed to read the scan status")
|
|
return
|
|
}
|
|
Write(w, r, ScanStatusResponse{Envelope: NewEnvelope("ok"), ScanStatus: st})
|
|
}
|
|
|
|
// startScan starts a library scan; only an admin may. It answers scanning
|
|
// at once: the scan records itself a moment after it starts, so the latest
|
|
// scan run alone would still read as finished.
|
|
func (s *scanHandlers) startScan(w http.ResponseWriter, r *http.Request) {
|
|
user, ok := UserFromContext(r.Context())
|
|
if !ok {
|
|
WriteFail(w, r, ErrNotAuthorized, "Not authenticated")
|
|
return
|
|
}
|
|
if !user.IsAdmin {
|
|
WriteFail(w, r, ErrNotAuthorized, "Only an admin can start a scan")
|
|
return
|
|
}
|
|
if s.start == nil {
|
|
WriteFail(w, r, ErrGeneric, "Scanning is not available on this server")
|
|
return
|
|
}
|
|
if _, err := s.start(r.Context()); err != nil {
|
|
WriteFail(w, r, ErrGeneric, "Failed to start a scan")
|
|
return
|
|
}
|
|
st, err := s.status(r.Context())
|
|
if err != nil {
|
|
WriteFail(w, r, ErrGeneric, "Failed to read the scan status")
|
|
return
|
|
}
|
|
st.Scanning = true
|
|
Write(w, r, ScanStatusResponse{Envelope: NewEnvelope("ok"), ScanStatus: st})
|
|
}
|