diff --git a/core/artwork.go b/core/artwork.go index 36799ac99..d4d6a5253 100644 --- a/core/artwork.go +++ b/core/artwork.go @@ -127,11 +127,11 @@ func (a *artwork) getArtwork(ctx context.Context, id string, path string, size i defer func() { if err != nil { log.Warn(ctx, "Error extracting image", "path", path, "size", size, err) - reader, err = resources.FS.Open(consts.PlaceholderAlbumArt) + reader, err = resources.FS().Open(consts.PlaceholderAlbumArt) if size != 0 && err == nil { var r io.ReadCloser - r, err = resources.FS.Open(consts.PlaceholderAlbumArt) + r, err = resources.FS().Open(consts.PlaceholderAlbumArt) reader, err = resizeImage(r, size, true) } } diff --git a/resources/embed.go b/resources/embed.go index 28517ccca..860e3130f 100644 --- a/resources/embed.go +++ b/resources/embed.go @@ -14,20 +14,19 @@ import ( var ( //go:embed * fsys embed.FS - FS fs.FS ) +func FS() fs.FS { + return utils.MergeFS{ + Base: fsys, + Overlay: os.DirFS(path.Join(conf.Server.DataFolder, "resources")), + } +} + func Asset(path string) ([]byte, error) { - f, err := FS.Open(path) + f, err := FS().Open(path) if err != nil { return nil, err } return io.ReadAll(f) } - -func init() { - FS = utils.MergeFS{ - Base: fsys, - Overlay: os.DirFS(path.Join(conf.Server.DataFolder, "resources")), - } -} diff --git a/server/nativeapi/translations.go b/server/nativeapi/translations.go index aa38e558a..ebcf3f6b9 100644 --- a/server/nativeapi/translations.go +++ b/server/nativeapi/translations.go @@ -28,7 +28,7 @@ var ( ) func newTranslationRepository(context.Context) rest.Repository { - if err := loadTranslations(resources.FS); err != nil { + if err := loadTranslations(resources.FS()); err != nil { log.Error("Error loading translation files", err) } return &translationRepository{} diff --git a/server/nativeapi/translations_test.go b/server/nativeapi/translations_test.go index 4e99b3200..bc3b756b9 100644 --- a/server/nativeapi/translations_test.go +++ b/server/nativeapi/translations_test.go @@ -3,7 +3,7 @@ package nativeapi import ( "encoding/json" "io" - "net/http" + "io/fs" "os" "path/filepath" @@ -15,17 +15,14 @@ import ( var _ = Describe("Translations", func() { Describe("I18n files", func() { - var fs http.FileSystem - BeforeEach(func() { - fs = http.FS(resources.FS) - }) It("contains only valid json language files", func() { - dir, _ := fs.Open(consts.I18nFolder) - files, _ := dir.Readdir(0) + fsys := resources.FS() + dir, _ := fsys.Open(consts.I18nFolder) + files, _ := dir.(fs.ReadDirFile).ReadDir(-1) for _, f := range files { name := filepath.Base(f.Name()) filePath := filepath.Join(consts.I18nFolder, name) - file, _ := fs.Open(filePath) + file, _ := fsys.Open(filePath) data, _ := io.ReadAll(file) var out map[string]interface{} diff --git a/server/subsonic/media_retrieval.go b/server/subsonic/media_retrieval.go index 30a6bf3a6..3ed8632e2 100644 --- a/server/subsonic/media_retrieval.go +++ b/server/subsonic/media_retrieval.go @@ -48,7 +48,7 @@ func (c *MediaRetrievalController) GetAvatar(w http.ResponseWriter, r *http.Requ } func (c *MediaRetrievalController) getPlaceHolderAvatar(w http.ResponseWriter, r *http.Request) (*responses.Subsonic, error) { - f, err := resources.FS.Open(consts.PlaceholderAvatar) + f, err := resources.FS().Open(consts.PlaceholderAvatar) if err != nil { log.Error(r, "Image not found", err) return nil, newError(responses.ErrorDataNotFound, "Avatar image not found")