🎧 Your Personal Streaming Service
Go airsonicmadsonicmedia-servermusicmusic-servernavidromeopensubsonicraspberry-piself-hostedstreamerstreaming-apistreaming-audiosubsonicsubsonic-server
Remove CoverArtID, fix tests
Deluanc36e77d41f6b
diff --git a/core/artwork_test.go b/core/artwork_test.goindex 5c95455e8..1aa6838eb 100644--- a/core/artwork_test.go+++ b/core/artwork_test.go@@ -2,28 +2,23 @@ package coreimport ("context"- "image"- "os"- "github.com/navidrome/navidrome/conf""github.com/navidrome/navidrome/log""github.com/navidrome/navidrome/model""github.com/navidrome/navidrome/tests". "github.com/onsi/ginkgo/v2"- . "github.com/onsi/gomega")var _ = Describe("Artwork", func() {- var artwork Artworkvar ds model.DataStorectx := log.NewContext(context.TODO())BeforeEach(func() {ds = &tests.MockDataStore{MockedTranscoding: &tests.MockTranscodingRepo{}}ds.Album(ctx).(*tests.MockAlbumRepo).SetData(model.Albums{- {ID: "222", EmbedArtId: "123", EmbedArtPath: "tests/fixtures/test.mp3"},- {ID: "333", EmbedArtId: ""},- {ID: "444", EmbedArtId: "444", EmbedArtPath: "tests/fixtures/cover.jpg"},+ {ID: "222", EmbedArtPath: "tests/fixtures/test.mp3"},+ {ID: "333"},+ {ID: "444", EmbedArtPath: "tests/fixtures/cover.jpg"},})ds.MediaFile(ctx).(*tests.MockMediaFileRepo).SetData(model.MediaFiles{{ID: "123", AlbumID: "222", Path: "tests/fixtures/test.mp3", HasCoverArt: true},@@ -31,114 +26,4 @@ var _ = Describe("Artwork", func() {})})- Context("Cache is configured", func() {- BeforeEach(func() {- conf.Server.DataFolder, _ = os.MkdirTemp("", "file_caches")- conf.Server.ImageCacheSize = "100MB"- cache := GetImageCache()- Eventually(func() bool { return cache.Ready(context.TODO()) }).Should(BeTrue())- artwork = NewArtwork(ds, cache)- })- AfterEach(func() {- _ = os.RemoveAll(conf.Server.DataFolder)- })-- It("retrieves the external artwork art for an album", func() {- r, err := artwork.Get(ctx, "al-444", 0)- Expect(err).To(BeNil())-- _, format, err := image.Decode(r)- Expect(err).To(BeNil())- Expect(format).To(Equal("jpeg"))- Expect(r.Close()).To(BeNil())- })-- It("retrieves the embedded artwork art for an album", func() {- r, err := artwork.Get(ctx, "al-222", 0)- Expect(err).To(BeNil())-- _, format, err := image.Decode(r)- Expect(err).To(BeNil())- Expect(format).To(Equal("jpeg"))- Expect(r.Close()).To(BeNil())- })-- It("returns the default artwork if album does not have artwork", func() {- r, err := artwork.Get(ctx, "al-333", 0)- Expect(err).To(BeNil())-- _, format, err := image.Decode(r)- Expect(err).To(BeNil())- Expect(format).To(Equal("png"))- Expect(r.Close()).To(BeNil())- })-- It("returns the default artwork if album is not found", func() {- r, err := artwork.Get(ctx, "al-0101", 0)- Expect(err).To(BeNil())-- _, format, err := image.Decode(r)- Expect(err).To(BeNil())- Expect(format).To(Equal("png"))- Expect(r.Close()).To(BeNil())- })-- It("retrieves the original artwork art from a media_file", func() {- r, err := artwork.Get(ctx, "123", 0)- Expect(err).To(BeNil())-- img, format, err := image.Decode(r)- Expect(err).To(BeNil())- Expect(format).To(Equal("jpeg"))- Expect(img.Bounds().Size().X).To(Equal(600))- Expect(img.Bounds().Size().Y).To(Equal(600))- Expect(r.Close()).To(BeNil())- })-- It("retrieves the album artwork art if media_file does not have one", func() {- r, err := artwork.Get(ctx, "456", 0)- Expect(err).To(BeNil())-- _, format, err := image.Decode(r)- Expect(err).To(BeNil())- Expect(format).To(Equal("jpeg"))- Expect(r.Close()).To(BeNil())- })-- It("retrieves the album artwork by album id", func() {- r, err := artwork.Get(ctx, "222", 0)- Expect(err).To(BeNil())-- _, format, err := image.Decode(r)- Expect(err).To(BeNil())- Expect(format).To(Equal("jpeg"))- Expect(r.Close()).To(BeNil())- })-- It("resized artwork art as requested", func() {- r, err := artwork.Get(ctx, "123", 200)- Expect(err).To(BeNil())-- img, format, err := image.Decode(r)- Expect(err).To(BeNil())- Expect(format).To(Equal("jpeg"))- Expect(img.Bounds().Size().X).To(Equal(200))- Expect(img.Bounds().Size().Y).To(Equal(200))- Expect(r.Close()).To(BeNil())- })-- Context("Errors", func() {- It("returns err if gets error from album table", func() {- ds.Album(ctx).(*tests.MockAlbumRepo).SetError(true)- _, err := artwork.Get(ctx, "al-222", 0)- Expect(err).To(MatchError("Error!"))- })-- It("returns err if gets error from media_file table", func() {- ds.MediaFile(ctx).(*tests.MockMediaFileRepo).SetError(true)- _, err := artwork.Get(ctx, "123", 0)- Expect(err).To(MatchError("Error!"))- })- })- })})diff --git a/db/migration/20221219140528_remove_cover_art_id.go b/db/migration/20221219140528_remove_cover_art_id.gonew file mode 100644index 000000000..98554f5bc--- /dev/null+++ b/db/migration/20221219140528_remove_cover_art_id.go@@ -0,0 +1,27 @@+package migrations++import (+ "database/sql"++ "github.com/pressly/goose"+)++func init() {+ goose.AddMigration(upRemoveCoverArtId, downRemoveCoverArtId)+}++func upRemoveCoverArtId(tx *sql.Tx) error {+ _, err := tx.Exec(`+alter table album drop column cover_art_id;+alter table album rename column cover_art_path to embed_art_path+`)+ if err != nil {+ return err+ }+ notice(tx, "A full rescan needs to be performed to import all album images")+ return forceFullRescan(tx)+}++func downRemoveCoverArtId(tx *sql.Tx) error {+ return nil+}diff --git a/model/album.go b/model/album.goindex 9e7203ae3..86de99d43 100644--- a/model/album.go+++ b/model/album.go@@ -7,8 +7,7 @@ type Album struct {ID string `structs:"id" json:"id" orm:"column(id)"`Name string `structs:"name" json:"name"`- EmbedArtPath string `structs:"cover_art_path" json:"coverArtPath"`- EmbedArtId string `structs:"cover_art_id" json:"coverArtId"`+ EmbedArtPath string `structs:"embed_art_path" json:"embedArtPath"`ArtistID string `structs:"artist_id" json:"artistId" orm:"column(artist_id)"`Artist string `structs:"artist" json:"artist"`AlbumArtistID string `structs:"album_artist_id" json:"albumArtistId" orm:"column(album_artist_id)"`diff --git a/model/mediafile.go b/model/mediafile.goindex e0ce424b3..83275cc6e 100644--- a/model/mediafile.go+++ b/model/mediafile.go@@ -135,8 +135,7 @@ func (mfs MediaFiles) ToAlbum() Album {m.Album, m.AlbumArtist, m.Artist,m.SortAlbumName, m.SortAlbumArtistName, m.SortArtistName,m.DiscSubtitle)- if m.HasCoverArt && a.EmbedArtId == "" {- a.EmbedArtId = m.ID+ if m.HasCoverArt && a.EmbedArtPath == "" {a.EmbedArtPath = m.Path}}diff --git a/model/mediafile_test.go b/model/mediafile_test.goindex eefd0a6ca..8d498797b 100644--- a/model/mediafile_test.go+++ b/model/mediafile_test.go@@ -51,7 +51,6 @@ var _ = Describe("MediaFiles", func() {Expect(album.MbzAlbumComment).To(Equal("MbzAlbumComment"))Expect(album.CatalogNum).To(Equal("CatalogNum"))Expect(album.Compilation).To(BeTrue())- Expect(album.EmbedArtId).To(Equal("2"))Expect(album.EmbedArtPath).To(Equal("/music/file.mp3"))})})diff --git a/persistence/persistence_suite_test.go b/persistence/persistence_suite_test.goindex 9ec2f85ef..b2d5016d9 100644--- a/persistence/persistence_suite_test.go+++ b/persistence/persistence_suite_test.go@@ -46,9 +46,9 @@ var ()var (- albumSgtPeppers = model.Album{ID: "101", Name: "Sgt Peppers", Artist: "The Beatles", OrderAlbumName: "sgt peppers", AlbumArtistID: "3", Genre: "Rock", Genres: model.Genres{genreRock}, EmbedArtId: "1", EmbedArtPath: P("/beatles/1/sgt/a day.mp3"), SongCount: 1, MaxYear: 1967, FullText: " beatles peppers sgt the"}- albumAbbeyRoad = model.Album{ID: "102", Name: "Abbey Road", Artist: "The Beatles", OrderAlbumName: "abbey road", AlbumArtistID: "3", Genre: "Rock", Genres: model.Genres{genreRock}, EmbedArtId: "2", EmbedArtPath: P("/beatles/1/come together.mp3"), SongCount: 1, MaxYear: 1969, FullText: " abbey beatles road the"}- albumRadioactivity = model.Album{ID: "103", Name: "Radioactivity", Artist: "Kraftwerk", OrderAlbumName: "radioactivity", AlbumArtistID: "2", Genre: "Electronic", Genres: model.Genres{genreElectronic, genreRock}, EmbedArtId: "3", EmbedArtPath: P("/kraft/radio/radio.mp3"), SongCount: 2, FullText: " kraftwerk radioactivity"}+ albumSgtPeppers = model.Album{ID: "101", Name: "Sgt Peppers", Artist: "The Beatles", OrderAlbumName: "sgt peppers", AlbumArtistID: "3", Genre: "Rock", Genres: model.Genres{genreRock}, EmbedArtPath: P("/beatles/1/sgt/a day.mp3"), SongCount: 1, MaxYear: 1967, FullText: " beatles peppers sgt the"}+ albumAbbeyRoad = model.Album{ID: "102", Name: "Abbey Road", Artist: "The Beatles", OrderAlbumName: "abbey road", AlbumArtistID: "3", Genre: "Rock", Genres: model.Genres{genreRock}, EmbedArtPath: P("/beatles/1/come together.mp3"), SongCount: 1, MaxYear: 1969, FullText: " abbey beatles road the"}+ albumRadioactivity = model.Album{ID: "103", Name: "Radioactivity", Artist: "Kraftwerk", OrderAlbumName: "radioactivity", AlbumArtistID: "2", Genre: "Electronic", Genres: model.Genres{genreElectronic, genreRock}, EmbedArtPath: P("/kraft/radio/radio.mp3"), SongCount: 2, FullText: " kraftwerk radioactivity"}testAlbums = model.Albums{albumSgtPeppers,albumAbbeyRoad,