release / go (push) Successful in 1m54s
release / web (push) Failing after 5s
release / integration (push) Failing after 3m44s
release / govulncheck (push) Successful in 20s
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 / Build signed APK (push) Canceled after 19s
release / android (push) Canceled after 2m37s
Minstrel is now a viewer of the library it is pointed at. Finding, downloading and filing music moves out of it. Removed from the server: - the request flow (requests, approval, auto-approve) and the wanted list, follows, release profiles and release blocks; - searching indexers, the download clients, the importer, the album lifecycle and missing-file re-acquisition; - the catalogue's discography, search and art (the MusicBrainz release and track-list cache stays, for the duplicate resolver); - Discover: its suggestions of artists not in the library, snoozes, the candidate-artist tag enrichment and its tuning scope; - writes to acquisition tables from moving the library folder and from merging duplicates, the want-list join on Suspect sources, the sealing of acquisition credentials, and the release-group lookup only re-acquisition used. Settling a wrong-slot duplicate no longer sets the release aside: the copies go and their slots show as missing until a good copy is in the library. Removed from the web: Admin > Acquisition and Requests, /requests, /discover, Follow on the artist page, the auto-approve toggle, and the Collection's wanted-list tabs. The Collection is now the library's health: an overview, Reports, Duplicates, Suspect sources and Missing files. The README and docs no longer describe getting music. The tables stay for now; a later migration drops them. The request notification kinds and the Android screens are still to go. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
175 lines
5.7 KiB
Go
175 lines
5.7 KiB
Go
package api
|
|
|
|
import (
|
|
"net/http"
|
|
"syscall"
|
|
"time"
|
|
|
|
"git.fabledsword.com/bvandeusen/minstrel/internal/buildinfo"
|
|
"git.fabledsword.com/bvandeusen/minstrel/internal/db/dbq"
|
|
"git.fabledsword.com/bvandeusen/minstrel/internal/logging"
|
|
)
|
|
|
|
// The admin Overview's status sections: after the verdict, who is
|
|
// listening, what the library holds and how much room
|
|
// it has, and how the server itself is doing. One read for the page, polled
|
|
// while it is open.
|
|
|
|
type listeningView struct {
|
|
Username string `json:"username"`
|
|
TrackID string `json:"track_id"`
|
|
Title string `json:"title"`
|
|
ArtistName string `json:"artist_name"`
|
|
AlbumID string `json:"album_id"`
|
|
AlbumTitle string `json:"album_title"`
|
|
DurationMs int32 `json:"duration_ms"`
|
|
StartedAt string `json:"started_at"`
|
|
Client string `json:"client"`
|
|
DeviceClass string `json:"device_class"`
|
|
}
|
|
|
|
type listeningStatusView struct {
|
|
Now []listeningView `json:"now"`
|
|
// The last day: how many plays, by how many people, the latest when.
|
|
PlaysDay int64 `json:"plays_day"`
|
|
ListenersDay int64 `json:"listeners_day"`
|
|
LastPlayAt *string `json:"last_play_at"`
|
|
}
|
|
|
|
// diskView is the filesystem one library folder, or the data folder, sits
|
|
// on.
|
|
type diskView struct {
|
|
Path string `json:"path"`
|
|
// Data marks Minstrel's own data folder (covers, fingerprints), beside
|
|
// the library's.
|
|
Data bool `json:"data,omitempty"`
|
|
TotalBytes uint64 `json:"total_bytes"`
|
|
FreeBytes uint64 `json:"free_bytes"`
|
|
// Error says why the folder could not be read, which is itself the
|
|
// news: a drive that did not mount.
|
|
Error string `json:"error,omitempty"`
|
|
}
|
|
|
|
type libraryStatusView struct {
|
|
Tracks int64 `json:"tracks"`
|
|
Albums int64 `json:"albums"`
|
|
Artists int64 `json:"artists"`
|
|
Bytes int64 `json:"bytes"`
|
|
Disks []diskView `json:"disks"`
|
|
}
|
|
|
|
type serverErrorView struct {
|
|
At string `json:"at"`
|
|
Message string `json:"message"`
|
|
Attrs string `json:"attrs"`
|
|
}
|
|
|
|
type serverStatusView struct {
|
|
Version string `json:"version"`
|
|
Channel string `json:"channel"`
|
|
StartedAt string `json:"started_at"`
|
|
// Migration is the database schema's version, and Dirty whether its
|
|
// last migration stopped part way.
|
|
Migration int64 `json:"migration"`
|
|
Dirty bool `json:"dirty"`
|
|
// Errors is the newest few errors logged since the start, newest first;
|
|
// ErrorCount is all of them.
|
|
Errors []serverErrorView `json:"errors"`
|
|
ErrorCount int64 `json:"error_count"`
|
|
}
|
|
|
|
type adminStatusView struct {
|
|
Listening listeningStatusView `json:"listening"`
|
|
Library libraryStatusView `json:"library"`
|
|
Server serverStatusView `json:"server"`
|
|
}
|
|
|
|
// overviewErrors is how many recent errors the Overview lists.
|
|
const overviewErrors = 10
|
|
|
|
// handleGetAdminStatus implements GET /api/admin/status.
|
|
func (h *handlers) handleGetAdminStatus(w http.ResponseWriter, r *http.Request) {
|
|
q := dbq.New(h.pool)
|
|
ctx := r.Context()
|
|
var out adminStatusView
|
|
|
|
now, err := q.ListListeningNow(ctx)
|
|
if err != nil {
|
|
h.logger.Error("admin status: listening", "err", err)
|
|
writeAdminJSONErr(w, http.StatusInternalServerError, "server_error")
|
|
return
|
|
}
|
|
out.Listening.Now = make([]listeningView, 0, len(now))
|
|
for _, p := range now {
|
|
out.Listening.Now = append(out.Listening.Now, listeningView{
|
|
Username: p.Username, TrackID: uuidToString(p.TrackID), Title: p.TrackTitle,
|
|
ArtistName: p.ArtistName, AlbumID: uuidToString(p.AlbumID), AlbumTitle: p.AlbumTitle,
|
|
DurationMs: p.DurationMs, StartedAt: formatTimestamp(p.StartedAt),
|
|
Client: deref(p.ClientID), DeviceClass: deref(p.DeviceClass),
|
|
})
|
|
}
|
|
day, err := q.PlaysLastDay(ctx)
|
|
if err != nil {
|
|
h.logger.Error("admin status: plays", "err", err)
|
|
writeAdminJSONErr(w, http.StatusInternalServerError, "server_error")
|
|
return
|
|
}
|
|
out.Listening.PlaysDay, out.Listening.ListenersDay = day.Plays, day.Listeners
|
|
if day.LastAt.Valid {
|
|
at := formatTimestamp(day.LastAt)
|
|
out.Listening.LastPlayAt = &at
|
|
}
|
|
|
|
lib, err := q.LibraryStatus(ctx)
|
|
if err != nil {
|
|
h.logger.Error("admin status: library", "err", err)
|
|
writeAdminJSONErr(w, http.StatusInternalServerError, "server_error")
|
|
return
|
|
}
|
|
out.Library = libraryStatusView{Tracks: lib.Tracks, Albums: lib.Albums, Artists: lib.Artists,
|
|
Bytes: lib.Bytes, Disks: []diskView{}}
|
|
if h.scanner != nil {
|
|
for _, root := range h.scanner.Roots() {
|
|
out.Library.Disks = append(out.Library.Disks, diskOf(root))
|
|
}
|
|
}
|
|
if h.dataDir != "" {
|
|
d := diskOf(h.dataDir)
|
|
d.Data = true
|
|
out.Library.Disks = append(out.Library.Disks, d)
|
|
}
|
|
|
|
out.Server = serverStatus(logging.Errors)
|
|
// golang-migrate's own table, outside sqlc's schema.
|
|
if err := h.pool.QueryRow(ctx, `SELECT version, dirty FROM schema_migrations LIMIT 1`).
|
|
Scan(&out.Server.Migration, &out.Server.Dirty); err != nil {
|
|
h.logger.Warn("admin status: migration version", "err", err)
|
|
}
|
|
writeJSON(w, http.StatusOK, out)
|
|
}
|
|
|
|
// diskOf reads the size and free space of the filesystem path is on.
|
|
func diskOf(path string) diskView {
|
|
var st syscall.Statfs_t
|
|
if err := syscall.Statfs(path, &st); err != nil {
|
|
return diskView{Path: path, Error: err.Error()}
|
|
}
|
|
bsize := uint64(st.Bsize)
|
|
return diskView{Path: path, TotalBytes: st.Blocks * bsize, FreeBytes: st.Bavail * bsize}
|
|
}
|
|
|
|
func serverStatus(ring *logging.ErrorRing) serverStatusView {
|
|
kept, total := ring.Snapshot()
|
|
v := serverStatusView{Version: buildinfo.Version, Channel: buildinfo.Channel,
|
|
StartedAt: buildinfo.Started.UTC().Format(time.RFC3339), ErrorCount: total,
|
|
Errors: make([]serverErrorView, 0, min(len(kept), overviewErrors))}
|
|
for i, e := range kept {
|
|
if i == overviewErrors {
|
|
break
|
|
}
|
|
v.Errors = append(v.Errors, serverErrorView{At: e.At.UTC().Format(time.RFC3339),
|
|
Message: e.Message, Attrs: e.Attrs})
|
|
}
|
|
return v
|
|
}
|