mirror of
https://github.com/navidrome/navidrome.git
synced 2025-04-13 02:37:18 +03:00
Move static
to resources
. Embed them at build time
This commit is contained in:
parent
b7dcdedf41
commit
1a9663d432
@ -3,6 +3,7 @@ project_name: navidrome
|
|||||||
|
|
||||||
before:
|
before:
|
||||||
hooks:
|
hooks:
|
||||||
|
- go-bindata -fs -prefix resources -tags embed -ignore="\\\*.go" -pkg resources -o resources/embedded_gen.go resources/...
|
||||||
- go-bindata -fs -prefix ui/build -tags embed -nocompress -pkg assets -o assets/embedded_gen.go ui/build/...
|
- go-bindata -fs -prefix ui/build -tags embed -nocompress -pkg assets -o assets/embedded_gen.go ui/build/...
|
||||||
|
|
||||||
builds:
|
builds:
|
||||||
|
@ -35,6 +35,7 @@ RUN GIT_TAG=$(git describe --tags `git rev-list --tags --max-count=1`) && \
|
|||||||
GIT_TAG=${GIT_TAG#"tags/"} && \
|
GIT_TAG=${GIT_TAG#"tags/"} && \
|
||||||
GIT_SHA=$(git rev-parse --short HEAD) && \
|
GIT_SHA=$(git rev-parse --short HEAD) && \
|
||||||
echo "Building version: ${GIT_TAG} (${GIT_SHA})" && \
|
echo "Building version: ${GIT_TAG} (${GIT_SHA})" && \
|
||||||
|
go-bindata -fs -prefix resources -tags embed -ignore="\\\*.go" -pkg resources -o resources/embedded_gen.go resources/...
|
||||||
go-bindata -fs -prefix ui/build -tags embed -nocompress -pkg assets -o assets/embedded_gen.go ui/build/... && \
|
go-bindata -fs -prefix ui/build -tags embed -nocompress -pkg assets -o assets/embedded_gen.go ui/build/... && \
|
||||||
go build -ldflags="-X github.com/deluan/navidrome/consts.gitSha=${GIT_SHA} -X github.com/deluan/navidrome/consts.gitTag=${GIT_TAG}" -tags=embed
|
go build -ldflags="-X github.com/deluan/navidrome/consts.gitSha=${GIT_SHA} -X github.com/deluan/navidrome/consts.gitTag=${GIT_TAG}" -tags=embed
|
||||||
|
|
||||||
|
5
Makefile
5
Makefile
@ -49,10 +49,6 @@ setup-dev: setup
|
|||||||
@lefthook install
|
@lefthook install
|
||||||
.PHONY: setup
|
.PHONY: setup
|
||||||
|
|
||||||
static:
|
|
||||||
cd static && go-bindata -fs -prefix "static" -nocompress -ignore="\\\*.go" -pkg static .
|
|
||||||
.PHONY: static
|
|
||||||
|
|
||||||
Jamstash-master:
|
Jamstash-master:
|
||||||
wget -N https://github.com/tsquillario/Jamstash/archive/master.zip
|
wget -N https://github.com/tsquillario/Jamstash/archive/master.zip
|
||||||
unzip -o master.zip
|
unzip -o master.zip
|
||||||
@ -84,6 +80,7 @@ build: check_go_env
|
|||||||
|
|
||||||
buildall: check_env
|
buildall: check_env
|
||||||
@(cd ./ui && npm run build)
|
@(cd ./ui && npm run build)
|
||||||
|
go-bindata -fs -prefix "resources" -tags embed -ignore="\\\*.go" -pkg resources -o resources/embedded_gen.go resources/...
|
||||||
go-bindata -fs -prefix "ui/build" -tags embed -nocompress -pkg assets -o assets/embedded_gen.go ui/build/...
|
go-bindata -fs -prefix "ui/build" -tags embed -nocompress -pkg assets -o assets/embedded_gen.go ui/build/...
|
||||||
go build -ldflags="-X github.com/deluan/navidrome/consts.gitSha=$(GIT_SHA) -X github.com/deluan/navidrome/consts.gitTag=$(GIT_TAG)-SNAPSHOT" -tags=embed
|
go build -ldflags="-X github.com/deluan/navidrome/consts.gitSha=$(GIT_SHA) -X github.com/deluan/navidrome/consts.gitTag=$(GIT_TAG)-SNAPSHOT" -tags=embed
|
||||||
.PHONY: buildall
|
.PHONY: buildall
|
||||||
|
@ -6,7 +6,6 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"github.com/deluan/navidrome/consts"
|
|
||||||
"github.com/deluan/navidrome/log"
|
"github.com/deluan/navidrome/log"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -14,7 +13,7 @@ var once sync.Once
|
|||||||
|
|
||||||
func AssetFile() http.FileSystem {
|
func AssetFile() http.FileSystem {
|
||||||
once.Do(func() {
|
once.Do(func() {
|
||||||
log.Warn("Using external assets from " + consts.UIAssetsLocalPath)
|
log.Warn("Using external assets from 'ui/build' folder")
|
||||||
})
|
})
|
||||||
return http.Dir(consts.UIAssetsLocalPath)
|
return http.Dir("ui/build")
|
||||||
}
|
}
|
||||||
|
@ -5,11 +5,11 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"unicode"
|
"unicode"
|
||||||
|
|
||||||
"github.com/deluan/navidrome/static"
|
"github.com/deluan/navidrome/resources"
|
||||||
)
|
)
|
||||||
|
|
||||||
func getBanner() string {
|
func getBanner() string {
|
||||||
data, _ := static.Asset("banner.txt")
|
data, _ := resources.Asset("banner.txt")
|
||||||
return strings.TrimRightFunc(string(data), unicode.IsSpace)
|
return strings.TrimRightFunc(string(data), unicode.IsSpace)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -19,8 +19,6 @@ const (
|
|||||||
JWTIssuer = "ND"
|
JWTIssuer = "ND"
|
||||||
DefaultSessionTimeout = 30 * time.Minute
|
DefaultSessionTimeout = 30 * time.Minute
|
||||||
|
|
||||||
UIAssetsLocalPath = "ui/build"
|
|
||||||
|
|
||||||
DevInitialUserName = "admin"
|
DevInitialUserName = "admin"
|
||||||
DevInitialName = "Dev Admin"
|
DevInitialName = "Dev Admin"
|
||||||
|
|
||||||
|
@ -18,7 +18,7 @@ import (
|
|||||||
"github.com/deluan/navidrome/consts"
|
"github.com/deluan/navidrome/consts"
|
||||||
"github.com/deluan/navidrome/log"
|
"github.com/deluan/navidrome/log"
|
||||||
"github.com/deluan/navidrome/model"
|
"github.com/deluan/navidrome/model"
|
||||||
"github.com/deluan/navidrome/static"
|
"github.com/deluan/navidrome/resources"
|
||||||
"github.com/dhowden/tag"
|
"github.com/dhowden/tag"
|
||||||
"github.com/disintegration/imaging"
|
"github.com/disintegration/imaging"
|
||||||
"github.com/djherbis/fscache"
|
"github.com/djherbis/fscache"
|
||||||
@ -122,7 +122,7 @@ func (c *cover) getCover(ctx context.Context, path string, size int) (reader io.
|
|||||||
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 = static.AssetFile().Open("navidrome-310x310.png")
|
reader, err = resources.AssetFile().Open("navidrome-310x310.png")
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
var data []byte
|
var data []byte
|
||||||
|
28
resources/external.go
Normal file
28
resources/external.go
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
// +build !embed
|
||||||
|
|
||||||
|
package resources
|
||||||
|
|
||||||
|
import (
|
||||||
|
"io/ioutil"
|
||||||
|
"net/http"
|
||||||
|
"sync"
|
||||||
|
|
||||||
|
"github.com/deluan/navidrome/log"
|
||||||
|
)
|
||||||
|
|
||||||
|
var once sync.Once
|
||||||
|
|
||||||
|
func Asset(filePath string) ([]byte, error) {
|
||||||
|
f, err := AssetFile().Open(filePath)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return ioutil.ReadAll(f)
|
||||||
|
}
|
||||||
|
|
||||||
|
func AssetFile() http.FileSystem {
|
||||||
|
once.Do(func() {
|
||||||
|
log.Warn("Using external resources from 'resources' folder")
|
||||||
|
})
|
||||||
|
return http.Dir("resources")
|
||||||
|
}
|
Before Width: | Height: | Size: 61 KiB After Width: | Height: | Size: 61 KiB |
@ -7,8 +7,8 @@ import (
|
|||||||
"github.com/deluan/navidrome/engine"
|
"github.com/deluan/navidrome/engine"
|
||||||
"github.com/deluan/navidrome/log"
|
"github.com/deluan/navidrome/log"
|
||||||
"github.com/deluan/navidrome/model"
|
"github.com/deluan/navidrome/model"
|
||||||
|
"github.com/deluan/navidrome/resources"
|
||||||
"github.com/deluan/navidrome/server/subsonic/responses"
|
"github.com/deluan/navidrome/server/subsonic/responses"
|
||||||
"github.com/deluan/navidrome/static"
|
|
||||||
"github.com/deluan/navidrome/utils"
|
"github.com/deluan/navidrome/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -21,7 +21,7 @@ func NewMediaRetrievalController(cover engine.Cover) *MediaRetrievalController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *MediaRetrievalController) GetAvatar(w http.ResponseWriter, r *http.Request) (*responses.Subsonic, error) {
|
func (c *MediaRetrievalController) GetAvatar(w http.ResponseWriter, r *http.Request) (*responses.Subsonic, error) {
|
||||||
f, err := static.AssetFile().Open("navidrome-310x310.png")
|
f, err := resources.AssetFile().Open("navidrome-310x310.png")
|
||||||
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")
|
||||||
|
File diff suppressed because one or more lines are too long
Binary file not shown.
Before Width: | Height: | Size: 22 KiB |
Loading…
x
Reference in New Issue
Block a user