mirror of
https://github.com/navidrome/navidrome.git
synced 2025-04-03 04:27:37 +03:00
Small refactorings
This commit is contained in:
parent
08840f6170
commit
7540881695
8 changed files with 13 additions and 19 deletions
|
@ -8,13 +8,12 @@ import (
|
|||
"github.com/navidrome/navidrome/resources"
|
||||
)
|
||||
|
||||
func getBanner() string {
|
||||
func loadBanner() string {
|
||||
data, _ := resources.Asset("banner.txt")
|
||||
return strings.TrimRightFunc(string(data), unicode.IsSpace)
|
||||
}
|
||||
|
||||
func Banner() string {
|
||||
version := "Version: " + Version()
|
||||
padding := strings.Repeat(" ", 52-len(version))
|
||||
return fmt.Sprintf("%s\n%s%s\n", getBanner(), padding, version)
|
||||
return fmt.Sprintf("%s\n%52s\n", loadBanner(), version)
|
||||
}
|
||||
|
|
|
@ -127,7 +127,7 @@ 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.Assets().Open(consts.PlaceholderAlbumArt)
|
||||
reader, err = resources.FS.Open(consts.PlaceholderAlbumArt)
|
||||
}
|
||||
}()
|
||||
|
||||
|
|
|
@ -2,21 +2,16 @@ package resources
|
|||
|
||||
import (
|
||||
"embed"
|
||||
"io/fs"
|
||||
"io/ioutil"
|
||||
)
|
||||
|
||||
//go:embed *
|
||||
var filesystem embed.FS
|
||||
var FS embed.FS
|
||||
|
||||
func Asset(path string) ([]byte, error) {
|
||||
f, err := filesystem.Open(path)
|
||||
f, err := FS.Open(path)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return ioutil.ReadAll(f)
|
||||
}
|
||||
|
||||
func Assets() fs.FS {
|
||||
return filesystem
|
||||
}
|
||||
|
|
|
@ -31,7 +31,7 @@ var (
|
|||
|
||||
func newTranslationRepository(context.Context) rest.Repository {
|
||||
dir := utils.NewMergeFS(
|
||||
http.FS(resources.Assets()),
|
||||
http.FS(resources.FS),
|
||||
http.Dir(filepath.Join(conf.Server.DataFolder, "resources")),
|
||||
)
|
||||
if err := loadTranslations(dir); err != nil {
|
||||
|
|
|
@ -16,7 +16,7 @@ var _ = Describe("Translations", func() {
|
|||
Describe("I18n files", func() {
|
||||
var fs http.FileSystem
|
||||
BeforeEach(func() {
|
||||
fs = http.FS(resources.Assets())
|
||||
fs = http.FS(resources.FS)
|
||||
})
|
||||
It("contains only valid json language files", func() {
|
||||
dir, _ := fs.Open(consts.I18nFolder)
|
||||
|
|
|
@ -65,7 +65,7 @@ func (s *Server) initRoutes() {
|
|||
r.Use(clientUniqueIdAdder)
|
||||
r.Use(loggerInjector)
|
||||
r.Use(requestLogger)
|
||||
r.Use(robotsTXT(ui.Assets()))
|
||||
r.Use(robotsTXT(ui.BuildAssets()))
|
||||
r.Use(authHeaderMapper)
|
||||
r.Use(jwtVerifier)
|
||||
|
||||
|
@ -99,7 +99,7 @@ func (s *Server) initRoutes() {
|
|||
func (s *Server) frontendAssetsHandler() http.Handler {
|
||||
r := chi.NewRouter()
|
||||
|
||||
r.Handle("/", serveIndex(s.ds, ui.Assets()))
|
||||
r.Handle("/*", http.StripPrefix(s.appRoot, http.FileServer(http.FS(ui.Assets()))))
|
||||
r.Handle("/", serveIndex(s.ds, ui.BuildAssets()))
|
||||
r.Handle("/*", http.StripPrefix(s.appRoot, http.FileServer(http.FS(ui.BuildAssets()))))
|
||||
return r
|
||||
}
|
||||
|
|
|
@ -46,7 +46,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.Assets().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")
|
||||
|
|
|
@ -5,10 +5,10 @@ import (
|
|||
"io/fs"
|
||||
)
|
||||
|
||||
//go:embed build/*
|
||||
//go:embed build
|
||||
var filesystem embed.FS
|
||||
|
||||
func Assets() fs.FS {
|
||||
func BuildAssets() fs.FS {
|
||||
build, _ := fs.Sub(filesystem, "build")
|
||||
return build
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue