文章编辑器问题

This commit is contained in:
Alex-larget
2026-03-14 23:27:22 +08:00
parent d82ef6d8e4
commit 7ece8f52ff
24 changed files with 642 additions and 217 deletions

View File

@@ -49,6 +49,9 @@ type Config struct {
// 订单对账定时任务间隔分钟0 表示不启动内置定时任务
SyncOrdersIntervalMinutes int
// 上传目录绝对路径air 运行时避免相对路径解析错误)
UploadDir string
}
// BaseURLJoin 将路径拼接到 BaseURLpath 应以 / 开头
@@ -239,6 +242,14 @@ func Load() (*Config, error) {
}
}
// 上传目录:优先 UPLOAD_DIR 环境变量,否则用项目根下的 uploads
uploadDir := strings.TrimSpace(os.Getenv("UPLOAD_DIR"))
if uploadDir == "" {
uploadDir = resolveUploadDir(workDir, execDir)
} else if !filepath.IsAbs(uploadDir) {
uploadDir, _ = filepath.Abs(filepath.Join(workDir, uploadDir))
}
return &Config{
Port: port,
Mode: mode,
@@ -265,5 +276,21 @@ func Load() (*Config, error) {
AdminPassword: adminPassword,
AdminSessionSecret: adminSessionSecret,
SyncOrdersIntervalMinutes: syncOrdersInterval,
UploadDir: uploadDir,
}, nil
}
// resolveUploadDir 解析上传目录绝对路径air 运行时 exe 在 tmp/,需用项目根)
func resolveUploadDir(workDir, execDir string) string {
root := workDir
if execDir != "" {
base := filepath.Base(execDir)
if base == "tmp" {
root = filepath.Dir(execDir)
} else {
root = execDir
}
}
abs, _ := filepath.Abs(filepath.Join(root, "uploads"))
return abs
}