Simplify resources code, enabling any resource to be overridden (not just translations)

This commit is contained in:
Deluan
2021-10-28 10:25:25 -04:00
parent 9072412812
commit fa3471f527
6 changed files with 30 additions and 20 deletions
+19
View File
@@ -0,0 +1,19 @@
package resources
import (
"fmt"
"strings"
"unicode"
"github.com/navidrome/navidrome/consts"
)
func loadBanner() string {
data, _ := Asset("banner.txt")
return strings.TrimRightFunc(string(data), unicode.IsSpace)
}
func Banner() string {
version := "Version: " + consts.Version()
return fmt.Sprintf("%s\n%52s\n", loadBanner(), version)
}
+18 -2
View File
@@ -3,10 +3,19 @@ package resources
import (
"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")),
}
}

Before

Width:  |  Height:  |  Size: 297 KiB

After

Width:  |  Height:  |  Size: 297 KiB