From d84b5fe777f0fbdf9f81066ec39255a1ddd1f4cc Mon Sep 17 00:00:00 2001 From: lzh <1625167628@qq.com> Date: Fri, 6 Jun 2025 11:41:36 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=A0=B9=E8=B7=AF=E5=BE=84?= =?UTF-8?q?=E4=BD=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cmd/app.go | 19 ++++++++++--------- service/files.go | 4 ++-- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/cmd/app.go b/cmd/app.go index 848480d..63d6098 100644 --- a/cmd/app.go +++ b/cmd/app.go @@ -13,8 +13,17 @@ import ( "github.com/filebrowser/filebrowser/v2/service" ) +func init() { + if os.Getenv("MODE_ENV") != "" { + os.Setenv(constant.ConfigFileEnvKey, fmt.Sprintf("./conf/%s/%s", os.Getenv("MODE_ENV"), "dubbogo.yaml")) + service.BasePath = "./data" + } else { + os.Setenv(constant.ConfigFileEnvKey, "../conf/dubbogo.yaml") + service.BasePath = "../" + } +} + func main() { - initEnv() config.SetProviderService(&service.FilesProvider{}) if err := config.Load(); err != nil { panic(err) @@ -25,11 +34,3 @@ func main() { log.Printf("Caught signal %s: shutting down.", sig) os.Exit(0) } - -func initEnv() { - if os.Getenv("MODE_ENV") != "" { - os.Setenv(constant.ConfigFileEnvKey, fmt.Sprintf("./conf/%s/%s", os.Getenv("MODE_ENV"), "dubbogo.yaml")) - } else { - os.Setenv(constant.ConfigFileEnvKey, "../conf/dubbogo.yaml") - } -} diff --git a/service/files.go b/service/files.go index f501cd6..0e643eb 100644 --- a/service/files.go +++ b/service/files.go @@ -31,7 +31,7 @@ type FilesProvider struct { filesApi.UnimplementedFileServer } -const BASE_PATH = "../" +var BasePath = "../" var imgSvc = img.New(4) // 图片预览可用协程数 @@ -459,7 +459,7 @@ func newFileDownloadWriter(stream filesApi.File_DirDownloadServer) *fileDownload } func getFs(userSpacePath string) afero.Fs { - bashAbs, _ := filepath.Abs(BASE_PATH) + bashAbs, _ := filepath.Abs(BasePath) if !strings.HasPrefix(userSpacePath, "/") { userSpacePath = "/" + userSpacePath