fix: 将自动生成标签后的内容更新到请求中
This commit is contained in:
parent
8ba457d1b8
commit
3318bd45fc
@ -123,9 +123,12 @@ func UpdateWorkImageCore(ctx *gin.Context, req *cast.UpdateWorkImageReq) (*cast.
|
|||||||
// return nil, err
|
// return nil, err
|
||||||
//}
|
//}
|
||||||
// 处理内容中的标签:提取、验证并批量导入,以及自动生成标签
|
// 处理内容中的标签:提取、验证并批量导入,以及自动生成标签
|
||||||
if err = processContentAndAutoTags(ctx, req.Content); err != nil {
|
content, err := processContentAndAutoTags(ctx, req.Content)
|
||||||
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
// 将自动生成标签后的内容更新到请求中
|
||||||
|
req.Content = content
|
||||||
newCtx := NewCtxWithUserInfo(ctx)
|
newCtx := NewCtxWithUserInfo(ctx)
|
||||||
req.Source = 1
|
req.Source = 1
|
||||||
resp, err := service.CastProvider.UpdateWorkImage(newCtx, req)
|
resp, err := service.CastProvider.UpdateWorkImage(newCtx, req)
|
||||||
@ -220,17 +223,17 @@ func processContentTags(ctx *gin.Context, content string) error {
|
|||||||
|
|
||||||
// processContentAndAutoTags 处理内容标签并自动生成标签
|
// processContentAndAutoTags 处理内容标签并自动生成标签
|
||||||
// 该函数统一处理内容中的标签提取、验证和自动生成标签的逻辑
|
// 该函数统一处理内容中的标签提取、验证和自动生成标签的逻辑
|
||||||
func processContentAndAutoTags(ctx *gin.Context, content string) error {
|
func processContentAndAutoTags(ctx *gin.Context, content string) (string, error) {
|
||||||
// 如果内容为空,直接返回
|
// 如果内容为空,直接返回
|
||||||
if content == "" {
|
if content == "" {
|
||||||
return nil
|
return "", nil
|
||||||
}
|
}
|
||||||
// 处理内容中的标签:提取、验证并批量导入
|
// 处理内容中的标签:提取、验证并批量导入
|
||||||
if err := processContentTags(ctx, content); err != nil {
|
if err := processContentTags(ctx, content); err != nil {
|
||||||
return err
|
return content, err
|
||||||
}
|
}
|
||||||
// 处理完内容标签后,自动生成标签并存入数据库
|
// 处理完内容标签后,自动生成标签并存入数据库
|
||||||
_, newTags, needMore, err := GenerateAutoHashtags(
|
resp, newTags, needMore, err := GenerateAutoHashtags(
|
||||||
context.Background(),
|
context.Background(),
|
||||||
content,
|
content,
|
||||||
0, // max 为0时自动计算
|
0, // max 为0时自动计算
|
||||||
@ -238,14 +241,14 @@ func processContentAndAutoTags(ctx *gin.Context, content string) error {
|
|||||||
"", // language 使用默认值
|
"", // language 使用默认值
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return content, err
|
||||||
} else if needMore && len(newTags) > 0 {
|
} else if needMore && len(newTags) > 0 {
|
||||||
if saveErr := SaveTagsToDatabase(ctx, newTags, 4); saveErr != nil {
|
if saveErr := SaveTagsToDatabase(ctx, newTags, 4); saveErr != nil {
|
||||||
zap.L().Error("processContentAndAutoTags SaveTagsToDatabase failed", zap.Error(saveErr))
|
zap.L().Error("processContentAndAutoTags SaveTagsToDatabase failed", zap.Error(saveErr))
|
||||||
return errors.New("自动生成标签保存到数据库失败")
|
return content, errors.New("自动生成标签保存到数据库失败")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil
|
return resp.Post, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// UpdateWorkVideoCore 更新作品视频的核心逻辑,可以被其他函数复用
|
// UpdateWorkVideoCore 更新作品视频的核心逻辑,可以被其他函数复用
|
||||||
@ -328,9 +331,12 @@ func UpdateWorkVideoCore(ctx *gin.Context, req *cast.UpdateWorkVideoReq) (*cast.
|
|||||||
req.ArtistPhoneAreaCode = infoResp.TelAreaCode
|
req.ArtistPhoneAreaCode = infoResp.TelAreaCode
|
||||||
req.ArtistSubNum = infoResp.SubNum
|
req.ArtistSubNum = infoResp.SubNum
|
||||||
// 处理内容中的标签:提取、验证并批量导入,以及自动生成标签
|
// 处理内容中的标签:提取、验证并批量导入,以及自动生成标签
|
||||||
if err = processContentAndAutoTags(ctx, req.Content); err != nil {
|
content, err := processContentAndAutoTags(ctx, req.Content)
|
||||||
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
// 将自动生成标签后的内容更新到请求中
|
||||||
|
req.Content = content
|
||||||
newCtx := NewCtxWithUserInfo(ctx)
|
newCtx := NewCtxWithUserInfo(ctx)
|
||||||
req.Source = 1
|
req.Source = 1
|
||||||
resp, err := service.CastProvider.UpdateWorkVideo(newCtx, req)
|
resp, err := service.CastProvider.UpdateWorkVideo(newCtx, req)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user