🎧 Your Personal Streaming Service
Go airsonicmadsonicmedia-servermusicmusic-servernavidromeopensubsonicraspberry-piself-hostedstreamerstreaming-apistreaming-audiosubsonicsubsonic-server
Simplify `resources` code, enabling any resource to be overridden (not just translations)
Deluanfa3471f527e1
diff --git a/cmd/root.go b/cmd/root.goindex dbeef0f6b..50c33a09c 100644--- a/cmd/root.go+++ b/cmd/root.go@@ -10,6 +10,7 @@ import ("github.com/navidrome/navidrome/consts""github.com/navidrome/navidrome/db""github.com/navidrome/navidrome/log"+ "github.com/navidrome/navidrome/resources""github.com/navidrome/navidrome/scheduler""github.com/oklog/run""github.com/spf13/cobra"@@ -45,7 +46,7 @@ func Execute() {func preRun() {if !noBanner {- println(consts.Banner())+ println(resources.Banner())}conf.Load()}diff --git a/consts/consts.go b/consts/consts.goindex 57cd36b03..0471cf7f5 100644--- a/consts/consts.go+++ b/consts/consts.go@@ -44,7 +44,7 @@ const (I18nFolder = "i18n"SkipScanFile = ".ndignore"- PlaceholderAlbumArt = "navidrome-600x600.png"+ PlaceholderAlbumArt = "placeholder.png"PlaceholderAvatar = "logo-192x192.png"DefaultHttpClientTimeOut = 10 * time.Seconddiff --git a/consts/banner.go b/resources/banner.gosimilarity index 61%rename from consts/banner.gorename to resources/banner.goindex 296dd8f48..a71830855 100644--- a/consts/banner.go+++ b/resources/banner.go@@ -1,19 +1,19 @@-package consts+package resourcesimport ("fmt""strings""unicode"- "github.com/navidrome/navidrome/resources"+ "github.com/navidrome/navidrome/consts")func loadBanner() string {- data, _ := resources.Asset("banner.txt")+ data, _ := Asset("banner.txt")return strings.TrimRightFunc(string(data), unicode.IsSpace)}func Banner() string {- version := "Version: " + Version()+ version := "Version: " + consts.Version()return fmt.Sprintf("%s\n%52s\n", loadBanner(), version)}diff --git a/resources/embed.go b/resources/embed.goindex 4228d5522..28517ccca 100644--- a/resources/embed.go+++ b/resources/embed.go@@ -3,10 +3,19 @@ package resourcesimport ("embed""io"+ "io/fs"+ "os"+ "path"++ "github.com/navidrome/navidrome/conf"+ "github.com/navidrome/navidrome/utils")-//go:embed *-var FS embed.FS+var (+ //go:embed *+ fsys embed.FS+ FS fs.FS+)func Asset(path string) ([]byte, error) {f, err := FS.Open(path)@@ -15,3 +24,10 @@ func Asset(path string) ([]byte, error) {}return io.ReadAll(f)}++func init() {+ FS = utils.MergeFS{+ Base: fsys,+ Overlay: os.DirFS(path.Join(conf.Server.DataFolder, "resources")),+ }+}diff --git a/resources/navidrome-600x600.png b/resources/placeholder.pngsimilarity index 100%rename from resources/navidrome-600x600.pngrename to resources/placeholder.pngdiff --git a/server/nativeapi/translations.go b/server/nativeapi/translations.goindex 5fb93b8eb..aa38e558a 100644--- a/server/nativeapi/translations.go+++ b/server/nativeapi/translations.go@@ -6,17 +6,14 @@ import ("encoding/json""io""io/fs"- "os""path""strings""sync""github.com/deluan/rest"- "github.com/navidrome/navidrome/conf""github.com/navidrome/navidrome/consts""github.com/navidrome/navidrome/log""github.com/navidrome/navidrome/resources"- "github.com/navidrome/navidrome/utils")type translation struct {@@ -31,11 +28,7 @@ var ()func newTranslationRepository(context.Context) rest.Repository {- dir := utils.MergeFS{- Base: resources.FS,- Overlay: os.DirFS(path.Join(conf.Server.DataFolder, "resources")),- }- if err := loadTranslations(dir); err != nil {+ if err := loadTranslations(resources.FS); err != nil {log.Error("Error loading translation files", err)}return &translationRepository{}@@ -50,13 +43,13 @@ func (r *translationRepository) Read(id string) (interface{}, error) {return nil, rest.ErrNotFound}-// Simple Count implementation. Does not support any `options`-func (r *translationRepository) Count(options ...rest.QueryOptions) (int64, error) {+// Count simple implementation, does not support any `options`+func (r *translationRepository) Count(...rest.QueryOptions) (int64, error) {return int64(len(translations)), nil}-// Simple ReadAll implementation, only returns IDs. Does not support any `options`-func (r *translationRepository) ReadAll(options ...rest.QueryOptions) (interface{}, error) {+// ReadAll simple implementation, only returns IDs. Does not support any `options`+func (r *translationRepository) ReadAll(...rest.QueryOptions) (interface{}, error) {var result []translationfor _, t := range translations {t.Data = ""