From eeb322dcf5331a436cb5faffb2051e2d70bf652c Mon Sep 17 00:00:00 2001 From: fusikai Date: Fri, 5 May 2023 14:22:09 +0800 Subject: [PATCH] =?UTF-8?q?=E5=85=BC=E5=AE=B9window?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/apiv1/static/filesystem.go | 5 +++++ assets/assets.go | 4 +++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/api/apiv1/static/filesystem.go b/api/apiv1/static/filesystem.go index 0550976cd..b32be2303 100644 --- a/api/apiv1/static/filesystem.go +++ b/api/apiv1/static/filesystem.go @@ -28,6 +28,8 @@ func (d Dir) Exists(name string) bool { } fullName := filepath.Join(dir, filepath.FromSlash(path.Clean("/"+name))) fullName = strings.TrimPrefix(fullName, strings.TrimPrefix(Prefix, "/")) + fullName = strings.TrimPrefix(fullName, string(filepath.Separator)) + fullName = strings.ReplaceAll(fullName, "\\", "/") _, err := statikFS.Open(fullName) return err == nil } @@ -38,7 +40,10 @@ func (d Dir) Open(name string) (http.File, error) { if dir == "" { dir = "." } + fullName := filepath.Join(dir, filepath.FromSlash(path.Clean("/"+name))) fullName = strings.TrimPrefix(fullName, strings.TrimPrefix(Prefix, "/")) + fullName = strings.TrimPrefix(fullName, string(filepath.Separator)) + fullName = strings.ReplaceAll(fullName, "\\", "/") return statikFS.Open(fullName) } diff --git a/assets/assets.go b/assets/assets.go index 136703b67..ac11c7573 100644 --- a/assets/assets.go +++ b/assets/assets.go @@ -5,10 +5,12 @@ package assets import ( "net/http" + "path/filepath" ) var AssetsEmbedded = false func Assets() (http.FileSystem, error) { - return http.Dir("./assets/dist"), nil + pathDir := filepath.Join(".", "assets", "dist") + return http.Dir(pathDir), nil }