mirror of
https://github.com/navidrome/navidrome.git
synced 2025-04-04 13:07:36 +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() {
|
defer func() {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Warn(ctx, "Error extracting image", "path", path, "size", size, err)
|
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 {
|
if size != 0 && err == nil {
|
||||||
var r io.ReadCloser
|
var r io.ReadCloser
|
||||||
r, err = resources.FS.Open(consts.PlaceholderAlbumArt)
|
r, err = resources.FS().Open(consts.PlaceholderAlbumArt)
|
||||||
reader, err = resizeImage(r, size, true)
|
reader, err = resizeImage(r, size, true)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,20 +14,19 @@ import (
|
||||||
var (
|
var (
|
||||||
//go:embed *
|
//go:embed *
|
||||||
fsys embed.FS
|
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) {
|
func Asset(path string) ([]byte, error) {
|
||||||
f, err := FS.Open(path)
|
f, err := FS().Open(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return io.ReadAll(f)
|
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 {
|
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)
|
log.Error("Error loading translation files", err)
|
||||||
}
|
}
|
||||||
return &translationRepository{}
|
return &translationRepository{}
|
||||||
|
|
|
@ -3,7 +3,7 @@ package nativeapi
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"io/fs"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
|
@ -15,17 +15,14 @@ import (
|
||||||
|
|
||||||
var _ = Describe("Translations", func() {
|
var _ = Describe("Translations", func() {
|
||||||
Describe("I18n files", func() {
|
Describe("I18n files", func() {
|
||||||
var fs http.FileSystem
|
|
||||||
BeforeEach(func() {
|
|
||||||
fs = http.FS(resources.FS)
|
|
||||||
})
|
|
||||||
It("contains only valid json language files", func() {
|
It("contains only valid json language files", func() {
|
||||||
dir, _ := fs.Open(consts.I18nFolder)
|
fsys := resources.FS()
|
||||||
files, _ := dir.Readdir(0)
|
dir, _ := fsys.Open(consts.I18nFolder)
|
||||||
|
files, _ := dir.(fs.ReadDirFile).ReadDir(-1)
|
||||||
for _, f := range files {
|
for _, f := range files {
|
||||||
name := filepath.Base(f.Name())
|
name := filepath.Base(f.Name())
|
||||||
filePath := filepath.Join(consts.I18nFolder, name)
|
filePath := filepath.Join(consts.I18nFolder, name)
|
||||||
file, _ := fs.Open(filePath)
|
file, _ := fsys.Open(filePath)
|
||||||
data, _ := io.ReadAll(file)
|
data, _ := io.ReadAll(file)
|
||||||
var out map[string]interface{}
|
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) {
|
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 {
|
if err != nil {
|
||||||
log.Error(r, "Image not found", err)
|
log.Error(r, "Image not found", err)
|
||||||
return nil, newError(responses.ErrorDataNotFound, "Avatar image not found")
|
return nil, newError(responses.ErrorDataNotFound, "Avatar image not found")
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue