Fix filepath separator and external files on windows

For some reason, '/' is used instead of '\' on windows when loading
lang. FSJoin will now use whatever already exists in the path.
app.GetPath now creates a DirFS from the containing directory instead of
app.systemFS, which fixes loading on windows.
pull/61/head
Harvey Tindall 4 years ago
parent cdc837e781
commit adbb5b9d38
No known key found for this signature in database
GPG Key ID: BBC65952848FB1A2

@ -3,6 +3,7 @@ package main
import (
"fmt"
"io/fs"
"os"
"path/filepath"
"strconv"
"strings"
@ -17,7 +18,8 @@ func (app *appContext) GetPath(sect, key string) (fs.FS, string) {
if strings.HasPrefix(val, "jfa-go:") {
return localFS, strings.TrimPrefix(val, "jfa-go:")
}
return app.systemFS, strings.TrimPrefix(val, "/")
dir, file := filepath.Split(val)
return os.DirFS(dir), file
}
func (app *appContext) loadConfig() error {

@ -5,12 +5,25 @@ import (
"log"
"os"
"path/filepath"
"strings"
)
var localFS fs.FS
var langFS fs.FS
func FSJoin(elem ...string) string { return filepath.Join(elem...) }
// When using os.DirFS, even on Windows the separator seems to be '/'.
// func FSJoin(elem ...string) string { return filepath.Join(elem...) }
func FSJoin(elem ...string) string {
sep := "/"
if strings.Contains(elem[0], "\\") {
sep = "\\"
}
path := ""
for _, el := range elem {
path += el + sep
}
return strings.TrimSuffix(path, sep)
}
func loadFilesystems() {
log.Println("Using external storage")

@ -65,7 +65,6 @@ type appContext struct {
configBasePath string
configBase settings
dataPath string
systemFS fs.FS
webFS httpFS
cssClass string
jellyfinLogin bool
@ -141,7 +140,6 @@ func start(asDaemon, firstCall bool) {
userConfigDir, _ := os.UserConfigDir()
app.dataPath = filepath.Join(userConfigDir, "jfa-go")
app.configPath = filepath.Join(app.dataPath, "config.ini")
app.systemFS = os.DirFS("/")
// gin-static doesn't just take a plain http.FileSystem, so we implement it's ServeFileSystem. See static.go.
app.webFS = httpFS{
hfs: http.FS(localFS),

6
package-lock.json generated

@ -228,9 +228,9 @@
"integrity": "sha1-vfpzUplmTfr9NFKe1PhSKidf6lY="
},
"esbuild": {
"version": "0.8.46",
"resolved": "https://registry.npm.taobao.org/esbuild/download/esbuild-0.8.46.tgz",
"integrity": "sha1-j8cjDOMBmxLiVTOZ8MA4dacpwms="
"version": "0.8.47",
"resolved": "https://registry.npm.taobao.org/esbuild/download/esbuild-0.8.47.tgz",
"integrity": "sha1-XVxZt9y4og3632WpheXlynsk7/I="
},
"escalade": {
"version": "3.1.1",

@ -18,7 +18,7 @@
"homepage": "https://github.com/hrfee/jfa-go#readme",
"dependencies": {
"a17t": "^0.4.0",
"esbuild": "^0.8.46",
"esbuild": "^0.8.47",
"lodash": "^4.17.19",
"mjml": "^4.8.0",
"remixicon": "^2.5.0",

Loading…
Cancel
Save