优化结构

This commit is contained in:
Yvan
2026-08-24 13:25:16 +08:00
parent 7a9a738c6a
commit 0b6b8ddf1a
72 changed files with 2475 additions and 1443 deletions
+17 -17
View File
@@ -11,7 +11,7 @@ import (
"sort"
"strings"
"kra/internal/conf"
"kra/internal/config"
)
type fileStorage struct {
@@ -19,41 +19,41 @@ type fileStorage struct {
urlPrefix string
}
func New(config *conf.AdminBackend) (system.FileStorage, error) {
func New(admin *config.Admin) (system.FileStorage, error) {
storageType := "local"
if config != nil && config.Storage != nil && config.Storage.Type != "" {
storageType = strings.ToLower(config.Storage.Type)
if admin != nil && admin.Storage != nil && admin.Storage.Type != "" {
storageType = strings.ToLower(admin.Storage.Type)
}
if storageType == "qiniu" {
return newQiniuStorage(config.Storage.Qiniu)
return newQiniuStorage(admin.Storage.Qiniu)
}
if storageType != "local" {
var object *conf.AdminBackend_ObjectStore
var object *config.ObjectStore
switch storageType {
case "aliyun-oss":
return newAliyunStorage(config.Storage.AliyunOss)
return newAliyunStorage(admin.Storage.AliyunOSS)
case "huawei-obs":
return newHuaweiStorage(config.Storage.HuaweiObs)
return newHuaweiStorage(admin.Storage.HuaweiOBS)
case "tencent-cos":
return newTencentStorage(config.Storage.TencentCos)
return newTencentStorage(admin.Storage.TencentCOS)
case "aws-s3":
return newAWSStorage(storageType, config.Storage.AwsS3)
return newAWSStorage(storageType, admin.Storage.AWSS3)
case "cloudflare-r2":
return newAWSStorage(storageType, config.Storage.CloudflareR2)
return newAWSStorage(storageType, admin.Storage.CloudflareR2)
case "minio":
object = config.Storage.Minio
object = admin.Storage.Minio
default:
return nil, fmt.Errorf("unsupported storage type %q", storageType)
}
return newS3Storage(storageType, object)
}
root, prefix := "uploads/file", "uploads/file"
if config != nil && config.Local != nil {
if config.Local.StorePath != "" {
root = config.Local.StorePath
if admin != nil && admin.Local != nil {
if admin.Local.StorePath != "" {
root = admin.Local.StorePath
}
if config.Local.PathPrefix != "" {
prefix = config.Local.PathPrefix
if admin.Local.PathPrefix != "" {
prefix = admin.Local.PathPrefix
}
}
root = filepath.Clean(root)