mirror of
https://github.com/navidrome/navidrome.git
synced 2026-08-01 07:21:17 +00:00
Relocate the image-upload service from core to core/artwork as artwork.Uploader, co-locating it with the resolver/worker/serving that own the artwork state it invalidates. MaxImageUploadSize moves too — its only callers are the two image-upload handlers — which lets core/image_upload.go be deleted entirely. Extract the shared "clear resolved state + re-queue at Bump" invalidation into artwork.Refresh and fold nativeapi's refreshArtwork handler onto it, removing the duplicated DeleteForItem+Enqueue block that had drifted into three places. The wire provider moves from core's set to artwork's; the playlists.ImageUploadService binding moves to the top-level injector so core/artwork stays unaware of playlists. Behavior is unchanged.
44 lines
1.4 KiB
Go
44 lines
1.4 KiB
Go
package nativeapi
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"github.com/go-chi/chi/v5"
|
|
"github.com/navidrome/navidrome/core/artwork"
|
|
"github.com/navidrome/navidrome/log"
|
|
"github.com/navidrome/navidrome/model"
|
|
)
|
|
|
|
// refreshableArtworkKinds are the entity kinds a manual re-resolve accepts.
|
|
var refreshableArtworkKinds = map[string]bool{
|
|
model.KindAlbumArtwork.Prefix(): true,
|
|
model.KindArtistArtwork.Prefix(): true,
|
|
model.KindPlaylistArtwork.Prefix(): true,
|
|
model.KindRadioArtwork.Prefix(): true,
|
|
model.KindMediaFileArtwork.Prefix(): true,
|
|
}
|
|
|
|
func (api *Router) addArtworkRoute(r chi.Router) {
|
|
r.Post("/artwork/{kind}/{id}/refresh", api.refreshArtwork())
|
|
}
|
|
|
|
// refreshArtwork clears an item's resolved artwork state and re-queues it at Bump priority.
|
|
// State is deliberately cleared so a wrong pick disappears immediately (placeholder until re-resolved).
|
|
func (api *Router) refreshArtwork() http.HandlerFunc {
|
|
return func(w http.ResponseWriter, r *http.Request) {
|
|
ctx := r.Context()
|
|
kind := chi.URLParam(r, "kind")
|
|
id := chi.URLParam(r, "id")
|
|
if !refreshableArtworkKinds[kind] {
|
|
http.Error(w, "invalid artwork kind", http.StatusBadRequest)
|
|
return
|
|
}
|
|
if err := artwork.Refresh(ctx, api.ds, kind, id); err != nil {
|
|
log.Error(ctx, "Error refreshing artwork", "kind", kind, "id", id, err)
|
|
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
|
|
return
|
|
}
|
|
w.WriteHeader(http.StatusNoContent)
|
|
}
|
|
}
|