@ -977,8 +977,7 @@ func PostAS(ctx context.Context, workUuid string, publishSource cast.PublishSour
func RePublish ( ctx * gin . Context ) {
var (
req * cast . RePublishReq
resp * cast . RePublishResp
req * cast . RePublishReq
//workInfoResp *cast.WorkInfoResp
)
var err error
@ -990,57 +989,37 @@ func RePublish(ctx *gin.Context) {
req . PublishSource = cast . PublishSourceENUM_RePublishType_MANUAL
}
newCtx := NewCtxWithUserInfo ( ctx )
/ * workInfoResp , err = service . CastProvider . WorkInfo ( context . Background ( ) , & cast . WorkInfoReq {
WorkUuid : req . WorkUuid ,
} )
if err != nil {
service . Error ( ctx , err )
return
}
fmt . Println ( workInfoResp ) * /
/ * artistID , _ := strconv . ParseInt ( workInfoResp . ArtistUuid , 10 , 64 )
if err = CheckUserBundleBalance ( int32 ( artistID ) , modelCast . BalanceTypeVideoValue ) ; err != nil {
service . Error ( ctx , err )
return
}
balanceReq := & bundle . AddBundleBalanceReq {
UserId : int32 ( artistID ) ,
}
if workInfoResp . WorkCategory == 1 {
balanceReq . ImageConsumptionNumber = 1
}
if workInfoResp . WorkCategory == 2 {
balanceReq . VideoConsumptionNumber = 1
}
_ , err = service . BundleProvider . AddBundleBalance ( context . Background ( ) , balanceReq )
err = republishCore ( ctx , newCtx , req )
if err != nil {
service . Error ( ctx , err )
return
} * /
}
service . Success ( ctx , req )
return
}
func republishCore ( gCtx * gin . Context , newCtx context . Context , req * cast . RePublishReq ) error {
var resp * cast . RePublishResp
var err error
if len ( req . PlatformIDs ) == 0 && len ( req . MediaAccountUuids ) == 0 {
service . Error ( ctx , errors . New ( "请选择发布平台或账号" ) )
return
return errors . New ( "请选择发布平台或账号" )
}
if len ( req . MediaAccountUuids ) == 0 {
if len ( req . WorkUuids ) != 1 {
service . Error ( ctx , errors . New ( "只选择平台时只能单个作品重发" ) )
return
return errors . New ( "只选择平台时只能单个作品重发" )
}
workInfo , _err := service . CastProvider . WorkInfo ( context . Background ( ) , & cast . WorkInfoReq { WorkUuid : req . WorkUuids [ 0 ] } )
if _err != nil {
service . Error ( ctx , _err )
return
return _err
}
accountResp , _err := service . CastProvider . MediaAccounts ( context . Background ( ) , & cast . MediaAccountsReq {
ArtistUuid : workInfo . ArtistUuid ,
} )
if _err != nil {
service . Error ( ctx , _err )
return
return _err
}
if accountResp == nil || len ( accountResp . Data ) == 0 {
service . Error ( ctx , errors . New ( "该艺人无可用媒体账号" ) )
return
return errors . New ( "该艺人无可用媒体账号" )
}
for _ , platformId := range req . PlatformIDs {
for _ , v := range accountResp . Data {
@ -1052,10 +1031,12 @@ func RePublish(ctx *gin.Context) {
}
resp , err = service . CastProvider . RePublish ( newCtx , req )
if err != nil {
service . Error ( ctx , err )
return
return err
}
var loginInfo login . Info
if gCtx != nil {
loginInfo = login . GetUserInfoFromC ( gCtx )
}
loginInfo := login . GetUserInfoFromC ( ctx )
var extraBytes [ ] byte
extraBytes , _ = json . Marshal ( req )
_ , err = service . CastProvider . UpsertTaskList ( newCtx , & cast . UpsertTaskListReq {
@ -1068,14 +1049,57 @@ func RePublish(ctx *gin.Context) {
} )
if err != nil {
zap . L ( ) . Error ( "RePublish UpsertTaskList failed" , zap . Error ( err ) )
service . Error ( ctx , err )
return
return err
}
if err = PublishWork ( newCtx , & cast . PublishReq { WorkUuids : resp . WorkUuids } ) ; err != nil {
return err
}
return nil
}
// CronRePublish 定时重发布接口( 不走登录校验, 通过header校验)
func CronRePublish ( ctx * gin . Context ) {
// 从 header 中获取 API Key
apiNoAuthKey := ctx . GetHeader ( "X-Api-Key" )
if apiNoAuthKey == "" {
service . Error ( ctx , errors . New ( "非法请求!" ) )
return
}
// 从配置文件中获取预设的 API Key
expectedKey := "c8a2512cea2274a0f3d34520d82d51b3b149e7edc571e5f46854b8c6c0575920"
if apiNoAuthKey != expectedKey {
service . Error ( ctx , errors . New ( "非法请求!!" ) )
return
}
// 校验通过,调用 RePublish 逻辑
var (
req * cast . RePublishReq
)
var err error
if err = ctx . ShouldBind ( & req ) ; err != nil {
service . Error ( ctx , err )
return
}
service . Success ( ctx , req )
// 设置发布源为定时任务
if req . PublishSource == cast . PublishSourceENUM_RePublishType_UNKNOW {
req . PublishSource = cast . PublishSourceENUM_RePublishType_SCHEDULED_RETRY
}
// 创建系统用户上下文(因为没有登录用户信息)
var mm = make ( map [ string ] interface { } , 3 )
mm [ "userid" ] = ""
mm [ "name" ] = "定时任务补发"
mm [ "phone" ] = ""
newCtx := context . WithValue ( context . Background ( ) , constant . DubboCtxKey ( "attachment" ) , mm )
// 调用重发布服务
err = republishCore ( nil , newCtx , req )
if err != nil {
service . Error ( ctx , err )
return
}
service . Success ( ctx , nil )
return
}