2023-12-21 22:17:40 +08:00
|
|
|
package imageaudit
|
|
|
|
|
|
|
|
import (
|
|
|
|
"service/bizcommon/util"
|
|
|
|
"service/dbstruct"
|
|
|
|
"service/library/configcenter"
|
|
|
|
"service/library/contentaudit/textaudit"
|
|
|
|
"service/library/logger"
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
imageauditproto "service/api/proto/imageaudit/proto"
|
|
|
|
imageaudittaskproto "service/api/proto/imageaudittask/proto"
|
|
|
|
|
|
|
|
openapi "github.com/alibabacloud-go/darabonba-openapi/v2/client"
|
|
|
|
imageaudit "github.com/alibabacloud-go/imageaudit-20191230/v3/client"
|
|
|
|
"github.com/alibabacloud-go/tea/tea"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
|
|
)
|
|
|
|
|
|
|
|
// 数据库接口
|
|
|
|
type ImageAuditService interface {
|
|
|
|
OpCreate(ctx *gin.Context, req *imageauditproto.OpCreateReq) error
|
|
|
|
OpUpdate(ctx *gin.Context, req *imageauditproto.OpUpdateReq) error
|
|
|
|
OpDelete(ctx *gin.Context, id string) error
|
|
|
|
OpList(ctx *gin.Context, req *imageauditproto.OpListReq) (*dbstruct.ImageAudit, error)
|
|
|
|
OpCreateFragmentGroup(ctx *gin.Context, req *imageauditproto.OpCreateBatchReq) error
|
|
|
|
OpUpdateByIds(ctx *gin.Context, req *imageauditproto.OpUpdateByIdsReq) error
|
|
|
|
OpUpdateByBatchId(ctx *gin.Context, batchId string, imageaudit *dbstruct.ImageAudit) error
|
|
|
|
}
|
|
|
|
|
|
|
|
type ImageAuditTaskService interface {
|
|
|
|
OpCreate(ctx *gin.Context, req *imageaudittaskproto.OpCreateReq) error
|
|
|
|
OpUpdate(ctx *gin.Context, req *imageaudittaskproto.OpUpdateReq) error
|
|
|
|
OpDelete(ctx *gin.Context, id string) error
|
|
|
|
OpList(ctx *gin.Context, req *imageaudittaskproto.OpListReq) ([]*dbstruct.ImageAuditTask, error)
|
|
|
|
OpUpdateByIds(ctx *gin.Context, req *imageaudittaskproto.OpUpdateByIdsReq) error
|
|
|
|
OpUpdateByBatchId(ctx *gin.Context, batchId string, imageaudittask *dbstruct.ImageAuditTask) error
|
2024-01-04 21:55:00 +08:00
|
|
|
OpHandleOverdue(ctx *gin.Context, task *dbstruct.ImageAuditTask, batchId string) error
|
2023-12-21 22:17:40 +08:00
|
|
|
}
|
|
|
|
|
2024-05-22 17:14:20 +08:00
|
|
|
type ContentAuditRTIService interface {
|
|
|
|
GetAndUpdateImageAuditBatchId(ctx *gin.Context, batchId string) (string, error)
|
|
|
|
}
|
|
|
|
|
2024-01-20 06:33:10 +08:00
|
|
|
type ImageAuditTaskResultHandler interface {
|
|
|
|
Handle(ctx *gin.Context, task *dbstruct.ImageAuditTask, option int) error
|
|
|
|
}
|
|
|
|
|
2023-12-21 22:17:40 +08:00
|
|
|
var defaultImageAuditClient *imageaudit.Client
|
|
|
|
var _DefaultImageAudit ImageAuditService
|
|
|
|
var _DefaultImageAuditTask ImageAuditTaskService
|
2024-01-20 06:33:10 +08:00
|
|
|
var _DefaultResultHandler ImageAuditTaskResultHandler
|
2024-05-22 17:14:20 +08:00
|
|
|
var _DefaultContentAuditRTI ContentAuditRTIService
|
2023-12-21 22:17:40 +08:00
|
|
|
var scenes []*string
|
|
|
|
|
|
|
|
func Init(cfg *configcenter.ImageAuditConfig) (err error) {
|
|
|
|
config := &openapi.Config{
|
|
|
|
AccessKeyId: tea.String(cfg.AccessKeyId),
|
|
|
|
AccessKeySecret: tea.String(cfg.AccessKeySecret),
|
|
|
|
}
|
|
|
|
|
|
|
|
config.Endpoint = tea.String("imageaudit.cn-shanghai.aliyuncs.com")
|
|
|
|
defaultImageAuditClient, err = imageaudit.NewClient(config)
|
|
|
|
if err != nil {
|
|
|
|
logger.Error("NewImageAuditClient fail, cfg: %v, err: %v", util.ToJson(config), err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// 让文字审核连接到这个服务
|
|
|
|
textaudit.ConnectToTextAuditClient(defaultImageAuditClient)
|
|
|
|
|
|
|
|
// 初始化审核选项
|
|
|
|
scenelist := strings.Split(cfg.Scenes, " ")
|
|
|
|
scenes = make([]*string, len(scenelist))
|
|
|
|
for i, scene := range scenelist {
|
|
|
|
scenes[i] = tea.String(scene)
|
|
|
|
}
|
|
|
|
|
2024-05-22 17:14:20 +08:00
|
|
|
// batch_id
|
|
|
|
_, err = RefreshBatchId()
|
|
|
|
if err != nil {
|
|
|
|
logger.Error("RefreshBatchId fail, cfg: %v, err: %v", util.ToJson(config), err)
|
|
|
|
return
|
|
|
|
}
|
2023-12-21 22:17:40 +08:00
|
|
|
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
func ConnectToImageAuditService(serivce ImageAuditService) {
|
|
|
|
_DefaultImageAudit = serivce
|
|
|
|
}
|
|
|
|
|
2024-01-20 06:33:10 +08:00
|
|
|
func ConnectToImageAuditTaskService(service ImageAuditTaskService, handler ImageAuditTaskResultHandler) {
|
2023-12-21 22:17:40 +08:00
|
|
|
_DefaultImageAuditTask = service
|
2024-01-20 06:33:10 +08:00
|
|
|
_DefaultResultHandler = handler
|
2023-12-21 22:17:40 +08:00
|
|
|
}
|
2024-05-22 17:14:20 +08:00
|
|
|
|
|
|
|
func ConnectToContentAuditRTIService(service ContentAuditRTIService) {
|
|
|
|
_DefaultContentAuditRTI = service
|
|
|
|
}
|