调整目录
This commit is contained in:
+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()})
|
||||
Reference in New Issue
Block a user