i18n翻译
This commit is contained in:
@@ -195,6 +195,25 @@ func (t *ThirdPartyDataSync) processAndSaveHeroData(ctx context.Context, data []
|
||||
//zhAttribute := i18n.GetZh(ctx, hero.Attribute)
|
||||
fmt.Println(hero.Assets.Image)
|
||||
|
||||
// 上传图片到 OSS,并获取自定义域名的访问路径
|
||||
ossObjectKey := fmt.Sprintf("epic/hero/images/%s.png", hero.Code)
|
||||
ossUrl, err := util.DownloadAndUploadToOSS(ctx, hero.Assets.Icon, ossObjectKey)
|
||||
if err != nil {
|
||||
g.Log().Error(ctx, "上传英雄图片到OSS失败:", err)
|
||||
return err // 直接返回,后续数据库不会插入
|
||||
}
|
||||
fmt.Println(ossUrl)
|
||||
// 替换为自定义域名
|
||||
customImgUrl := ""
|
||||
if ossUrl != "" {
|
||||
prefix := consts.S3Endpoint + "/" + consts.S3Bucket
|
||||
if len(ossUrl) > len(prefix) && ossUrl[:len(prefix)] == prefix {
|
||||
customImgUrl = consts.S3CustomDomain + ossUrl[len(prefix):]
|
||||
} else {
|
||||
customImgUrl = ossUrl // fallback
|
||||
}
|
||||
}
|
||||
|
||||
newHero := &entity.EpicHeroInfo{
|
||||
Id: 0,
|
||||
HeroName: zhHeroName,
|
||||
@@ -209,7 +228,7 @@ func (t *ThirdPartyDataSync) processAndSaveHeroData(ctx context.Context, data []
|
||||
Rarity: strconv.Itoa(hero.Rarity),
|
||||
Role: hero.Role,
|
||||
//Zodiac: "",
|
||||
HeadImgUrl: "",
|
||||
HeadImgUrl: customImgUrl,
|
||||
Attribute: hero.Attribute,
|
||||
Remark: "",
|
||||
RawJson: heroJson,
|
||||
@@ -221,6 +240,15 @@ func (t *ThirdPartyDataSync) processAndSaveHeroData(ctx context.Context, data []
|
||||
continue
|
||||
}
|
||||
g.Log().Debug(ctx, "插入新英雄:", hero.Code)
|
||||
|
||||
// 新增后立即刷新该图片的OSS预签名URL到缓存
|
||||
if customImgUrl != "" {
|
||||
key := ossObjectKey
|
||||
err := util.RefreshOssPresignedUrlCache(ctx, []string{key}, 24*time.Hour)
|
||||
if err != nil {
|
||||
g.Log().Error(ctx, "刷新新英雄图片预签名URL失败:", key, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
|
||||
Reference in New Issue
Block a user