Files
minstrel/internal/coverart/settings.go
T
bvandeusenandClaude Opus 5.5 e1f270362d
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
chore(release): everything that ships points at GitHub and GHCR (#7897)
- 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>
2026-11-28 19:28:16 -05:00

110 lines
3.4 KiB
Go

package coverart
import (
"context"
"fmt"
"log/slog"
"github.com/jackc/pgx/v5/pgxpool"
"github.com/Fabled-Sword/minstrel/internal/db/dbq"
"github.com/Fabled-Sword/minstrel/internal/providers"
"github.com/Fabled-Sword/minstrel/internal/secret"
)
// ProviderUpdatePatch is the admin PATCH body; see providers.UpdatePatch.
type ProviderUpdatePatch = providers.UpdatePatch
// ProviderInfo is a provider as GET /api/admin/cover-sources shows it.
type ProviderInfo = providers.Info
// SettingsService is the cover-art providers' settings: the shared
// providers.Service over cover_art_provider_settings and the
// cover_art_sources_meta version, plus the cover-art capability views.
type SettingsService struct {
*providers.Service
}
// NewSettingsService reconciles the registry with the settings table and
// Configures every provider.
func NewSettingsService(ctx context.Context, pool *pgxpool.Pool, logger *slog.Logger) (*SettingsService, error) {
svc, err := providers.NewService(ctx, providers.Config{
Registry: registry,
Store: settingsStore{q: dbq.New(pool)},
KeyColumn: secret.CoverArtAPIKey,
Supports: supports,
Logger: logger,
})
if err != nil {
return nil, fmt.Errorf("cover art settings boot: %w", err)
}
return &SettingsService{svc}, nil
}
// EnabledAlbumProviders returns the enabled album-cover providers, in
// registration order.
func (s *SettingsService) EnabledAlbumProviders() []AlbumCoverProvider {
return providers.EnabledAs[AlbumCoverProvider](s.Service)
}
// EnabledArtistProviders returns the enabled artist-image providers, in
// registration order.
func (s *SettingsService) EnabledArtistProviders() []ArtistArtProvider {
return providers.EnabledAs[ArtistArtProvider](s.Service)
}
// supports names what p can fetch, for the admin view.
func supports(p Provider) []string {
var out []string
if _, ok := p.(AlbumCoverProvider); ok {
out = append(out, "album_cover")
}
if _, ok := p.(ArtistArtProvider); ok {
out = append(out, "artist_thumb", "artist_fanart")
}
return out
}
// settingsStore is cover art's providers.Store.
type settingsStore struct{ q *dbq.Queries }
func (st settingsStore) EnsureRow(ctx context.Context, id string, enabled bool, order int32) error {
return st.q.UpsertProviderSettings(ctx, dbq.UpsertProviderSettingsParams{
ProviderID: id, Enabled: enabled, DisplayOrder: order,
})
}
func (st settingsStore) List(ctx context.Context) ([]providers.Row, error) {
rows, err := st.q.ListProviderSettings(ctx)
if err != nil {
return nil, err
}
out := make([]providers.Row, len(rows))
for i, r := range rows {
out[i] = providers.Row{ProviderID: r.ProviderID, Enabled: r.Enabled, APIKey: r.ApiKey}
}
return out, nil
}
func (st settingsStore) Save(ctx context.Context, id string, enabled, keyChanged bool, sealedKey *string) error {
return st.q.UpdateProviderSettings(ctx, dbq.UpdateProviderSettingsParams{
ProviderID: id, Enabled: enabled, Column3: keyChanged, ApiKey: sealedKey,
})
}
func (st settingsStore) Version(ctx context.Context) (int32, error) {
return st.q.GetCurrentSourcesVersion(ctx)
}
func (st settingsStore) BumpVersion(ctx context.Context) (int32, error) {
return st.q.BumpSourcesVersion(ctx)
}
func (st settingsStore) ProvidersHash(ctx context.Context) (string, error) {
return st.q.GetCoverArtProvidersHash(ctx)
}
func (st settingsStore) BumpVersionForProviders(ctx context.Context, hash string) (int32, error) {
return st.q.BumpVersionAndSetProvidersHash(ctx, hash)
}