mirror of
https://github.com/navidrome/navidrome.git
synced 2025-04-03 20:47:35 +03:00
Fix loading overridden translations from ${DataFolder}/resources/i18n
This commit is contained in:
parent
50ff8bcce7
commit
028723f721
5 changed files with 17 additions and 21 deletions
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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")),
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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{}
|
||||
|
|
|
@ -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{}
|
||||
|
||||
|
|
|
@ -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")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue