调整目录
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
package dataengine
|
||||
package check
|
||||
|
||||
// 送检状态常量
|
||||
const (
|
||||
@@ -1,4 +1,4 @@
|
||||
package dataengine
|
||||
package check
|
||||
|
||||
// PostgreSQL表名常量
|
||||
const (
|
||||
+33
-34
@@ -1,9 +1,8 @@
|
||||
package yidun
|
||||
package check
|
||||
|
||||
import (
|
||||
internal "cid/controller/internal"
|
||||
dto "cid/model/dto/yidun"
|
||||
serviceDataengine "cid/service/dataengine"
|
||||
dto "cid/model/dto/check"
|
||||
check2 "cid/service/check"
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
@@ -18,31 +17,31 @@ var ContentCheck = new(ContentCheckController)
|
||||
|
||||
// StatusRes 状态响应
|
||||
type StatusRes struct {
|
||||
Running bool `json:"running"`
|
||||
Config serviceDataengine.ContentCheckConfig `json:"config"`
|
||||
PendingStats map[string]int `json:"pending_stats"`
|
||||
Running bool `json:"running"`
|
||||
Config check2.ContentCheckConfig `json:"config"`
|
||||
PendingStats map[string]int `json:"pending_stats"`
|
||||
}
|
||||
|
||||
// Start 启动送检服务
|
||||
func (c *ContentCheckController) Start(ctx context.Context, req *dto.StartCheckReq) (res *beans.ResponseEmpty, err error) {
|
||||
ctx = internal.WithAdminUser(ctx)
|
||||
ctx = WithAdminUser(ctx)
|
||||
|
||||
if serviceDataengine.TencentContentCheck.IsRunning() {
|
||||
if check2.TencentContentCheck.IsRunning() {
|
||||
return &beans.ResponseEmpty{}, nil
|
||||
}
|
||||
|
||||
// 如果有配置参数,更新配置
|
||||
if req.BatchSize > 0 || req.IntervalSeconds > 0 {
|
||||
config := serviceDataengine.ContentCheckConfig{
|
||||
config := check2.ContentCheckConfig{
|
||||
BatchSize: req.BatchSize,
|
||||
ImageEnabled: req.ImageEnabled,
|
||||
VideoEnabled: req.VideoEnabled,
|
||||
IntervalSeconds: req.IntervalSeconds,
|
||||
}
|
||||
serviceDataengine.TencentContentCheck.SetConfig(config)
|
||||
check2.TencentContentCheck.SetConfig(config)
|
||||
}
|
||||
|
||||
err = serviceDataengine.TencentContentCheck.Start(ctx)
|
||||
err = check2.TencentContentCheck.Start(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -51,76 +50,76 @@ func (c *ContentCheckController) Start(ctx context.Context, req *dto.StartCheckR
|
||||
|
||||
// Stop 停止送检服务
|
||||
func (c *ContentCheckController) Stop(ctx context.Context, req *dto.EmptyReq) (res *beans.ResponseEmpty, err error) {
|
||||
ctx = internal.WithAdminUser(ctx)
|
||||
serviceDataengine.TencentContentCheck.Stop(ctx)
|
||||
ctx = WithAdminUser(ctx)
|
||||
check2.TencentContentCheck.Stop(ctx)
|
||||
return
|
||||
}
|
||||
|
||||
// Status 获取送检服务状态
|
||||
func (c *ContentCheckController) Status(ctx context.Context, req *dto.EmptyReq) (res *StatusRes, err error) {
|
||||
ctx = internal.WithAdminUser(ctx)
|
||||
ctx = WithAdminUser(ctx)
|
||||
|
||||
res = &StatusRes{
|
||||
Running: serviceDataengine.TencentContentCheck.IsRunning(),
|
||||
Config: serviceDataengine.TencentContentCheck.GetConfig(),
|
||||
PendingStats: serviceDataengine.TencentContentCheck.GetPendingStats(ctx),
|
||||
Running: check2.TencentContentCheck.IsRunning(),
|
||||
Config: check2.TencentContentCheck.GetConfig(),
|
||||
PendingStats: check2.TencentContentCheck.GetPendingStats(ctx),
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// ProcessImageCallback 处理图片检测回调
|
||||
func (c *ContentCheckController) ProcessImageCallback(ctx context.Context, req *dto.ProcessImageCallbackReq) (res *beans.ResponseEmpty, err error) {
|
||||
ctx = internal.WithAdminUser(ctx)
|
||||
ctx = WithAdminUser(ctx)
|
||||
|
||||
if req.CallbackData == "" {
|
||||
return nil, fmt.Errorf("callbackData不能为空")
|
||||
}
|
||||
|
||||
err = serviceDataengine.TencentContentCallback.ProcessImageCallback(ctx, req.CallbackData)
|
||||
err = check2.TencentContentCallback.ProcessImageCallback(ctx, req.CallbackData)
|
||||
return
|
||||
}
|
||||
|
||||
// ProcessVideoCallback 处理视频检测回调
|
||||
func (c *ContentCheckController) ProcessVideoCallback(ctx context.Context, req *dto.ProcessVideoCallbackReq) (res *beans.ResponseEmpty, err error) {
|
||||
ctx = internal.WithAdminUser(ctx)
|
||||
ctx = WithAdminUser(ctx)
|
||||
|
||||
if req.CallbackData == "" {
|
||||
return nil, fmt.Errorf("callbackData不能为空")
|
||||
}
|
||||
|
||||
err = serviceDataengine.TencentContentCallback.ProcessVideoCallback(ctx, req.CallbackData)
|
||||
err = check2.TencentContentCallback.ProcessVideoCallback(ctx, req.CallbackData)
|
||||
return
|
||||
}
|
||||
|
||||
// ProcessImageResult 查询并处理图片检测结果(轮询模式)
|
||||
func (c *ContentCheckController) ProcessImageResult(ctx context.Context, req *dto.ProcessImageResultReq) (res *beans.ResponseEmpty, err error) {
|
||||
ctx = internal.WithAdminUser(ctx)
|
||||
ctx = WithAdminUser(ctx)
|
||||
|
||||
if req.TaskID == "" {
|
||||
return nil, fmt.Errorf("taskId不能为空")
|
||||
}
|
||||
|
||||
err = serviceDataengine.TencentContentCallback.ProcessImageResult(ctx, req.TaskID)
|
||||
err = check2.TencentContentCallback.ProcessImageResult(ctx, req.TaskID)
|
||||
return
|
||||
}
|
||||
|
||||
// ProcessVideoResult 查询并处理视频检测结果(轮询模式)
|
||||
func (c *ContentCheckController) ProcessVideoResult(ctx context.Context, req *dto.ProcessVideoResultReq) (res *beans.ResponseEmpty, err error) {
|
||||
ctx = internal.WithAdminUser(ctx)
|
||||
ctx = WithAdminUser(ctx)
|
||||
|
||||
if req.TaskID == "" {
|
||||
return nil, fmt.Errorf("taskId不能为空")
|
||||
}
|
||||
|
||||
err = serviceDataengine.TencentContentCallback.ProcessVideoResult(ctx, req.TaskID)
|
||||
err = check2.TencentContentCallback.ProcessVideoResult(ctx, req.TaskID)
|
||||
return
|
||||
}
|
||||
|
||||
// ManualSubmitImageByID 根据图片ID手动提交送检
|
||||
func (c *ContentCheckController) ManualSubmitImageByID(ctx context.Context, req *dto.ManualSubmitImageByIDReq) (res *dto.ManualSubmitRes, err error) {
|
||||
ctx = internal.WithAdminUser(ctx)
|
||||
ctx = WithAdminUser(ctx)
|
||||
|
||||
result, err := serviceDataengine.TencentContentCheck.SubmitImageByID(ctx, req.ImageID)
|
||||
result, err := check2.TencentContentCheck.SubmitImageByID(ctx, req.ImageID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -133,9 +132,9 @@ func (c *ContentCheckController) ManualSubmitImageByID(ctx context.Context, req
|
||||
|
||||
// ManualSubmitVideoByID 根据视频ID手动提交送检
|
||||
func (c *ContentCheckController) ManualSubmitVideoByID(ctx context.Context, req *dto.ManualSubmitVideoByIDReq) (res *dto.ManualSubmitRes, err error) {
|
||||
ctx = internal.WithAdminUser(ctx)
|
||||
ctx = WithAdminUser(ctx)
|
||||
|
||||
result, err := serviceDataengine.TencentContentCheck.SubmitVideoByID(ctx, req.VideoID)
|
||||
result, err := check2.TencentContentCheck.SubmitVideoByID(ctx, req.VideoID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -148,9 +147,9 @@ func (c *ContentCheckController) ManualSubmitVideoByID(ctx context.Context, req
|
||||
|
||||
// GetImageCheckLogs 获取图片的送检日志
|
||||
func (c *ContentCheckController) GetImageCheckLogs(ctx context.Context, req *dto.GetImageCheckLogsReq) (res *dto.GetCheckLogsRes, err error) {
|
||||
ctx = internal.WithAdminUser(ctx)
|
||||
ctx = WithAdminUser(ctx)
|
||||
|
||||
logs, err := serviceDataengine.TencentContentCallback.GetCheckLogsByImageID(ctx, req.ImageID)
|
||||
logs, err := check2.TencentContentCallback.GetCheckLogsByImageID(ctx, req.ImageID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -163,9 +162,9 @@ func (c *ContentCheckController) GetImageCheckLogs(ctx context.Context, req *dto
|
||||
|
||||
// GetVideoCheckLogs 获取视频的送检日志
|
||||
func (c *ContentCheckController) GetVideoCheckLogs(ctx context.Context, req *dto.GetVideoCheckLogsReq) (res *dto.GetCheckLogsRes, err error) {
|
||||
ctx = internal.WithAdminUser(ctx)
|
||||
ctx = WithAdminUser(ctx)
|
||||
|
||||
logs, err := serviceDataengine.TencentContentCallback.GetCheckLogsByVideoID(ctx, req.VideoID)
|
||||
logs, err := check2.TencentContentCallback.GetCheckLogsByVideoID(ctx, req.VideoID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
+24
-25
@@ -1,11 +1,10 @@
|
||||
package dataengine
|
||||
package check
|
||||
|
||||
import (
|
||||
consts "cid/consts/dataengine"
|
||||
internal "cid/controller/internal"
|
||||
dao "cid/dao/dataengine"
|
||||
entity "cid/model/entity/dataengine"
|
||||
serviceDataengine "cid/service/dataengine"
|
||||
consts "cid/consts/check"
|
||||
dao "cid/dao/check"
|
||||
entity "cid/model/entity/check"
|
||||
serviceDataengine "cid/service/check"
|
||||
"context"
|
||||
"fmt"
|
||||
"time"
|
||||
@@ -105,7 +104,7 @@ type BatchVerifyReq struct {
|
||||
|
||||
// ListImage 图片素材列表
|
||||
func (c *MaterialVerifyController) ListImage(ctx context.Context, req *ImageListReq) (res *ImageListRes, err error) {
|
||||
ctx = internal.WithAdminUser(ctx)
|
||||
ctx = WithAdminUser(ctx)
|
||||
|
||||
if req.Page == 0 {
|
||||
req.Page = 1
|
||||
@@ -135,7 +134,7 @@ func (c *MaterialVerifyController) ListImage(ctx context.Context, req *ImageList
|
||||
|
||||
// StatsImage 图片素材统计
|
||||
func (c *MaterialVerifyController) StatsImage(ctx context.Context, req *ImageListReq) (res *StatsRes, err error) {
|
||||
ctx = internal.WithAdminUser(ctx)
|
||||
ctx = WithAdminUser(ctx)
|
||||
// 使用实体中定义的正确状态值:PENDING=待校验, VERIFIED=校验通过, REJECTED=校验不通过
|
||||
pending, err := dao.TencentImage.CountByStatus(ctx, entity.VerifyStatusPending)
|
||||
if err != nil {
|
||||
@@ -163,7 +162,7 @@ func (c *MaterialVerifyController) StatsImage(ctx context.Context, req *ImageLis
|
||||
|
||||
// ListVideo 视频素材列表
|
||||
func (c *MaterialVerifyController) ListVideo(ctx context.Context, req *VideoListReq) (res *VideoListRes, err error) {
|
||||
ctx = internal.WithAdminUser(ctx)
|
||||
ctx = WithAdminUser(ctx)
|
||||
|
||||
if req.Page == 0 {
|
||||
req.Page = 1
|
||||
@@ -193,7 +192,7 @@ func (c *MaterialVerifyController) ListVideo(ctx context.Context, req *VideoList
|
||||
|
||||
// StatsVideo 视频素材统计
|
||||
func (c *MaterialVerifyController) StatsVideo(ctx context.Context, req *VideoListReq) (res *StatsRes, err error) {
|
||||
ctx = internal.WithAdminUser(ctx)
|
||||
ctx = WithAdminUser(ctx)
|
||||
// 使用实体中定义的正确状态值:PENDING=待校验, VERIFIED=校验通过, REJECTED=校验不通过
|
||||
pending, err := dao.TencentVideo.CountByStatus(ctx, entity.VerifyStatusPending)
|
||||
if err != nil {
|
||||
@@ -227,7 +226,7 @@ type ListLogRes struct {
|
||||
|
||||
// ListLog 日志列表
|
||||
func (c *MaterialVerifyController) ListLog(ctx context.Context, req *LogListReq) (res *ListLogRes, err error) {
|
||||
ctx = internal.WithAdminUser(ctx)
|
||||
ctx = WithAdminUser(ctx)
|
||||
|
||||
if req.Page == 0 {
|
||||
req.Page = 1
|
||||
@@ -274,7 +273,7 @@ type GetLogDetailReq struct {
|
||||
|
||||
// GetLogDetail 日志详情
|
||||
func (c *MaterialVerifyController) GetLogDetail(ctx context.Context, req *GetLogDetailReq) (res *LogDetailRes, err error) {
|
||||
ctx = internal.WithAdminUser(ctx)
|
||||
ctx = WithAdminUser(ctx)
|
||||
|
||||
log, err := serviceDataengine.MaterialVerify.GetLogByID(ctx, req.Id)
|
||||
if err != nil {
|
||||
@@ -313,7 +312,7 @@ type StatsLogRes struct {
|
||||
|
||||
// StatsLog 日志统计
|
||||
func (c *MaterialVerifyController) StatsLog(ctx context.Context, req *LogListReq) (res *StatsLogRes, err error) {
|
||||
ctx = internal.WithAdminUser(ctx)
|
||||
ctx = WithAdminUser(ctx)
|
||||
stats, err := serviceDataengine.MaterialVerify.GetStats(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -340,7 +339,7 @@ type ManualVerifyImageRes struct {
|
||||
|
||||
// ManualVerifyImage 手动校验图片
|
||||
func (c *MaterialVerifyController) ManualVerifyImage(ctx context.Context, req *ManualVerifyReq) (res *ManualVerifyImageRes, err error) {
|
||||
ctx = internal.WithAdminUser(ctx)
|
||||
ctx = WithAdminUser(ctx)
|
||||
|
||||
log, err := serviceDataengine.MaterialVerify.VerifyImageByID(ctx, req.MaterialID)
|
||||
if err != nil {
|
||||
@@ -356,7 +355,7 @@ func (c *MaterialVerifyController) ManualVerifyImage(ctx context.Context, req *M
|
||||
|
||||
// ManualVerifyVideo 手动校验视频
|
||||
func (c *MaterialVerifyController) ManualVerifyVideo(ctx context.Context, req *ManualVerifyReq) (res *ManualVerifyImageRes, err error) {
|
||||
ctx = internal.WithAdminUser(ctx)
|
||||
ctx = WithAdminUser(ctx)
|
||||
|
||||
log, err := serviceDataengine.MaterialVerify.VerifyVideoByID(ctx, req.MaterialID)
|
||||
if err != nil {
|
||||
@@ -384,7 +383,7 @@ type BatchVerifyRes struct {
|
||||
|
||||
// BatchVerifyImage 批量校验图片
|
||||
func (c *MaterialVerifyController) BatchVerifyImage(ctx context.Context, req *BatchVerifyReq) (res *BatchVerifyRes, err error) {
|
||||
ctx = internal.WithAdminUser(ctx)
|
||||
ctx = WithAdminUser(ctx)
|
||||
|
||||
if req.Limit <= 0 {
|
||||
req.Limit = 100
|
||||
@@ -419,7 +418,7 @@ func (c *MaterialVerifyController) BatchVerifyImage(ctx context.Context, req *Ba
|
||||
|
||||
// BatchVerifyVideo 批量校验视频
|
||||
func (c *MaterialVerifyController) BatchVerifyVideo(ctx context.Context, req *BatchVerifyReq) (res *BatchVerifyRes, err error) {
|
||||
ctx = internal.WithAdminUser(ctx)
|
||||
ctx = WithAdminUser(ctx)
|
||||
|
||||
if req.Limit <= 0 {
|
||||
req.Limit = 100
|
||||
@@ -472,7 +471,7 @@ type ListAccountsRes struct {
|
||||
|
||||
// ListAccounts 获取所有启用的广告账户列表(用于前端下拉筛选)
|
||||
func (c *MaterialVerifyController) ListAccounts(ctx context.Context, req *ListAccountsReq) (res *ListAccountsRes, err error) {
|
||||
ctx = internal.WithAdminUser(ctx)
|
||||
ctx = WithAdminUser(ctx)
|
||||
accounts, err := dao.TencentAccountRelation.GetAll(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -522,7 +521,7 @@ type ExportRejectedRes struct {
|
||||
|
||||
// ExportRejected 导出不通过的图片/视频数据(含失败原因)
|
||||
func (c *MaterialVerifyController) ExportRejected(ctx context.Context, req *ExportRejectedReq) (res *ExportRejectedRes, err error) {
|
||||
ctx = internal.WithAdminUser(ctx)
|
||||
ctx = WithAdminUser(ctx)
|
||||
|
||||
items, err := serviceDataengine.MaterialVerify.ExportRejectedData(ctx, req.MaterialType)
|
||||
if err != nil {
|
||||
@@ -564,10 +563,10 @@ type CallbackRes struct {
|
||||
|
||||
// ImageCallback 图片校验回调
|
||||
func (c *MaterialVerifyController) ImageCallback(ctx context.Context, req *ImageCallbackReq) (res *CallbackRes, err error) {
|
||||
if !internal.CheckCallbackIP(ctx) {
|
||||
if !CheckCallbackIP(ctx) {
|
||||
return &CallbackRes{Code: 403, Msg: "IP not allowed"}, nil
|
||||
}
|
||||
ctx = internal.WithCallbackUser(ctx)
|
||||
ctx = WithCallbackUser(ctx)
|
||||
if req.CallbackData == "" {
|
||||
return &CallbackRes{Code: 400, Msg: "callbackData不能为空"}, nil
|
||||
}
|
||||
@@ -582,10 +581,10 @@ func (c *MaterialVerifyController) ImageCallback(ctx context.Context, req *Image
|
||||
|
||||
// VideoCallback 视频校验回调
|
||||
func (c *MaterialVerifyController) VideoCallback(ctx context.Context, req *VideoCallbackReq) (res *CallbackRes, err error) {
|
||||
if !internal.CheckCallbackIP(ctx) {
|
||||
if !CheckCallbackIP(ctx) {
|
||||
return &CallbackRes{Code: 403, Msg: "IP not allowed"}, nil
|
||||
}
|
||||
ctx = internal.WithCallbackUser(ctx)
|
||||
ctx = WithCallbackUser(ctx)
|
||||
if req.CallbackData == "" {
|
||||
return &CallbackRes{Code: 400, Msg: "callbackData不能为空"}, nil
|
||||
}
|
||||
@@ -606,7 +605,7 @@ type ResultRes struct {
|
||||
|
||||
// ImageResult 图片校验结果查询(轮询模式)
|
||||
func (c *MaterialVerifyController) ImageResult(ctx context.Context, req *TaskIDReq) (res *ResultRes, err error) {
|
||||
ctx = internal.WithAdminUser(ctx)
|
||||
ctx = WithAdminUser(ctx)
|
||||
if req.TaskID == "" {
|
||||
return &ResultRes{Code: 400, Msg: "taskId不能为空"}, nil
|
||||
}
|
||||
@@ -621,7 +620,7 @@ func (c *MaterialVerifyController) ImageResult(ctx context.Context, req *TaskIDR
|
||||
|
||||
// VideoResult 视频校验结果查询(轮询模式)
|
||||
func (c *MaterialVerifyController) VideoResult(ctx context.Context, req *TaskIDReq) (res *ResultRes, err error) {
|
||||
ctx = internal.WithAdminUser(ctx)
|
||||
ctx = WithAdminUser(ctx)
|
||||
if req.TaskID == "" {
|
||||
return &ResultRes{Code: 400, Msg: "taskId不能为空"}, nil
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
// Package internal 提供 controller 层的共享工具函数
|
||||
package internal
|
||||
package check
|
||||
|
||||
import (
|
||||
"context"
|
||||
@@ -21,13 +21,13 @@ func WithCallbackUser(ctx context.Context) context.Context {
|
||||
}
|
||||
|
||||
// CheckCallbackIP 校验回调请求 IP 是否在白名单内
|
||||
// 读取配置 yidun.callback_allowed_ips,若未配置则跳过校验
|
||||
// 读取配置 check.callback_allowed_ips,若未配置则跳过校验
|
||||
func CheckCallbackIP(ctx context.Context) bool {
|
||||
r := ghttp.RequestFromCtx(ctx)
|
||||
if r == nil {
|
||||
return true
|
||||
}
|
||||
allowedIPs := g.Cfg().MustGet(ctx, "yidun.callback_allowed_ips", "").String()
|
||||
allowedIPs := g.Cfg().MustGet(ctx, "check.callback_allowed_ips", "").String()
|
||||
if allowedIPs == "" {
|
||||
return true
|
||||
}
|
||||
+24
-25
@@ -1,8 +1,7 @@
|
||||
package yidun
|
||||
package check
|
||||
|
||||
import (
|
||||
internal "cid/controller/internal"
|
||||
dataengineService "cid/service/dataengine"
|
||||
dataengineService "cid/service/check"
|
||||
"fmt"
|
||||
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
@@ -36,17 +35,17 @@ type PollResult struct {
|
||||
// =============================================================================
|
||||
|
||||
// ReceiveImageCallback 接收易盾图片检测结果推送
|
||||
// 易盾回调格式: POST /yidun/callback/receiveImage
|
||||
// 易盾回调格式: POST /check/callback/receiveImage
|
||||
// Body: callbackData={"antispam":{...}}
|
||||
func (c *YidunCallbackController) ReceiveImageCallback(r *ghttp.Request) {
|
||||
// IP 白名单校验
|
||||
if !internal.CheckCallbackIP(r.Context()) {
|
||||
if !CheckCallbackIP(r.Context()) {
|
||||
r.Response.WriteJson(CallbackResult{Code: 403, Msg: "IP not allowed"})
|
||||
return
|
||||
}
|
||||
|
||||
ctx := r.Context()
|
||||
ctx = internal.WithCallbackUser(ctx)
|
||||
ctx = WithCallbackUser(ctx)
|
||||
|
||||
// 易盾推送的数据在请求体中
|
||||
var callbackData string
|
||||
@@ -88,17 +87,17 @@ func (c *YidunCallbackController) ReceiveImageCallback(r *ghttp.Request) {
|
||||
}
|
||||
|
||||
// ReceiveVideoCallback 接收易盾视频检测结果推送
|
||||
// 易盾回调格式: POST /yidun/callback/receiveVideo
|
||||
// 易盾回调格式: POST /check/callback/receiveVideo
|
||||
// Body: callbackData={"antispam":{...}}
|
||||
func (c *YidunCallbackController) ReceiveVideoCallback(r *ghttp.Request) {
|
||||
// IP 白名单校验
|
||||
if !internal.CheckCallbackIP(r.Context()) {
|
||||
if !CheckCallbackIP(r.Context()) {
|
||||
r.Response.WriteJson(CallbackResult{Code: 403, Msg: "IP not allowed"})
|
||||
return
|
||||
}
|
||||
|
||||
ctx := r.Context()
|
||||
ctx = internal.WithCallbackUser(ctx)
|
||||
ctx = WithCallbackUser(ctx)
|
||||
|
||||
// 易盾推送的数据在请求体中
|
||||
var callbackData string
|
||||
@@ -144,10 +143,10 @@ func (c *YidunCallbackController) ReceiveVideoCallback(r *ghttp.Request) {
|
||||
// =============================================================================
|
||||
|
||||
// PollAllResults 轮询所有待查询的检测结果(图片+视频)
|
||||
// 格式: POST /yidun/callback/poll
|
||||
// 格式: POST /check/callback/poll
|
||||
func (c *YidunCallbackController) PollAllResults(r *ghttp.Request) {
|
||||
ctx := r.Context()
|
||||
ctx = internal.WithAdminUser(ctx)
|
||||
ctx = WithAdminUser(ctx)
|
||||
|
||||
g.Log().Info(ctx, "开始轮询所有待查询的检测结果...")
|
||||
|
||||
@@ -185,10 +184,10 @@ func (c *YidunCallbackController) PollAllResults(r *ghttp.Request) {
|
||||
}
|
||||
|
||||
// PollImageResults 轮询图片待查询的检测结果
|
||||
// 格式: POST /yidun/callback/pollImage
|
||||
// 格式: POST /check/callback/pollImage
|
||||
func (c *YidunCallbackController) PollImageResults(r *ghttp.Request) {
|
||||
ctx := r.Context()
|
||||
ctx = internal.WithAdminUser(ctx)
|
||||
ctx = WithAdminUser(ctx)
|
||||
|
||||
g.Log().Info(ctx, "开始轮询图片待查询的检测结果...")
|
||||
|
||||
@@ -211,10 +210,10 @@ func (c *YidunCallbackController) PollImageResults(r *ghttp.Request) {
|
||||
}
|
||||
|
||||
// PollVideoResults 轮询视频待查询的检测结果
|
||||
// 格式: POST /yidun/callback/pollVideo
|
||||
// 格式: POST /check/callback/pollVideo
|
||||
func (c *YidunCallbackController) PollVideoResults(r *ghttp.Request) {
|
||||
ctx := r.Context()
|
||||
ctx = internal.WithAdminUser(ctx)
|
||||
ctx = WithAdminUser(ctx)
|
||||
|
||||
g.Log().Info(ctx, "开始轮询视频待查询的检测结果...")
|
||||
|
||||
@@ -237,10 +236,10 @@ func (c *YidunCallbackController) PollVideoResults(r *ghttp.Request) {
|
||||
}
|
||||
|
||||
// PollByTaskID 根据任务ID查询单个检测结果
|
||||
// 格式: POST /yidun/callback/pollTask
|
||||
// 格式: POST /check/callback/pollTask
|
||||
func (c *YidunCallbackController) PollByTaskID(r *ghttp.Request) {
|
||||
ctx := r.Context()
|
||||
ctx = internal.WithAdminUser(ctx)
|
||||
ctx = WithAdminUser(ctx)
|
||||
|
||||
taskID := r.Get("taskId", "").String()
|
||||
taskType := r.Get("type", "").String() // image 或 video
|
||||
@@ -281,10 +280,10 @@ type PendingListRes struct {
|
||||
}
|
||||
|
||||
// GetPendingDetail 获取待查询结果的明细
|
||||
// 格式: GET /yidun/callback/pendingDetail
|
||||
// 格式: GET /check/callback/pendingDetail
|
||||
func (c *YidunCallbackController) GetPendingDetail(r *ghttp.Request) {
|
||||
ctx := r.Context()
|
||||
ctx = internal.WithAdminUser(ctx)
|
||||
ctx = WithAdminUser(ctx)
|
||||
|
||||
items, err := dataengineService.MaterialVerify.GetPendingResultsDetail(ctx, 50)
|
||||
if err != nil {
|
||||
@@ -302,10 +301,10 @@ func (c *YidunCallbackController) GetPendingDetail(r *ghttp.Request) {
|
||||
}
|
||||
|
||||
// GetPendingCount 获取待查询结果的数量
|
||||
// 格式: GET /yidun/callback/pendingCount
|
||||
// 格式: GET /check/callback/pendingCount
|
||||
func (c *YidunCallbackController) GetPendingCount(r *ghttp.Request) {
|
||||
ctx := r.Context()
|
||||
ctx = internal.WithAdminUser(ctx)
|
||||
ctx = WithAdminUser(ctx)
|
||||
|
||||
count, err := dataengineService.MaterialVerify.GetPendingResultsCount(ctx)
|
||||
if err != nil {
|
||||
@@ -327,10 +326,10 @@ func (c *YidunCallbackController) GetPendingCount(r *ghttp.Request) {
|
||||
// =============================================================================
|
||||
|
||||
// ProcessImageCallback 手动处理图片回调(兼容旧接口)
|
||||
// 格式: POST /yidun/callback/processImage
|
||||
// 格式: POST /check/callback/processImage
|
||||
func (c *YidunCallbackController) ProcessImageCallback(r *ghttp.Request) {
|
||||
ctx := r.Context()
|
||||
ctx = internal.WithAdminUser(ctx)
|
||||
ctx = WithAdminUser(ctx)
|
||||
|
||||
var req struct {
|
||||
CallbackData string `json:"callbackData" v:"required#回调数据不能为空"`
|
||||
@@ -351,10 +350,10 @@ func (c *YidunCallbackController) ProcessImageCallback(r *ghttp.Request) {
|
||||
}
|
||||
|
||||
// ProcessVideoCallback 手动处理视频回调(兼容旧接口)
|
||||
// 格式: POST /yidun/callback/processVideo
|
||||
// 格式: POST /check/callback/processVideo
|
||||
func (c *YidunCallbackController) ProcessVideoCallback(r *ghttp.Request) {
|
||||
ctx := r.Context()
|
||||
ctx = internal.WithAdminUser(ctx)
|
||||
ctx = WithAdminUser(ctx)
|
||||
|
||||
var req struct {
|
||||
CallbackData string `json:"callbackData" v:"required#回调数据不能为空"`
|
||||
@@ -1,9 +1,7 @@
|
||||
package yidun
|
||||
package check
|
||||
|
||||
import (
|
||||
internal "cid/controller/internal"
|
||||
serviceDataengine "cid/service/dataengine"
|
||||
"cid/service/yidun"
|
||||
"cid/service/check"
|
||||
"context"
|
||||
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
@@ -40,9 +38,9 @@ type DetectVideoReq struct {
|
||||
|
||||
// DetectText 文本检测
|
||||
func (c *yidunController) DetectText(ctx context.Context, req *DetectTextReq) (string, error) {
|
||||
ctx = internal.WithAdminUser(ctx)
|
||||
ctx = WithAdminUser(ctx)
|
||||
|
||||
businessId := g.Cfg().MustGet(ctx, "yidun.text.business_id").String()
|
||||
businessId := g.Cfg().MustGet(ctx, "check.text.business_id").String()
|
||||
sdkReq := single.NewTextAsyncCheckRequest(businessId)
|
||||
sdkReq.SetDataID(req.DataID)
|
||||
sdkReq.SetContent(req.Content)
|
||||
@@ -53,19 +51,19 @@ func (c *yidunController) DetectText(ctx context.Context, req *DetectTextReq) (s
|
||||
sdkReq.SetToken(req.Token)
|
||||
}
|
||||
|
||||
return yidun.TextDetection.DetectText(ctx, sdkReq)
|
||||
return check.TextDetection.DetectText(ctx, sdkReq)
|
||||
}
|
||||
|
||||
// DetectImage 图片检测
|
||||
func (c *yidunController) DetectImage(ctx context.Context, req *DetectImageReq) (*yidun.ImageSubmitResult, error) {
|
||||
ctx = internal.WithAdminUser(ctx)
|
||||
return yidun.ImageDetection.DetectImage(ctx, req.ImageURL, req.DataID, req.CallbackURL)
|
||||
func (c *yidunController) DetectImage(ctx context.Context, req *DetectImageReq) (*check.ImageSubmitResult, error) {
|
||||
ctx = WithAdminUser(ctx)
|
||||
return check.ImageDetection.DetectImage(ctx, req.ImageURL, req.DataID, req.CallbackURL)
|
||||
}
|
||||
|
||||
// DetectVideo 视频检测
|
||||
func (c *yidunController) DetectVideo(ctx context.Context, req *DetectVideoReq) (*yidun.VideoSubmitResult, error) {
|
||||
ctx = internal.WithAdminUser(ctx)
|
||||
return yidun.VideoDetection.DetectVideo(ctx, req.VideoURL, req.DataID, req.CallbackURL)
|
||||
func (c *yidunController) DetectVideo(ctx context.Context, req *DetectVideoReq) (*check.VideoSubmitResult, error) {
|
||||
ctx = WithAdminUser(ctx)
|
||||
return check.VideoDetection.DetectVideo(ctx, req.VideoURL, req.DataID, req.CallbackURL)
|
||||
}
|
||||
|
||||
// ImageCallbackResult 图片检测回调响应
|
||||
@@ -77,13 +75,13 @@ type ImageCallbackResult struct {
|
||||
// ReceiveImageCallback 接收图片检测结果推送
|
||||
func (c *yidunController) ReceiveImageCallback(r *ghttp.Request) {
|
||||
// IP 白名单校验
|
||||
if !internal.CheckCallbackIP(r.Context()) {
|
||||
if !CheckCallbackIP(r.Context()) {
|
||||
r.Response.WriteJson(ImageCallbackResult{Code: 403, Msg: "IP not allowed"})
|
||||
return
|
||||
}
|
||||
|
||||
ctx := r.Context()
|
||||
ctx = internal.WithAdminUser(ctx)
|
||||
ctx = WithAdminUser(ctx)
|
||||
|
||||
callbackData := r.GetForm("callbackData", "").String()
|
||||
if callbackData == "" {
|
||||
@@ -91,7 +89,7 @@ func (c *yidunController) ReceiveImageCallback(r *ghttp.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
err := serviceDataengine.MaterialVerify.ProcessImageCallback(ctx, callbackData)
|
||||
err := check.MaterialVerify.ProcessImageCallback(ctx, callbackData)
|
||||
if err != nil {
|
||||
g.Log().Errorf(ctx, "处理图片检测回调失败: %v", err)
|
||||
r.Response.WriteJson(ImageCallbackResult{Code: 500, Msg: err.Error()})
|
||||
@@ -110,13 +108,13 @@ type VideoCallbackResult struct {
|
||||
// ReceiveVideoCallback 接收视频检测结果推送
|
||||
func (c *yidunController) ReceiveVideoCallback(r *ghttp.Request) {
|
||||
// IP 白名单校验
|
||||
if !internal.CheckCallbackIP(r.Context()) {
|
||||
if !CheckCallbackIP(r.Context()) {
|
||||
r.Response.WriteJson(VideoCallbackResult{Code: 403, Msg: "IP not allowed"})
|
||||
return
|
||||
}
|
||||
|
||||
ctx := r.Context()
|
||||
ctx = internal.WithAdminUser(ctx)
|
||||
ctx = WithAdminUser(ctx)
|
||||
|
||||
callbackData := r.GetForm("callbackData", "").String()
|
||||
if callbackData == "" {
|
||||
@@ -124,7 +122,7 @@ func (c *yidunController) ReceiveVideoCallback(r *ghttp.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
err := serviceDataengine.MaterialVerify.ProcessVideoCallback(ctx, callbackData)
|
||||
err := check.MaterialVerify.ProcessVideoCallback(ctx, callbackData)
|
||||
if err != nil {
|
||||
g.Log().Errorf(ctx, "处理视频检测回调失败: %v", err)
|
||||
r.Response.WriteJson(VideoCallbackResult{Code: 500, Msg: err.Error()})
|
||||
@@ -137,7 +135,7 @@ func (c *yidunController) ReceiveVideoCallback(r *ghttp.Request) {
|
||||
// GetVideoResult 获取视频检测结果
|
||||
func (c *yidunController) GetVideoResult(r *ghttp.Request) {
|
||||
ctx := r.Context()
|
||||
ctx = internal.WithAdminUser(ctx)
|
||||
ctx = WithAdminUser(ctx)
|
||||
|
||||
taskId := r.Get("taskId", "").String()
|
||||
if taskId == "" {
|
||||
@@ -145,7 +143,7 @@ func (c *yidunController) GetVideoResult(r *ghttp.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
result, err := yidun.VideoDetection.GetVideoResult(ctx, taskId)
|
||||
result, err := check.VideoDetection.GetVideoResult(ctx, taskId)
|
||||
if err != nil {
|
||||
g.Log().Errorf(ctx, "查询视频检测结果失败: %v", err)
|
||||
r.Response.WriteJson(g.Map{"code": 500, "msg": err.Error()})
|
||||
@@ -158,7 +156,7 @@ func (c *yidunController) GetVideoResult(r *ghttp.Request) {
|
||||
// GetImageResult 获取图片检测结果
|
||||
func (c *yidunController) GetImageResult(r *ghttp.Request) {
|
||||
ctx := r.Context()
|
||||
ctx = internal.WithAdminUser(ctx)
|
||||
ctx = WithAdminUser(ctx)
|
||||
|
||||
taskId := r.Get("taskId", "").String()
|
||||
if taskId == "" {
|
||||
@@ -166,7 +164,7 @@ func (c *yidunController) GetImageResult(r *ghttp.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
result, err := yidun.ImageDetection.GetImageResult(ctx, taskId)
|
||||
result, err := check.ImageDetection.GetImageResult(ctx, taskId)
|
||||
if err != nil {
|
||||
g.Log().Errorf(ctx, "查询图片检测结果失败: %v", err)
|
||||
r.Response.WriteJson(g.Map{"code": 500, "msg": err.Error()})
|
||||
@@ -1,4 +1,4 @@
|
||||
package dataengine
|
||||
package check
|
||||
|
||||
import (
|
||||
"github.com/gogf/gf/v2/database/gdb"
|
||||
@@ -6,7 +6,7 @@ import (
|
||||
)
|
||||
|
||||
// Model 获取 dataEngine 数据库的 Model(GoFrame ORM)
|
||||
// 配置文件中 dataEngine 对应的实际数据库名是 dataengine
|
||||
// 配置文件中 dataEngine 对应的实际数据库名是 check
|
||||
func Model(tableName string) *gdb.Model {
|
||||
return g.DB("dataEngine").Model(tableName)
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
package dataengine
|
||||
package check
|
||||
|
||||
import (
|
||||
daoEntity "cid/model/entity/dataengine"
|
||||
daoEntity "cid/model/entity/check"
|
||||
"context"
|
||||
|
||||
"github.com/bwmarrin/snowflake"
|
||||
+3
-3
@@ -1,8 +1,8 @@
|
||||
package dataengine
|
||||
package check
|
||||
|
||||
import (
|
||||
consts "cid/consts/dataengine"
|
||||
entity "cid/model/entity/dataengine"
|
||||
consts "cid/consts/check"
|
||||
entity "cid/model/entity/check"
|
||||
"context"
|
||||
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
+3
-33
@@ -1,11 +1,9 @@
|
||||
package dataengine
|
||||
package check
|
||||
|
||||
import (
|
||||
consts "cid/consts/dataengine"
|
||||
entity "cid/model/entity/dataengine"
|
||||
yidunService "cid/service/yidun"
|
||||
consts "cid/consts/check"
|
||||
entity "cid/model/entity/check"
|
||||
"context"
|
||||
"encoding/json"
|
||||
|
||||
"github.com/bwmarrin/snowflake"
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
@@ -173,31 +171,3 @@ func (d *TencentContentCheckLogDAO) UpdateTaskID(ctx context.Context, id int64,
|
||||
Update()
|
||||
return err
|
||||
}
|
||||
|
||||
// GetImageSubmitResult 获取图片提交结果
|
||||
func (d *TencentContentCheckLogDAO) GetImageSubmitResult(ctx context.Context, id int64) (*yidunService.ImageSubmitResult, error) {
|
||||
log, err := d.GetByID(ctx, id)
|
||||
if err != nil || log == nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var result yidunService.ImageSubmitResult
|
||||
if err := json.Unmarshal([]byte(log.ResponseData), &result); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &result, nil
|
||||
}
|
||||
|
||||
// GetVideoSubmitResult 获取视频提交结果
|
||||
func (d *TencentContentCheckLogDAO) GetVideoSubmitResult(ctx context.Context, id int64) (*yidunService.VideoSubmitResult, error) {
|
||||
log, err := d.GetByID(ctx, id)
|
||||
if err != nil || log == nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var result yidunService.VideoSubmitResult
|
||||
if err := json.Unmarshal([]byte(log.ResponseData), &result); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &result, nil
|
||||
}
|
||||
@@ -1,8 +1,8 @@
|
||||
package dataengine
|
||||
package check
|
||||
|
||||
import (
|
||||
consts "cid/consts/dataengine"
|
||||
entity "cid/model/entity/dataengine"
|
||||
consts "cid/consts/check"
|
||||
entity "cid/model/entity/check"
|
||||
"context"
|
||||
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
@@ -1,8 +1,8 @@
|
||||
package dataengine
|
||||
package check
|
||||
|
||||
import (
|
||||
consts "cid/consts/dataengine"
|
||||
entity "cid/model/entity/dataengine"
|
||||
consts "cid/consts/check"
|
||||
entity "cid/model/entity/check"
|
||||
"context"
|
||||
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
@@ -1,10 +1,8 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"cid/controller/dataengine"
|
||||
"cid/controller/yidun"
|
||||
serviceDataengine "cid/service/dataengine"
|
||||
serviceYidun "cid/service/yidun"
|
||||
"cid/controller/check"
|
||||
serviceYidun "cid/service/check"
|
||||
"context"
|
||||
"fmt"
|
||||
"os"
|
||||
@@ -51,10 +49,10 @@ func main() {
|
||||
|
||||
// 注册 API 路由并启动服务器
|
||||
http.RouteRegister([]interface{}{
|
||||
yidun.YidunController,
|
||||
yidun.YidunCallback,
|
||||
yidun.ContentCheck,
|
||||
dataengine.MaterialVerify,
|
||||
check.YidunController,
|
||||
check.YidunCallback,
|
||||
check.ContentCheck,
|
||||
check.MaterialVerify,
|
||||
})
|
||||
|
||||
// 打印前端访问地址
|
||||
@@ -121,17 +119,17 @@ func startContentCheckService(ctx context.Context) {
|
||||
}
|
||||
|
||||
// 配置送检服务参数
|
||||
config := serviceDataengine.ContentCheckConfig{
|
||||
config := serviceYidun.ContentCheckConfig{
|
||||
BatchSize: g.Cfg().MustGet(ctx, "content_check.batch_size", 10).Int(),
|
||||
ImageEnabled: g.Cfg().MustGet(ctx, "content_check.image_enabled", true).Bool(),
|
||||
VideoEnabled: g.Cfg().MustGet(ctx, "content_check.video_enabled", true).Bool(),
|
||||
IntervalSeconds: g.Cfg().MustGet(ctx, "content_check.interval_seconds", 30).Int(),
|
||||
PollInterval: g.Cfg().MustGet(ctx, "content_check.poll_interval", 60).Int(),
|
||||
}
|
||||
serviceDataengine.TencentContentCheck.SetConfig(config)
|
||||
serviceYidun.TencentContentCheck.SetConfig(config)
|
||||
|
||||
// 启动服务
|
||||
if err := serviceDataengine.TencentContentCheck.Start(ctx); err != nil {
|
||||
if err := serviceYidun.TencentContentCheck.Start(ctx); err != nil {
|
||||
g.Log().Errorf(ctx, "启动内容送检服务失败: %v", err)
|
||||
} else {
|
||||
g.Log().Info(ctx, "内容送检服务启动成功")
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package yidun
|
||||
package check
|
||||
|
||||
// ContentCheckConfig 送检配置
|
||||
type ContentCheckConfig struct {
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package dataengine
|
||||
package check
|
||||
|
||||
import (
|
||||
"gitea.redpowerfuture.com/red-future/common/beans"
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package dataengine
|
||||
package check
|
||||
|
||||
import (
|
||||
"gitea.redpowerfuture.com/red-future/common/beans"
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package dataengine
|
||||
package check
|
||||
|
||||
import (
|
||||
"gitea.redpowerfuture.com/red-future/common/beans"
|
||||
@@ -1,4 +1,4 @@
|
||||
package dataengine
|
||||
package check
|
||||
|
||||
import (
|
||||
"gitea.redpowerfuture.com/red-future/common/beans"
|
||||
@@ -1,4 +1,4 @@
|
||||
package dataengine
|
||||
package check
|
||||
|
||||
import (
|
||||
"gitea.redpowerfuture.com/red-future/common/beans"
|
||||
@@ -1,4 +1,4 @@
|
||||
package yidun
|
||||
package check
|
||||
|
||||
import (
|
||||
"context"
|
||||
@@ -40,7 +40,7 @@ func (s *ImageDetectionService) DetectImage(ctx context.Context, imageURL, dataI
|
||||
return nil, fmt.Errorf("图片URL不能为空")
|
||||
}
|
||||
|
||||
businessId := g.Cfg().MustGet(ctx, "yidun.image.business_id").String()
|
||||
businessId := g.Cfg().MustGet(ctx, "check.image.business_id").String()
|
||||
g.Log().Infof(ctx, "图片检测任务提交, url: %s, business_id: %s", imageURL, businessId)
|
||||
|
||||
// 创建请求
|
||||
@@ -102,7 +102,7 @@ func (s *ImageDetectionService) DetectImageSync(ctx context.Context, imageURL, d
|
||||
return nil, fmt.Errorf("图片URL不能为空")
|
||||
}
|
||||
|
||||
businessId := g.Cfg().MustGet(ctx, "yidun.image.business_id").String()
|
||||
businessId := g.Cfg().MustGet(ctx, "check.image.business_id").String()
|
||||
g.Log().Infof(ctx, "图片同步检测, url: %s, business_id: %s", imageURL, businessId)
|
||||
|
||||
// 创建同步检测请求
|
||||
@@ -197,7 +197,7 @@ func (s *ImageDetectionService) GetImageResult(ctx context.Context, taskID strin
|
||||
return nil, fmt.Errorf("易盾图片检测客户端未初始化")
|
||||
}
|
||||
|
||||
businessId := g.Cfg().MustGet(ctx, "yidun.image.business_id").String()
|
||||
businessId := g.Cfg().MustGet(ctx, "check.image.business_id").String()
|
||||
g.Log().Infof(ctx, "查询图片检测结果, taskID: %s", taskID)
|
||||
|
||||
req := callback.NewImageCallbackRequest(businessId)
|
||||
+17
-18
@@ -1,10 +1,9 @@
|
||||
package dataengine
|
||||
package check
|
||||
|
||||
import (
|
||||
consts "cid/consts/dataengine"
|
||||
dao "cid/dao/dataengine"
|
||||
entity "cid/model/entity/dataengine"
|
||||
yidunService "cid/service/yidun"
|
||||
consts "cid/consts/check"
|
||||
dao "cid/dao/check"
|
||||
entity "cid/model/entity/check"
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
@@ -92,7 +91,7 @@ func (s *MaterialVerifyService) VerifyImageByID(ctx context.Context, imageID str
|
||||
func (s *MaterialVerifyService) submitImageCheck(ctx context.Context, image *entity.TencentImage, log *entity.MaterialVerifyLog) error {
|
||||
startTime := time.Now()
|
||||
|
||||
callbackMode := g.Cfg().MustGet(ctx, "yidun.callback_mode").Bool()
|
||||
callbackMode := g.Cfg().MustGet(ctx, "check.callback_mode").Bool()
|
||||
|
||||
requestParams := map[string]interface{}{
|
||||
"imageURL": image.PreviewURL,
|
||||
@@ -106,10 +105,10 @@ func (s *MaterialVerifyService) submitImageCheck(ctx context.Context, image *ent
|
||||
)
|
||||
|
||||
if callbackMode {
|
||||
callbackURL := g.Cfg().MustGet(ctx, "yidun.image.callback_url").String()
|
||||
callbackURL := g.Cfg().MustGet(ctx, "check.image.callback_url").String()
|
||||
requestParams["callbackURL"] = callbackURL
|
||||
|
||||
result, err := yidunService.ImageDetection.DetectImage(ctx, image.PreviewURL, image.ImageID, callbackURL)
|
||||
result, err := ImageDetection.DetectImage(ctx, image.PreviewURL, image.ImageID, callbackURL)
|
||||
duration = time.Since(startTime).Milliseconds()
|
||||
if err != nil {
|
||||
dao.MaterialVerifyLog.UpdateError(ctx, log.Id, entity.VerifyStatusPending, err.Error())
|
||||
@@ -127,7 +126,7 @@ func (s *MaterialVerifyService) submitImageCheck(ctx context.Context, image *ent
|
||||
g.Log().Infof(ctx, "图片异步检测已提交, id=%d, imageId=%s, taskId=%s, duration=%dms",
|
||||
image.Id, image.ImageID, taskID, duration)
|
||||
} else {
|
||||
syncResult, err := yidunService.ImageDetection.DetectImageSync(ctx, image.PreviewURL, image.ImageID)
|
||||
syncResult, err := ImageDetection.DetectImageSync(ctx, image.PreviewURL, image.ImageID)
|
||||
duration = time.Since(startTime).Milliseconds()
|
||||
if err != nil {
|
||||
dao.MaterialVerifyLog.UpdateError(ctx, log.Id, entity.VerifyStatusPending, err.Error())
|
||||
@@ -202,11 +201,11 @@ func (s *MaterialVerifyService) VerifyVideoByID(ctx context.Context, videoID str
|
||||
func (s *MaterialVerifyService) submitVideoCheck(ctx context.Context, video *entity.TencentVideo, log *entity.MaterialVerifyLog) error {
|
||||
startTime := time.Now()
|
||||
|
||||
callbackMode := g.Cfg().MustGet(ctx, "yidun.callback_mode").Bool()
|
||||
callbackMode := g.Cfg().MustGet(ctx, "check.callback_mode").Bool()
|
||||
|
||||
var callbackURL string
|
||||
if callbackMode {
|
||||
callbackURL = g.Cfg().MustGet(ctx, "yidun.video.callback_url").String()
|
||||
callbackURL = g.Cfg().MustGet(ctx, "check.video.callback_url").String()
|
||||
}
|
||||
|
||||
requestParams := map[string]interface{}{
|
||||
@@ -216,7 +215,7 @@ func (s *MaterialVerifyService) submitVideoCheck(ctx context.Context, video *ent
|
||||
}
|
||||
requestParamsJSON, _ := json.Marshal(requestParams)
|
||||
|
||||
result, err := yidunService.VideoDetection.DetectVideo(ctx, video.PreviewURL, video.VideoID, callbackURL)
|
||||
result, err := VideoDetection.DetectVideo(ctx, video.PreviewURL, video.VideoID, callbackURL)
|
||||
duration := time.Since(startTime).Milliseconds()
|
||||
|
||||
if err != nil {
|
||||
@@ -249,7 +248,7 @@ func (s *MaterialVerifyService) submitVideoCheck(ctx context.Context, video *ent
|
||||
func (s *MaterialVerifyService) ProcessImageCallback(ctx context.Context, callbackData string) error {
|
||||
g.Log().Infof(ctx, "处理图片校验回调, data: %s", callbackData)
|
||||
|
||||
var callback yidunService.ImageCallbackData
|
||||
var callback ImageCallbackData
|
||||
if err := json.Unmarshal([]byte(callbackData), &callback); err != nil {
|
||||
g.Log().Errorf(ctx, "解析图片回调数据失败: %v", err)
|
||||
return fmt.Errorf("解析图片回调数据失败: %w", err)
|
||||
@@ -301,7 +300,7 @@ func (s *MaterialVerifyService) ProcessImageCallback(ctx context.Context, callba
|
||||
func (s *MaterialVerifyService) ProcessVideoCallback(ctx context.Context, callbackData string) error {
|
||||
g.Log().Infof(ctx, "处理视频校验回调, data: %s", callbackData)
|
||||
|
||||
var callback yidunService.VideoCallbackData
|
||||
var callback VideoCallbackData
|
||||
if err := json.Unmarshal([]byte(callbackData), &callback); err != nil {
|
||||
g.Log().Errorf(ctx, "解析视频回调数据失败: %v", err)
|
||||
return fmt.Errorf("解析视频回调数据失败: %w", err)
|
||||
@@ -394,9 +393,9 @@ func (s *MaterialVerifyService) ProcessImageResultByTask(ctx context.Context, ta
|
||||
return fmt.Errorf("未找到校验日志, taskId=%s", taskID)
|
||||
}
|
||||
|
||||
result, err := yidunService.ImageDetection.GetImageResult(ctx, taskID)
|
||||
result, err := ImageDetection.GetImageResult(ctx, taskID)
|
||||
if err != nil {
|
||||
if err == yidunService.ErrImageResultNotFound || err == yidunService.ErrImageStillProcessing {
|
||||
if err == ErrImageResultNotFound || err == ErrImageStillProcessing {
|
||||
g.Log().Infof(ctx, "图片检测结果未就绪, taskId=%s, 保持pending状态, err=%v", taskID, err)
|
||||
return ErrResultPending
|
||||
}
|
||||
@@ -450,9 +449,9 @@ func (s *MaterialVerifyService) ProcessVideoResultByTask(ctx context.Context, ta
|
||||
return fmt.Errorf("未找到校验日志, taskId=%s", taskID)
|
||||
}
|
||||
|
||||
result, err := yidunService.VideoDetection.GetVideoResult(ctx, taskID)
|
||||
result, err := VideoDetection.GetVideoResult(ctx, taskID)
|
||||
if err != nil {
|
||||
if err == yidunService.ErrVideoResultNotFound || err == yidunService.ErrVideoStillProcessing {
|
||||
if err == ErrVideoResultNotFound || err == ErrVideoStillProcessing {
|
||||
g.Log().Infof(ctx, "视频检测结果未就绪, taskId=%s, 保持pending状态, err=%v", taskID, err)
|
||||
return ErrResultPending
|
||||
}
|
||||
+8
-9
@@ -1,10 +1,9 @@
|
||||
package dataengine
|
||||
package check
|
||||
|
||||
import (
|
||||
consts "cid/consts/dataengine"
|
||||
dao "cid/dao/dataengine"
|
||||
entity "cid/model/entity/dataengine"
|
||||
yidunService "cid/service/yidun"
|
||||
consts "cid/consts/check"
|
||||
dao "cid/dao/check"
|
||||
entity "cid/model/entity/check"
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
@@ -22,7 +21,7 @@ var TencentContentCallback = new(TencentContentCallbackService)
|
||||
func (s *TencentContentCallbackService) ProcessImageCallback(ctx context.Context, callbackData string) error {
|
||||
g.Log().Infof(ctx, "处理图片检测回调, data: %s", callbackData)
|
||||
|
||||
var callback yidunService.ImageCallbackData
|
||||
var callback ImageCallbackData
|
||||
if err := json.Unmarshal([]byte(callbackData), &callback); err != nil {
|
||||
g.Log().Errorf(ctx, "解析图片回调数据失败: %v", err)
|
||||
return fmt.Errorf("解析回调数据失败: %w", err)
|
||||
@@ -61,7 +60,7 @@ func (s *TencentContentCallbackService) ProcessImageCallback(ctx context.Context
|
||||
func (s *TencentContentCallbackService) ProcessVideoCallback(ctx context.Context, callbackData string) error {
|
||||
g.Log().Infof(ctx, "处理视频检测回调, data: %s", callbackData)
|
||||
|
||||
var callback yidunService.VideoCallbackData
|
||||
var callback VideoCallbackData
|
||||
if err := json.Unmarshal([]byte(callbackData), &callback); err != nil {
|
||||
g.Log().Errorf(ctx, "解析视频回调数据失败: %v", err)
|
||||
return fmt.Errorf("解析回调数据失败: %w", err)
|
||||
@@ -110,7 +109,7 @@ func (s *TencentContentCallbackService) ProcessImageResult(ctx context.Context,
|
||||
return fmt.Errorf("未找到送检日志, taskId=%s", taskID)
|
||||
}
|
||||
|
||||
result, err := yidunService.ImageDetection.GetImageResult(ctx, taskID)
|
||||
result, err := ImageDetection.GetImageResult(ctx, taskID)
|
||||
if err != nil {
|
||||
g.Log().Errorf(ctx, "查询图片检测结果失败: %v", err)
|
||||
return fmt.Errorf("查询图片检测结果失败: %w", err)
|
||||
@@ -136,7 +135,7 @@ func (s *TencentContentCallbackService) ProcessVideoResult(ctx context.Context,
|
||||
return fmt.Errorf("未找到送检日志, taskId=%s", taskID)
|
||||
}
|
||||
|
||||
result, err := yidunService.VideoDetection.GetVideoResult(ctx, taskID)
|
||||
result, err := VideoDetection.GetVideoResult(ctx, taskID)
|
||||
if err != nil {
|
||||
g.Log().Errorf(ctx, "查询视频检测结果失败: %v", err)
|
||||
return fmt.Errorf("查询视频检测结果失败: %w", err)
|
||||
+36
-9
@@ -1,10 +1,9 @@
|
||||
package dataengine
|
||||
package check
|
||||
|
||||
import (
|
||||
consts "cid/consts/dataengine"
|
||||
dao "cid/dao/dataengine"
|
||||
entity "cid/model/entity/dataengine"
|
||||
yidunService "cid/service/yidun"
|
||||
consts "cid/consts/check"
|
||||
dao "cid/dao/check"
|
||||
entity "cid/model/entity/check"
|
||||
"context"
|
||||
"encoding/json"
|
||||
"sync"
|
||||
@@ -294,7 +293,7 @@ func (s *TencentContentCheckService) writeAuditLog(ctx context.Context, sourceTa
|
||||
}
|
||||
|
||||
// SubmitImageByID 根据图片ID手动提交送检(统一走 MaterialVerify 系统)
|
||||
func (s *TencentContentCheckService) SubmitImageByID(ctx context.Context, imageID string) (*yidunService.ImageSubmitResult, error) {
|
||||
func (s *TencentContentCheckService) SubmitImageByID(ctx context.Context, imageID string) (*ImageSubmitResult, error) {
|
||||
mLog, err := MaterialVerify.VerifyImageByID(ctx, imageID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -305,13 +304,13 @@ func (s *TencentContentCheckService) SubmitImageByID(ctx context.Context, imageI
|
||||
s.writeAuditLog(ctx, consts.SourceTableTencentImage, image.Id, imageID, image.PreviewURL, mLog.TaskID, -1, 0, 0, "", 0)
|
||||
}
|
||||
|
||||
return &yidunService.ImageSubmitResult{
|
||||
return &ImageSubmitResult{
|
||||
TaskID: mLog.TaskID,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// SubmitVideoByID 根据视频ID手动提交送检(统一走 MaterialVerify 系统)
|
||||
func (s *TencentContentCheckService) SubmitVideoByID(ctx context.Context, videoID string) (*yidunService.VideoSubmitResult, error) {
|
||||
func (s *TencentContentCheckService) SubmitVideoByID(ctx context.Context, videoID string) (*VideoSubmitResult, error) {
|
||||
mLog, err := MaterialVerify.VerifyVideoByID(ctx, videoID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -322,7 +321,7 @@ func (s *TencentContentCheckService) SubmitVideoByID(ctx context.Context, videoI
|
||||
s.writeAuditLog(ctx, consts.SourceTableTencentVideo, video.Id, videoID, video.PreviewURL, mLog.TaskID, -1, 0, 0, "", 0)
|
||||
}
|
||||
|
||||
return &yidunService.VideoSubmitResult{
|
||||
return &VideoSubmitResult{
|
||||
TaskID: mLog.TaskID,
|
||||
}, nil
|
||||
}
|
||||
@@ -368,3 +367,31 @@ func (s *TencentContentCheckService) GetConfig() ContentCheckConfig {
|
||||
defer s.mu.RUnlock()
|
||||
return s.config
|
||||
}
|
||||
|
||||
// GetImageSubmitResult 获取图片提交结果(从送检日志解析)
|
||||
func (s *TencentContentCheckService) GetImageSubmitResult(ctx context.Context, id int64) (*ImageSubmitResult, error) {
|
||||
log, err := dao.TencentContentCheckLog.GetByID(ctx, id)
|
||||
if err != nil || log == nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var result ImageSubmitResult
|
||||
if err := json.Unmarshal([]byte(log.ResponseData), &result); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &result, nil
|
||||
}
|
||||
|
||||
// GetVideoSubmitResult 获取视频提交结果(从送检日志解析)
|
||||
func (s *TencentContentCheckService) GetVideoSubmitResult(ctx context.Context, id int64) (*VideoSubmitResult, error) {
|
||||
log, err := dao.TencentContentCheckLog.GetByID(ctx, id)
|
||||
if err != nil || log == nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var result VideoSubmitResult
|
||||
if err := json.Unmarshal([]byte(log.ResponseData), &result); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &result, nil
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package yidun
|
||||
package check
|
||||
|
||||
import (
|
||||
"context"
|
||||
@@ -1,4 +1,4 @@
|
||||
package yidun
|
||||
package check
|
||||
|
||||
import (
|
||||
"context"
|
||||
@@ -1,4 +1,4 @@
|
||||
package yidun
|
||||
package check
|
||||
|
||||
import (
|
||||
"context"
|
||||
@@ -23,26 +23,26 @@ func InitYidunClients(ctx context.Context) error {
|
||||
clients := &YidunClients{}
|
||||
|
||||
// 文本检测
|
||||
secretId := g.Cfg().MustGet(ctx, "yidun.text.secret_id").String()
|
||||
secretKey := g.Cfg().MustGet(ctx, "yidun.text.secret_key").String()
|
||||
secretId := g.Cfg().MustGet(ctx, "check.text.secret_id").String()
|
||||
secretKey := g.Cfg().MustGet(ctx, "check.text.secret_key").String()
|
||||
if secretId != "" && secretKey != "" {
|
||||
clients.TextClient = text.NewTextClientWithAccessKey(secretId, secretKey)
|
||||
g.Log().Info(ctx, "文本检测客户端初始化成功")
|
||||
}
|
||||
|
||||
// 图片检测
|
||||
secretId = g.Cfg().MustGet(ctx, "yidun.image.secret_id").String()
|
||||
secretKey = g.Cfg().MustGet(ctx, "yidun.image.secret_key").String()
|
||||
businessId := g.Cfg().MustGet(ctx, "yidun.image.business_id").String()
|
||||
secretId = g.Cfg().MustGet(ctx, "check.image.secret_id").String()
|
||||
secretKey = g.Cfg().MustGet(ctx, "check.image.secret_key").String()
|
||||
businessId := g.Cfg().MustGet(ctx, "check.image.business_id").String()
|
||||
if secretId != "" && secretKey != "" {
|
||||
clients.ImageClient = image.NewImageClientWithAccessKey(secretId, secretKey)
|
||||
g.Log().Infof(ctx, "图片检测客户端初始化成功, business_id: %s", businessId)
|
||||
}
|
||||
|
||||
// 视频检测
|
||||
secretId = g.Cfg().MustGet(ctx, "yidun.video.secret_id").String()
|
||||
secretKey = g.Cfg().MustGet(ctx, "yidun.video.secret_key").String()
|
||||
businessId = g.Cfg().MustGet(ctx, "yidun.video.business_id").String()
|
||||
secretId = g.Cfg().MustGet(ctx, "check.video.secret_id").String()
|
||||
secretKey = g.Cfg().MustGet(ctx, "check.video.secret_key").String()
|
||||
businessId = g.Cfg().MustGet(ctx, "check.video.business_id").String()
|
||||
if secretId != "" && secretKey != "" {
|
||||
clients.VideoClient = videosolution.NewVideoSolutionClientWithAccessKey(secretId, secretKey)
|
||||
g.Log().Infof(ctx, "视频检测客户端初始化成功, business_id: %s", businessId)
|
||||
Reference in New Issue
Block a user