feat: Modify COS file service initialization parameters and URL processing logic
This commit is contained in:
@@ -23,8 +23,8 @@ type cosFileService struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// NewCosFileService creates a new COS file service instance
|
// NewCosFileService creates a new COS file service instance
|
||||||
func NewCosFileService(appId, region, secretId, secretKey, cosPathPrefix string) (interfaces.FileService, error) {
|
func NewCosFileService(bucketName, region, secretId, secretKey, cosPathPrefix string) (interfaces.FileService, error) {
|
||||||
bucketURL := fmt.Sprintf("https://%s.cos.%s.myqcloud.com", appId, region)
|
bucketURL := fmt.Sprintf("https://%s.cos.%s.myqcloud.com/", bucketName, region)
|
||||||
u, err := url.Parse(bucketURL)
|
u, err := url.Parse(bucketURL)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("failed to parse bucketURL: %w", err)
|
return nil, fmt.Errorf("failed to parse bucketURL: %w", err)
|
||||||
@@ -59,7 +59,7 @@ func (s *cosFileService) SaveFile(ctx context.Context,
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return "", fmt.Errorf("failed to upload file to COS: %w", err)
|
return "", fmt.Errorf("failed to upload file to COS: %w", err)
|
||||||
}
|
}
|
||||||
return fmt.Sprintf("https://%s/%s", s.bucketURL, objectName), nil
|
return fmt.Sprintf("%s%s", s.bucketURL, objectName), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetFile retrieves a file from COS storage by its path URL
|
// GetFile retrieves a file from COS storage by its path URL
|
||||||
|
|||||||
@@ -216,7 +216,7 @@ func initFileService(cfg *config.Config) (interfaces.FileService, error) {
|
|||||||
false,
|
false,
|
||||||
)
|
)
|
||||||
case "cos":
|
case "cos":
|
||||||
if os.Getenv("COS_APP_ID") == "" ||
|
if os.Getenv("COS_BUCKET_NAME") == "" ||
|
||||||
os.Getenv("COS_REGION") == "" ||
|
os.Getenv("COS_REGION") == "" ||
|
||||||
os.Getenv("COS_SECRET_ID") == "" ||
|
os.Getenv("COS_SECRET_ID") == "" ||
|
||||||
os.Getenv("COS_SECRET_KEY") == "" ||
|
os.Getenv("COS_SECRET_KEY") == "" ||
|
||||||
@@ -224,7 +224,7 @@ func initFileService(cfg *config.Config) (interfaces.FileService, error) {
|
|||||||
return nil, fmt.Errorf("missing COS configuration")
|
return nil, fmt.Errorf("missing COS configuration")
|
||||||
}
|
}
|
||||||
return file.NewCosFileService(
|
return file.NewCosFileService(
|
||||||
os.Getenv("COS_APP_ID"),
|
os.Getenv("COS_BUCKET_NAME"),
|
||||||
os.Getenv("COS_REGION"),
|
os.Getenv("COS_REGION"),
|
||||||
os.Getenv("COS_SECRET_ID"),
|
os.Getenv("COS_SECRET_ID"),
|
||||||
os.Getenv("COS_SECRET_KEY"),
|
os.Getenv("COS_SECRET_KEY"),
|
||||||
|
|||||||
Reference in New Issue
Block a user