mirror of
https://github.com/hrfee/jfa-go.git
synced 2025-01-22 08:10:10 +00:00
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.
This commit is contained in:
parent
cdc837e781
commit
adbb5b9d38
@ -3,6 +3,7 @@ package main
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/fs"
|
"io/fs"
|
||||||
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
@ -17,7 +18,8 @@ func (app *appContext) GetPath(sect, key string) (fs.FS, string) {
|
|||||||
if strings.HasPrefix(val, "jfa-go:") {
|
if strings.HasPrefix(val, "jfa-go:") {
|
||||||
return localFS, strings.TrimPrefix(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 {
|
func (app *appContext) loadConfig() error {
|
||||||
|
@ -5,12 +5,25 @@ import (
|
|||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
var localFS fs.FS
|
var localFS fs.FS
|
||||||
var langFS 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() {
|
func loadFilesystems() {
|
||||||
log.Println("Using external storage")
|
log.Println("Using external storage")
|
||||||
|
2
main.go
2
main.go
@ -65,7 +65,6 @@ type appContext struct {
|
|||||||
configBasePath string
|
configBasePath string
|
||||||
configBase settings
|
configBase settings
|
||||||
dataPath string
|
dataPath string
|
||||||
systemFS fs.FS
|
|
||||||
webFS httpFS
|
webFS httpFS
|
||||||
cssClass string
|
cssClass string
|
||||||
jellyfinLogin bool
|
jellyfinLogin bool
|
||||||
@ -141,7 +140,6 @@ func start(asDaemon, firstCall bool) {
|
|||||||
userConfigDir, _ := os.UserConfigDir()
|
userConfigDir, _ := os.UserConfigDir()
|
||||||
app.dataPath = filepath.Join(userConfigDir, "jfa-go")
|
app.dataPath = filepath.Join(userConfigDir, "jfa-go")
|
||||||
app.configPath = filepath.Join(app.dataPath, "config.ini")
|
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.
|
// gin-static doesn't just take a plain http.FileSystem, so we implement it's ServeFileSystem. See static.go.
|
||||||
app.webFS = httpFS{
|
app.webFS = httpFS{
|
||||||
hfs: http.FS(localFS),
|
hfs: http.FS(localFS),
|
||||||
|
6
package-lock.json
generated
6
package-lock.json
generated
@ -228,9 +228,9 @@
|
|||||||
"integrity": "sha1-vfpzUplmTfr9NFKe1PhSKidf6lY="
|
"integrity": "sha1-vfpzUplmTfr9NFKe1PhSKidf6lY="
|
||||||
},
|
},
|
||||||
"esbuild": {
|
"esbuild": {
|
||||||
"version": "0.8.46",
|
"version": "0.8.47",
|
||||||
"resolved": "https://registry.npm.taobao.org/esbuild/download/esbuild-0.8.46.tgz",
|
"resolved": "https://registry.npm.taobao.org/esbuild/download/esbuild-0.8.47.tgz",
|
||||||
"integrity": "sha1-j8cjDOMBmxLiVTOZ8MA4dacpwms="
|
"integrity": "sha1-XVxZt9y4og3632WpheXlynsk7/I="
|
||||||
},
|
},
|
||||||
"escalade": {
|
"escalade": {
|
||||||
"version": "3.1.1",
|
"version": "3.1.1",
|
||||||
|
@ -18,7 +18,7 @@
|
|||||||
"homepage": "https://github.com/hrfee/jfa-go#readme",
|
"homepage": "https://github.com/hrfee/jfa-go#readme",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"a17t": "^0.4.0",
|
"a17t": "^0.4.0",
|
||||||
"esbuild": "^0.8.46",
|
"esbuild": "^0.8.47",
|
||||||
"lodash": "^4.17.19",
|
"lodash": "^4.17.19",
|
||||||
"mjml": "^4.8.0",
|
"mjml": "^4.8.0",
|
||||||
"remixicon": "^2.5.0",
|
"remixicon": "^2.5.0",
|
||||||
|
Loading…
Reference in New Issue
Block a user