release / govulncheck (push) Successful in 18s
release / web (push) Successful in 1m22s
release / go (push) Successful in 1m43s
release / integration (push) Successful in 4m56s
release / android (push) Successful in 5m16s
release / Build signed APK (releases and dev) (push) Successful in 5m27s
release / Attach APK to the Release (tag releases only) (push) Skipped
release / Build + push container image (push) Successful in 15s
release / Verify release artifacts (tag releases only) (push) Skipped
- A failed scan run sends scan_failed. Each failure adds to the count and the notice shows the latest error. A scan cut short by shutdown says nothing. - Marking tracks missing sends tracks_missing with a running count. - A duplicate sweep that proposes a group it had not proposed before sends duplicates_found, counting everything awaiting review. A sweep that only re-finds known groups stays quiet, so a read notice isn't repeated every sweep (CountDuplicateGroupsDetectedSince). - A playback-error report sends playback_errors, counting the unresolved errors (CountUnresolvedPlaybackErrors). The library package gets its notifier as a package-level SetNotifier beside SetEventBus, for the same reason the bus is package-level. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
87 lines
2.7 KiB
Go
87 lines
2.7 KiB
Go
package api
|
||
|
||
import (
|
||
"context"
|
||
|
||
"github.com/jackc/pgx/v5/pgtype"
|
||
|
||
"git.fabledsword.com/bvandeusen/minstrel/internal/db/dbq"
|
||
"git.fabledsword.com/bvandeusen/minstrel/internal/lidarrrequests"
|
||
"git.fabledsword.com/bvandeusen/minstrel/internal/notifications"
|
||
)
|
||
|
||
// Helpers for the handlers that produce notifications (M489). Every call is
|
||
// NotifyLogged: a notification never fails the action that caused it.
|
||
|
||
// userLabel is how a user is named to someone else: their display name, or
|
||
// their username when they have none.
|
||
func userLabel(u dbq.User) string {
|
||
if u.DisplayName != nil && *u.DisplayName != "" {
|
||
return *u.DisplayName
|
||
}
|
||
return u.Username
|
||
}
|
||
|
||
func requestPayload(row dbq.LidarrRequest) notifications.Payload {
|
||
return notifications.Payload{
|
||
RequestID: uuidToString(row.ID),
|
||
RequestKind: string(row.Kind),
|
||
Name: lidarrrequests.DisplayName(row),
|
||
}
|
||
}
|
||
|
||
// notifyRequestDecided tells the requester an admin approved or declined
|
||
// their request. An admin deciding their own request needs no notice.
|
||
func (h *handlers) notifyRequestDecided(ctx context.Context, kind notifications.Kind, admin dbq.User, row dbq.LidarrRequest, reason string) {
|
||
if row.UserID == admin.ID {
|
||
return
|
||
}
|
||
p := requestPayload(row)
|
||
p.Reason = reason
|
||
h.notifier.NotifyLogged(ctx, kind, notifications.ToUser(row.UserID), p.Map())
|
||
}
|
||
|
||
// quarantineReasonLabel is a flag reason as the flag popover words it, in
|
||
// lower case to sit inside a sentence ("flagged X: bad rip").
|
||
func quarantineReasonLabel(reason string) string {
|
||
switch reason {
|
||
case "bad_rip":
|
||
return "bad rip"
|
||
case "wrong_file":
|
||
return "wrong file"
|
||
case "wrong_tags":
|
||
return "wrong tags"
|
||
case "duplicate":
|
||
return "duplicate"
|
||
default:
|
||
return ""
|
||
}
|
||
}
|
||
|
||
// trackLabel names a track "Artist – Title" for a notification, falling back
|
||
// to the title alone, or to nothing, rather than failing the caller.
|
||
func (h *handlers) trackLabel(ctx context.Context, trackID pgtype.UUID) string {
|
||
q := dbq.New(h.pool)
|
||
t, err := q.GetTrackByID(ctx, trackID)
|
||
if err != nil {
|
||
return ""
|
||
}
|
||
if a, aerr := q.GetArtistByID(ctx, t.ArtistID); aerr == nil && a.Name != "" {
|
||
return a.Name + " – " + t.Title
|
||
}
|
||
return t.Title
|
||
}
|
||
|
||
// notifyPlaybackErrors tells admins how many playback errors await review.
|
||
// The notice coalesces, so while it is unread a new report only updates the
|
||
// count.
|
||
func (h *handlers) notifyPlaybackErrors(ctx context.Context) {
|
||
n, err := dbq.New(h.pool).CountUnresolvedPlaybackErrors(ctx)
|
||
if err != nil {
|
||
h.logger.Warn("api: playback_error: count unresolved", "err", err)
|
||
return
|
||
}
|
||
h.notifier.NotifyLogged(ctx, notifications.KindPlaybackErrors, notifications.ToAdmins(pgtype.UUID{}),
|
||
notifications.Payload{Count: n}.Map())
|
||
}
|