feat(album): add uploaded_image column and path helper

This commit is contained in:
Deluan 2026-07-17 18:43:47 -04:00
commit 0d8ba90b13
4 changed files with 26 additions and 0 deletions

View file

@ -124,6 +124,7 @@ const (
// Entity types
const (
EntityArtist = "artist"
EntityAlbum = "album"
EntityPlaylist = "playlist"
EntityRadio = "radio"
)

View file

@ -0,0 +1,5 @@
-- +goose Up
ALTER TABLE album ADD COLUMN uploaded_image varchar NOT NULL DEFAULT '';
-- +goose Down
ALTER TABLE album DROP COLUMN uploaded_image;

View file

@ -8,6 +8,7 @@ import (
"time"
"github.com/navidrome/navidrome/conf"
"github.com/navidrome/navidrome/consts"
"github.com/gohugoio/hashstructure"
)
@ -49,6 +50,7 @@ type Album struct {
MbzReleaseGroupID string `structs:"mbz_release_group_id" json:"mbzReleaseGroupId,omitempty"`
FolderIDs []string `structs:"folder_ids" json:"-" hash:"set"` // All folders that contain media_files for this album
ExplicitStatus string `structs:"explicit_status" json:"explicitStatus"`
UploadedImage string `structs:"-" json:"uploadedImage,omitempty" hash:"ignore"`
// External metadata fields
Description string `structs:"description" json:"description,omitempty" hash:"ignore"`
@ -73,6 +75,10 @@ func (a Album) CoverArtID() ArtworkID {
return artworkIDFromAlbum(a)
}
func (a Album) UploadedImagePath() string {
return UploadedImagePath(consts.EntityAlbum, a.UploadedImage)
}
func (a Album) FullName() string {
if conf.Server.Subsonic.AppendAlbumVersion && len(a.Tags[TagAlbumVersion]) > 0 {
return fmt.Sprintf("%s (%s)", a.Name, a.Tags[TagAlbumVersion][0])

View file

@ -2,6 +2,7 @@ package model_test
import (
"encoding/json"
"path/filepath"
"github.com/navidrome/navidrome/conf"
"github.com/navidrome/navidrome/conf/configtest"
@ -25,6 +26,19 @@ var _ = Describe("Album", func() {
Entry("returns just name when tag is absent", true, Tags{}, "Album"),
Entry("returns just name when tag is an empty slice", true, Tags{TagAlbumVersion: []string{}}, "Album"),
)
Describe("UploadedImagePath", func() {
BeforeEach(func() {
conf.Server.DataFolder = conf.NewDir("/data")
})
It("returns empty when no image was uploaded", func() {
Expect(Album{ID: "al-1"}.UploadedImagePath()).To(BeEmpty())
})
It("returns the path under the data folder when set", func() {
a := Album{ID: "al-1", UploadedImage: "al-1_cover.jpg"}
Expect(a.UploadedImagePath()).To(Equal(filepath.Join("/data", "artwork", "album", "al-1_cover.jpg")))
})
})
})
var _ = Describe("Albums", func() {