Simplify resources code, enabling any resource to be overridden (not just translations)
This commit is contained in:
@@ -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
@@ -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 |
Reference in New Issue
Block a user