feat: 使用配置项替换文件URL中的CDN域名
将硬编码的CDN域名替换为可配置的filePrefix,方便切换文件上传服务地址,并更新本地数据库连接配置。
This commit is contained in:
@@ -239,8 +239,9 @@ func DownloadFile(ossURL string) ([]byte, error) {
|
||||
}
|
||||
|
||||
func GetFileBytesFromURL(ctx context.Context, fileUrl string) ([]byte, error) {
|
||||
newS := strings.ReplaceAll(fileUrl, "http://cdn.redpowerfuture.com", g.Cfg().MustGet(ctx, "filePrefix").String())
|
||||
// 使用 GoFrame 客户端(自带超时、追踪、日志等能力)
|
||||
resp, err := g.Client().Get(ctx, fileUrl)
|
||||
resp, err := g.Client().Get(ctx, newS)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("下载OSS文件失败: %w", err)
|
||||
}
|
||||
@@ -254,7 +255,7 @@ func GetFileBytesFromURL(ctx context.Context, fileUrl string) ([]byte, error) {
|
||||
// 读取全部内容
|
||||
allBytes, err := io.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return nil, gerror.Wrapf(err, "failed to read response body, url: %s", fileUrl)
|
||||
return nil, gerror.Wrapf(err, "failed to read response body, url: %s", newS)
|
||||
}
|
||||
|
||||
return allBytes, nil
|
||||
|
||||
Reference in New Issue
Block a user