release / govulncheck (push) Successful in 15s
release / web (push) Failing after 1m21s
release / go (push) Successful in 1m35s
release / integration (push) Failing after 4m57s
release / android (push) Successful in 5m11s
release / Build signed APK (releases and dev) (push) Successful in 5m28s
release / Attach APK to the Release (tag releases only) (push) Skipped
release / Build + push container image (push) Skipped
release / Verify release artifacts (tag releases only) (push) Skipped
Minstrel keeps its own list of what it is to get, keyed by MusicBrainz release group. A want comes from an approved request, a new release by a followed artist, or an album whose files went missing, and is held once the library has a full edition of it. - Migration 0081: release_type_profiles (Standard seeded: Album, EP, Single, studio only), follows, follow_seen_groups and wants. lidarr_requests becomes requests with plain *_mbid columns; approved album and track requests move onto the wanted list, approved artist requests become follows, and the library's album artists start out followed. missing_reacquisitions and the retry settings go. - internal/wanted: follows are checked against MusicBrainz discographies daily. The first check sets a baseline, and only releases after it are wanted unless the follow asked for what already exists. Profiles filter by primary and secondary type, so live recordings stay out unless a profile ticks Live. - internal/requests (was lidarrrequests): approving puts the request on the wanted list, and an artist request can be approved on a chosen profile. A request completes when its want is held. - The re-acquisition sweeper wants a missing album back instead of asking Lidarr; searching for it is the search schedule's (#5521). - Web: an admin Wanted page (Wanted, Missing files, Held, Following), a follow control on artist pages, a release-type profiles card on Integrations, "Approve on a profile" on Requests, and want state on Missing files. The artist detail API returns the artist's MBID. - Android: the request body sends artist_mbid, album_mbid and track_mbid. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
77 lines
2.8 KiB
Go
77 lines
2.8 KiB
Go
package api
|
|
|
|
import (
|
|
"encoding/json"
|
|
"errors"
|
|
"net/http"
|
|
|
|
"git.fabledsword.com/bvandeusen/minstrel/internal/apierror"
|
|
"git.fabledsword.com/bvandeusen/minstrel/internal/db/dbq"
|
|
"git.fabledsword.com/bvandeusen/minstrel/internal/reacquisition"
|
|
)
|
|
|
|
// reacquisitionSettingsResp is the admin card's payload (milestone #290).
|
|
//
|
|
// Carries more than the stored settings: [UnnameableAlbums] is the count of
|
|
// albums with missing files that can never be wanted automatically because
|
|
// neither they nor their artist has an MBID. The card states that number
|
|
// rather than leaving the operator to wonder why some rows never get wanted —
|
|
// a feature that silently does nothing for part of its input reads as broken.
|
|
type reacquisitionSettingsResp struct {
|
|
Enabled bool `json:"enabled"`
|
|
GraceHours int32 `json:"grace_hours"`
|
|
MaxPerPass int32 `json:"max_per_pass"`
|
|
|
|
UnnameableAlbums int64 `json:"unnameable_albums"`
|
|
}
|
|
|
|
// handleGetReacquisitionSettings implements GET /api/admin/library/reacquisition.
|
|
func (h *handlers) handleGetReacquisitionSettings(w http.ResponseWriter, r *http.Request) {
|
|
writeJSON(w, http.StatusOK, h.reacquisitionPayload(r))
|
|
}
|
|
|
|
// handleUpdateReacquisitionSettings implements PUT /api/admin/library/reacquisition.
|
|
func (h *handlers) handleUpdateReacquisitionSettings(w http.ResponseWriter, r *http.Request) {
|
|
var req reacquisitionSettingsResp
|
|
if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
|
|
writeErr(w, apierror.BadRequest("invalid_body", "malformed JSON"))
|
|
return
|
|
}
|
|
_, err := h.reacqSettings.Set(r.Context(), reacquisition.Settings{
|
|
Enabled: req.Enabled,
|
|
GraceHours: req.GraceHours,
|
|
MaxPerPass: req.MaxPerPass,
|
|
})
|
|
if err != nil {
|
|
// The Go-side validation mirrors migration 0056's CHECKs so the
|
|
// operator gets a readable message naming the field, rather than a
|
|
// constraint-violation string leaking through as a 500.
|
|
if errors.Is(err, reacquisition.ErrOutOfRange) {
|
|
writeErr(w, apierror.BadRequest("invalid_setting", err.Error()))
|
|
return
|
|
}
|
|
writeErrWithLog(w, h.logger, "admin reacquisition: update failed", apierror.Internal(err))
|
|
return
|
|
}
|
|
// Echo the payload recomputed under the new values so the card reflects
|
|
// what it just did without a reload.
|
|
writeJSON(w, http.StatusOK, h.reacquisitionPayload(r))
|
|
}
|
|
|
|
func (h *handlers) reacquisitionPayload(r *http.Request) reacquisitionSettingsResp {
|
|
cur := h.reacqSettings.Get()
|
|
out := reacquisitionSettingsResp{
|
|
Enabled: cur.Enabled,
|
|
GraceHours: cur.GraceHours,
|
|
MaxPerPass: cur.MaxPerPass,
|
|
}
|
|
// Best-effort: the settings are the point of this endpoint, and failing
|
|
// the whole card because a count query hiccuped would be the wrong trade.
|
|
if n, err := dbq.New(h.pool).CountAlbumsMissingWithoutMbid(r.Context()); err == nil {
|
|
out.UnnameableAlbums = n
|
|
} else {
|
|
h.logger.Warn("admin reacquisition: unnameable count failed", "err", err)
|
|
}
|
|
return out
|
|
}
|