feat(oss): register OSS in factory and container initialization

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
bingxiang.cheng
2026-04-13 11:57:47 +08:00
parent a584df052d
commit 3bd56c17a8
2 changed files with 46 additions and 0 deletions
@@ -101,6 +101,30 @@ func NewFileServiceFromStorageConfig(
svc, err := NewS3FileService(sec.S3.Endpoint, sec.S3.AccessKey, sec.S3.SecretKey, sec.S3.BucketName, sec.S3.Region, pathPrefix)
return svc, p, err
case "oss":
if sec == nil || sec.OSS == nil || sec.OSS.Endpoint == "" || sec.OSS.Region == "" || sec.OSS.AccessKey == "" || sec.OSS.SecretKey == "" || sec.OSS.BucketName == "" {
return nil, p, fmt.Errorf("incomplete oss config")
}
pathPrefix := strings.TrimSpace(sec.OSS.PathPrefix)
if pathPrefix == "" {
pathPrefix = "weknora/"
}
var svc interfaces.FileService
var err error
if sec.OSS.UseTempBucket && sec.OSS.TempBucketName != "" {
svc, err = NewOssFileServiceWithTempBucket(
sec.OSS.Endpoint, sec.OSS.Region, sec.OSS.AccessKey, sec.OSS.SecretKey,
sec.OSS.BucketName, pathPrefix,
sec.OSS.TempBucketName, sec.OSS.TempRegion,
)
} else {
svc, err = NewOssFileService(
sec.OSS.Endpoint, sec.OSS.Region, sec.OSS.AccessKey, sec.OSS.SecretKey,
sec.OSS.BucketName, pathPrefix,
)
}
return svc, p, err
default:
return nil, p, fmt.Errorf("unsupported provider %q", p)
}
+22
View File
@@ -644,6 +644,28 @@ func initFileService(cfg *config.Config) (interfaces.FileService, error) {
os.Getenv("S3_REGION"),
pathPrefix,
)
case "oss":
if os.Getenv("OSS_ENDPOINT") == "" ||
os.Getenv("OSS_REGION") == "" ||
os.Getenv("OSS_ACCESS_KEY") == "" ||
os.Getenv("OSS_SECRET_KEY") == "" ||
os.Getenv("OSS_BUCKET_NAME") == "" {
return nil, fmt.Errorf("missing OSS configuration")
}
pathPrefix := os.Getenv("OSS_PATH_PREFIX")
if pathPrefix == "" {
pathPrefix = "weknora/"
}
return file.NewOssFileServiceWithTempBucket(
os.Getenv("OSS_ENDPOINT"),
os.Getenv("OSS_REGION"),
os.Getenv("OSS_ACCESS_KEY"),
os.Getenv("OSS_SECRET_KEY"),
os.Getenv("OSS_BUCKET_NAME"),
pathPrefix,
os.Getenv("OSS_TEMP_BUCKET_NAME"),
os.Getenv("OSS_TEMP_REGION"),
)
case "local":
baseDir := os.Getenv("LOCAL_STORAGE_BASE_DIR")
if baseDir == "" {