From 2fcba12650a8224239a48f956eca6453c650c891 Mon Sep 17 00:00:00 2001 From: sentriz Date: Mon, 29 Sep 2025 18:24:10 +0100 Subject: [PATCH] wire tag.Reader to subsonic Controller --- cmd/gonic/gonic.go | 2 +- server/ctrlsubsonic/ctrl.go | 63 ++++++++++++++++------------- server/ctrlsubsonic/handlers_raw.go | 11 ++--- 3 files changed, 41 insertions(+), 35 deletions(-) diff --git a/cmd/gonic/gonic.go b/cmd/gonic/gonic.go index 6eb2f7d..0903067 100644 --- a/cmd/gonic/gonic.go +++ b/cmd/gonic/gonic.go @@ -249,7 +249,7 @@ func main() { if err != nil { log.Panicf("error creating admin controller: %v\n", err) } - ctrlSubsonic, err := ctrlsubsonic.New(dbc, scannr, musicPaths, *confPodcastPath, cacheDirAudio, cacheDirCovers, jukebx, playlistStore, scrobblers, podcast, transcoder, lastfmClient, artistInfoCache, albumInfoCache, resolveProxyPath) + ctrlSubsonic, err := ctrlsubsonic.New(dbc, scannr, musicPaths, *confPodcastPath, cacheDirAudio, cacheDirCovers, jukebx, playlistStore, scrobblers, podcast, transcoder, lastfmClient, artistInfoCache, albumInfoCache, tagReader, resolveProxyPath) if err != nil { log.Panicf("error creating subsonic controller: %v\n", err) } diff --git a/server/ctrlsubsonic/ctrl.go b/server/ctrlsubsonic/ctrl.go index 308cf0c..a548909 100644 --- a/server/ctrlsubsonic/ctrl.go +++ b/server/ctrlsubsonic/ctrl.go @@ -24,6 +24,7 @@ import ( "go.senan.xyz/gonic/scrobble" "go.senan.xyz/gonic/server/ctrlsubsonic/params" "go.senan.xyz/gonic/server/ctrlsubsonic/spec" + "go.senan.xyz/gonic/tags" "go.senan.xyz/gonic/transcode" ) @@ -52,41 +53,45 @@ type ProxyPathResolver func(in string) string type Controller struct { *http.ServeMux - dbc *db.DB - scanner *scanner.Scanner - musicPaths []MusicPath - podcastsPath string - cacheAudioPath string - cacheCoverPath string - jukebox *jukebox.Jukebox - playlistStore *playlist.Store - scrobblers []scrobble.Scrobbler - podcasts *podcast.Podcasts - transcoder transcode.Transcoder - lastFMClient *lastfm.Client - artistInfoCache *artistinfocache.ArtistInfoCache - albumInfoCache *albuminfocache.AlbumInfoCache + dbc *db.DB + scanner *scanner.Scanner + musicPaths []MusicPath + podcastsPath string + cacheAudioPath string + cacheCoverPath string + jukebox *jukebox.Jukebox + playlistStore *playlist.Store + scrobblers []scrobble.Scrobbler + podcasts *podcast.Podcasts + transcoder transcode.Transcoder + lastFMClient *lastfm.Client + artistInfoCache *artistinfocache.ArtistInfoCache + albumInfoCache *albuminfocache.AlbumInfoCache + tagReader tags.Reader + resolveProxyPath ProxyPathResolver } -func New(dbc *db.DB, scannr *scanner.Scanner, musicPaths []MusicPath, podcastsPath string, cacheAudioPath string, cacheCoverPath string, jukebox *jukebox.Jukebox, playlistStore *playlist.Store, scrobblers []scrobble.Scrobbler, podcasts *podcast.Podcasts, transcoder transcode.Transcoder, lastFMClient *lastfm.Client, artistInfoCache *artistinfocache.ArtistInfoCache, albumInfoCache *albuminfocache.AlbumInfoCache, resolveProxyPath ProxyPathResolver) (*Controller, error) { +func New(dbc *db.DB, scannr *scanner.Scanner, musicPaths []MusicPath, podcastsPath string, cacheAudioPath string, cacheCoverPath string, jukebox *jukebox.Jukebox, playlistStore *playlist.Store, scrobblers []scrobble.Scrobbler, podcasts *podcast.Podcasts, transcoder transcode.Transcoder, lastFMClient *lastfm.Client, artistInfoCache *artistinfocache.ArtistInfoCache, albumInfoCache *albuminfocache.AlbumInfoCache, tagReader tags.Reader, resolveProxyPath ProxyPathResolver) (*Controller, error) { c := Controller{ ServeMux: http.NewServeMux(), - dbc: dbc, - scanner: scannr, - musicPaths: musicPaths, - podcastsPath: podcastsPath, - cacheAudioPath: cacheAudioPath, - cacheCoverPath: cacheCoverPath, - jukebox: jukebox, - playlistStore: playlistStore, - scrobblers: scrobblers, - podcasts: podcasts, - transcoder: transcoder, - lastFMClient: lastFMClient, - artistInfoCache: artistInfoCache, - albumInfoCache: albumInfoCache, + dbc: dbc, + scanner: scannr, + musicPaths: musicPaths, + podcastsPath: podcastsPath, + cacheAudioPath: cacheAudioPath, + cacheCoverPath: cacheCoverPath, + jukebox: jukebox, + playlistStore: playlistStore, + scrobblers: scrobblers, + podcasts: podcasts, + transcoder: transcoder, + lastFMClient: lastFMClient, + artistInfoCache: artistInfoCache, + albumInfoCache: albumInfoCache, + tagReader: tagReader, + resolveProxyPath: resolveProxyPath, } diff --git a/server/ctrlsubsonic/handlers_raw.go b/server/ctrlsubsonic/handlers_raw.go index 73ee80b..cdfc5db 100644 --- a/server/ctrlsubsonic/handlers_raw.go +++ b/server/ctrlsubsonic/handlers_raw.go @@ -85,7 +85,7 @@ func coverFor(dbc *db.DB, artistInfoCache *artistinfocache.ArtistInfoCache, id s case specid.Podcast: return coverForPodcast(dbc, id.Value) case specid.PodcastEpisode: - return coverGetPathPodcastEpisode(dbc, id.Value) + return coverForPodcastEpisode(dbc, id.Value) default: return nil, errCoverNotFound } @@ -135,7 +135,7 @@ func coverForPodcast(dbc *db.DB, id int) (*os.File, error) { return os.Open(filepath.Join(podcast.RootDir, podcast.Image)) } -func coverGetPathPodcastEpisode(dbc *db.DB, id int) (*os.File, error) { +func coverForPodcastEpisode(dbc *db.DB, id int) (*os.File, error) { var pe db.PodcastEpisode err := dbc. Preload("Podcast"). @@ -155,9 +155,10 @@ func coverScaleAndSave(reader io.Reader, cachePath string, size int) error { if err != nil { return fmt.Errorf("resizing: %w", err) } - width := min(size, - // don't upscale images - src.Bounds().Dx()) + + // don't upscale images + width := min(size, src.Bounds().Dx()) + if err := imaging.Save(imaging.Resize(src, width, 0, imaging.Lanczos), cachePath); err != nil { return fmt.Errorf("caching %q: %w", cachePath, err) }