This commit is contained in:
戴育兵 2025-12-16 15:22:06 +08:00
parent c93ae3f602
commit 1fd4feefc9
5 changed files with 1278 additions and 304 deletions

File diff suppressed because it is too large Load Diff

View File

@ -126,3 +126,44 @@ func (this *UsageReq) Validate() error {
func (this *UsageResp) Validate() error {
return nil
}
func (this *SecurityStatusData) Validate() error {
return nil
}
func (this *SecurityScanReq) Validate() error {
return nil
}
func (this *SecurityScanResp) Validate() error {
return nil
}
func (this *UpdateFileSecurityStatusReq) Validate() error {
for _, item := range this.SecurityStatusData {
if item != nil {
if err := github_com_mwitkow_go_proto_validators.CallValidatorIfExists(item); err != nil {
return github_com_mwitkow_go_proto_validators.FieldError("SecurityStatusData", err)
}
}
}
return nil
}
func (this *UpdateFileSecurityStatusResp) Validate() error {
return nil
}
func (this *ManualAntiReq) Validate() error {
for _, item := range this.SecurityStatusData {
if item != nil {
if err := github_com_mwitkow_go_proto_validators.CallValidatorIfExists(item); err != nil {
return github_com_mwitkow_go_proto_validators.FieldError("SecurityStatusData", err)
}
}
}
return nil
}
func (this *ManualAntiResp) Validate() error {
return nil
}
func (this *GetFileSecurityStatusReq) Validate() error {
return nil
}
func (this *GetFileSecurityStatusResp) Validate() error {
return nil
}

View File

@ -42,6 +42,10 @@ type FileClient interface {
Action(ctx context.Context, in *ActionReq, opts ...grpc_go.CallOption) (*ActionResp, common.ErrorWithAttachment)
DirDownload(ctx context.Context, in *DirDownloadReq, opts ...grpc_go.CallOption) (File_DirDownloadClient, error)
Usage(ctx context.Context, in *UsageReq, opts ...grpc_go.CallOption) (*UsageResp, common.ErrorWithAttachment)
SecurityScan(ctx context.Context, in *SecurityScanReq, opts ...grpc_go.CallOption) (*SecurityScanResp, common.ErrorWithAttachment)
UpdateFileSecurityStatus(ctx context.Context, in *UpdateFileSecurityStatusReq, opts ...grpc_go.CallOption) (*UpdateFileSecurityStatusResp, common.ErrorWithAttachment)
ManualAnti(ctx context.Context, in *ManualAntiReq, opts ...grpc_go.CallOption) (*ManualAntiResp, common.ErrorWithAttachment)
GetFileSecurityStatus(ctx context.Context, in *GetFileSecurityStatusReq, opts ...grpc_go.CallOption) (*GetFileSecurityStatusResp, common.ErrorWithAttachment)
}
type fileClient struct {
@ -49,19 +53,23 @@ type fileClient struct {
}
type FileClientImpl struct {
List func(ctx context.Context, in *FileListReq) (*FileListResp, error)
Info func(ctx context.Context, in *FileInfoReq) (*FileInfoResp, error)
Create func(ctx context.Context, in *CreateReq) (*CreateResp, error)
Delete func(ctx context.Context, in *DeleteReq) (*DeleteResp, error)
Search func(ctx context.Context, in *SearchReq) (*SearchResp, error)
Upload func(ctx context.Context, in *UploadReq) (*UploadResp, error)
TusCreate func(ctx context.Context, in *TusCreateReq) (*TusCreateResp, error)
TusUpload func(ctx context.Context, in *TusUploadReq) (*TusUploadResp, error)
ResumableTransfer func(ctx context.Context, in *ResumableTransferReq) (*ResumableTransferResp, error)
Preview func(ctx context.Context, in *PreviewReq) (*PreviewResp, error)
Action func(ctx context.Context, in *ActionReq) (*ActionResp, error)
DirDownload func(ctx context.Context, in *DirDownloadReq) (File_DirDownloadClient, error)
Usage func(ctx context.Context, in *UsageReq) (*UsageResp, error)
List func(ctx context.Context, in *FileListReq) (*FileListResp, error)
Info func(ctx context.Context, in *FileInfoReq) (*FileInfoResp, error)
Create func(ctx context.Context, in *CreateReq) (*CreateResp, error)
Delete func(ctx context.Context, in *DeleteReq) (*DeleteResp, error)
Search func(ctx context.Context, in *SearchReq) (*SearchResp, error)
Upload func(ctx context.Context, in *UploadReq) (*UploadResp, error)
TusCreate func(ctx context.Context, in *TusCreateReq) (*TusCreateResp, error)
TusUpload func(ctx context.Context, in *TusUploadReq) (*TusUploadResp, error)
ResumableTransfer func(ctx context.Context, in *ResumableTransferReq) (*ResumableTransferResp, error)
Preview func(ctx context.Context, in *PreviewReq) (*PreviewResp, error)
Action func(ctx context.Context, in *ActionReq) (*ActionResp, error)
DirDownload func(ctx context.Context, in *DirDownloadReq) (File_DirDownloadClient, error)
Usage func(ctx context.Context, in *UsageReq) (*UsageResp, error)
SecurityScan func(ctx context.Context, in *SecurityScanReq) (*SecurityScanResp, error)
UpdateFileSecurityStatus func(ctx context.Context, in *UpdateFileSecurityStatusReq) (*UpdateFileSecurityStatusResp, error)
ManualAnti func(ctx context.Context, in *ManualAntiReq) (*ManualAntiResp, error)
GetFileSecurityStatus func(ctx context.Context, in *GetFileSecurityStatusReq) (*GetFileSecurityStatusResp, error)
}
func (c *FileClientImpl) GetDubboStub(cc *triple.TripleConn) FileClient {
@ -181,6 +189,30 @@ func (c *fileClient) Usage(ctx context.Context, in *UsageReq, opts ...grpc_go.Ca
return out, c.cc.Invoke(ctx, "/"+interfaceKey+"/Usage", in, out)
}
func (c *fileClient) SecurityScan(ctx context.Context, in *SecurityScanReq, opts ...grpc_go.CallOption) (*SecurityScanResp, common.ErrorWithAttachment) {
out := new(SecurityScanResp)
interfaceKey := ctx.Value(constant.InterfaceKey).(string)
return out, c.cc.Invoke(ctx, "/"+interfaceKey+"/SecurityScan", in, out)
}
func (c *fileClient) UpdateFileSecurityStatus(ctx context.Context, in *UpdateFileSecurityStatusReq, opts ...grpc_go.CallOption) (*UpdateFileSecurityStatusResp, common.ErrorWithAttachment) {
out := new(UpdateFileSecurityStatusResp)
interfaceKey := ctx.Value(constant.InterfaceKey).(string)
return out, c.cc.Invoke(ctx, "/"+interfaceKey+"/UpdateFileSecurityStatus", in, out)
}
func (c *fileClient) ManualAnti(ctx context.Context, in *ManualAntiReq, opts ...grpc_go.CallOption) (*ManualAntiResp, common.ErrorWithAttachment) {
out := new(ManualAntiResp)
interfaceKey := ctx.Value(constant.InterfaceKey).(string)
return out, c.cc.Invoke(ctx, "/"+interfaceKey+"/ManualAnti", in, out)
}
func (c *fileClient) GetFileSecurityStatus(ctx context.Context, in *GetFileSecurityStatusReq, opts ...grpc_go.CallOption) (*GetFileSecurityStatusResp, common.ErrorWithAttachment) {
out := new(GetFileSecurityStatusResp)
interfaceKey := ctx.Value(constant.InterfaceKey).(string)
return out, c.cc.Invoke(ctx, "/"+interfaceKey+"/GetFileSecurityStatus", in, out)
}
// FileServer is the server API for File service.
// All implementations must embed UnimplementedFileServer
// for forward compatibility
@ -198,6 +230,10 @@ type FileServer interface {
Action(context.Context, *ActionReq) (*ActionResp, error)
DirDownload(*DirDownloadReq, File_DirDownloadServer) error
Usage(context.Context, *UsageReq) (*UsageResp, error)
SecurityScan(context.Context, *SecurityScanReq) (*SecurityScanResp, error)
UpdateFileSecurityStatus(context.Context, *UpdateFileSecurityStatusReq) (*UpdateFileSecurityStatusResp, error)
ManualAnti(context.Context, *ManualAntiReq) (*ManualAntiResp, error)
GetFileSecurityStatus(context.Context, *GetFileSecurityStatusReq) (*GetFileSecurityStatusResp, error)
mustEmbedUnimplementedFileServer()
}
@ -245,6 +281,18 @@ func (UnimplementedFileServer) DirDownload(*DirDownloadReq, File_DirDownloadServ
func (UnimplementedFileServer) Usage(context.Context, *UsageReq) (*UsageResp, error) {
return nil, status.Errorf(codes.Unimplemented, "method Usage not implemented")
}
func (UnimplementedFileServer) SecurityScan(context.Context, *SecurityScanReq) (*SecurityScanResp, error) {
return nil, status.Errorf(codes.Unimplemented, "method SecurityScan not implemented")
}
func (UnimplementedFileServer) UpdateFileSecurityStatus(context.Context, *UpdateFileSecurityStatusReq) (*UpdateFileSecurityStatusResp, error) {
return nil, status.Errorf(codes.Unimplemented, "method UpdateFileSecurityStatus not implemented")
}
func (UnimplementedFileServer) ManualAnti(context.Context, *ManualAntiReq) (*ManualAntiResp, error) {
return nil, status.Errorf(codes.Unimplemented, "method ManualAnti not implemented")
}
func (UnimplementedFileServer) GetFileSecurityStatus(context.Context, *GetFileSecurityStatusReq) (*GetFileSecurityStatusResp, error) {
return nil, status.Errorf(codes.Unimplemented, "method GetFileSecurityStatus not implemented")
}
func (s *UnimplementedFileServer) XXX_SetProxyImpl(impl protocol.Invoker) {
s.proxyImpl = impl
}
@ -648,6 +696,122 @@ func _File_Usage_Handler(srv interface{}, ctx context.Context, dec func(interfac
return interceptor(ctx, in, info, handler)
}
func _File_SecurityScan_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc_go.UnaryServerInterceptor) (interface{}, error) {
in := new(SecurityScanReq)
if err := dec(in); err != nil {
return nil, err
}
base := srv.(dubbo3.Dubbo3GrpcService)
args := []interface{}{}
args = append(args, in)
md, _ := metadata.FromIncomingContext(ctx)
invAttachment := make(map[string]interface{}, len(md))
for k, v := range md {
invAttachment[k] = v
}
invo := invocation.NewRPCInvocation("SecurityScan", args, invAttachment)
if interceptor == nil {
result := base.XXX_GetProxyImpl().Invoke(ctx, invo)
return result, result.Error()
}
info := &grpc_go.UnaryServerInfo{
Server: srv,
FullMethod: ctx.Value("XXX_TRIPLE_GO_INTERFACE_NAME").(string),
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
result := base.XXX_GetProxyImpl().Invoke(ctx, invo)
return result, result.Error()
}
return interceptor(ctx, in, info, handler)
}
func _File_UpdateFileSecurityStatus_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc_go.UnaryServerInterceptor) (interface{}, error) {
in := new(UpdateFileSecurityStatusReq)
if err := dec(in); err != nil {
return nil, err
}
base := srv.(dubbo3.Dubbo3GrpcService)
args := []interface{}{}
args = append(args, in)
md, _ := metadata.FromIncomingContext(ctx)
invAttachment := make(map[string]interface{}, len(md))
for k, v := range md {
invAttachment[k] = v
}
invo := invocation.NewRPCInvocation("UpdateFileSecurityStatus", args, invAttachment)
if interceptor == nil {
result := base.XXX_GetProxyImpl().Invoke(ctx, invo)
return result, result.Error()
}
info := &grpc_go.UnaryServerInfo{
Server: srv,
FullMethod: ctx.Value("XXX_TRIPLE_GO_INTERFACE_NAME").(string),
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
result := base.XXX_GetProxyImpl().Invoke(ctx, invo)
return result, result.Error()
}
return interceptor(ctx, in, info, handler)
}
func _File_ManualAnti_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc_go.UnaryServerInterceptor) (interface{}, error) {
in := new(ManualAntiReq)
if err := dec(in); err != nil {
return nil, err
}
base := srv.(dubbo3.Dubbo3GrpcService)
args := []interface{}{}
args = append(args, in)
md, _ := metadata.FromIncomingContext(ctx)
invAttachment := make(map[string]interface{}, len(md))
for k, v := range md {
invAttachment[k] = v
}
invo := invocation.NewRPCInvocation("ManualAnti", args, invAttachment)
if interceptor == nil {
result := base.XXX_GetProxyImpl().Invoke(ctx, invo)
return result, result.Error()
}
info := &grpc_go.UnaryServerInfo{
Server: srv,
FullMethod: ctx.Value("XXX_TRIPLE_GO_INTERFACE_NAME").(string),
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
result := base.XXX_GetProxyImpl().Invoke(ctx, invo)
return result, result.Error()
}
return interceptor(ctx, in, info, handler)
}
func _File_GetFileSecurityStatus_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc_go.UnaryServerInterceptor) (interface{}, error) {
in := new(GetFileSecurityStatusReq)
if err := dec(in); err != nil {
return nil, err
}
base := srv.(dubbo3.Dubbo3GrpcService)
args := []interface{}{}
args = append(args, in)
md, _ := metadata.FromIncomingContext(ctx)
invAttachment := make(map[string]interface{}, len(md))
for k, v := range md {
invAttachment[k] = v
}
invo := invocation.NewRPCInvocation("GetFileSecurityStatus", args, invAttachment)
if interceptor == nil {
result := base.XXX_GetProxyImpl().Invoke(ctx, invo)
return result, result.Error()
}
info := &grpc_go.UnaryServerInfo{
Server: srv,
FullMethod: ctx.Value("XXX_TRIPLE_GO_INTERFACE_NAME").(string),
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
result := base.XXX_GetProxyImpl().Invoke(ctx, invo)
return result, result.Error()
}
return interceptor(ctx, in, info, handler)
}
// File_ServiceDesc is the grpc_go.ServiceDesc for File service.
// It's only intended for direct use with grpc_go.RegisterService,
// and not to be introspected or modified (even as a copy)
@ -703,6 +867,22 @@ var File_ServiceDesc = grpc_go.ServiceDesc{
MethodName: "Usage",
Handler: _File_Usage_Handler,
},
{
MethodName: "SecurityScan",
Handler: _File_SecurityScan_Handler,
},
{
MethodName: "UpdateFileSecurityStatus",
Handler: _File_UpdateFileSecurityStatus_Handler,
},
{
MethodName: "ManualAnti",
Handler: _File_ManualAnti_Handler,
},
{
MethodName: "GetFileSecurityStatus",
Handler: _File_GetFileSecurityStatus_Handler,
},
},
Streams: []grpc_go.StreamDesc{
{

View File

@ -9,6 +9,7 @@ import (
"fonchain-fiee/api/aryshare"
"fonchain-fiee/api/bundle"
"fonchain-fiee/api/cast"
"fonchain-fiee/api/files"
"fonchain-fiee/cmd/config"
"fonchain-fiee/pkg/cache"
"fonchain-fiee/pkg/e"
@ -34,15 +35,16 @@ func UpdateWorkImage(ctx *gin.Context) {
var req *cast.UpdateWorkImageReq
var infoResp *accountFiee.UserInfoResponse
var err error
var ok bool
if err = ctx.ShouldBind(&req); err != nil {
service.Error(ctx, err)
return
}
// 图片鉴定
for _, v := range req.Images {
ok, _err := check.SecurityFile(v)
if _err != nil {
service.Error(ctx, _err)
ok, err = check.SecurityFile(v)
if err != nil {
service.Error(ctx, err)
return
}
if !ok {
@ -50,6 +52,24 @@ func UpdateWorkImage(ctx *gin.Context) {
return
}
}
ok, err = check.SecurityText(req.Title)
if err != nil {
service.Error(ctx, err)
return
}
if !ok {
service.Error(ctx, errors.New("标题鉴定未通过"))
return
}
ok, err = check.SecurityText(req.Content)
if err != nil {
service.Error(ctx, err)
return
}
if !ok {
service.Error(ctx, errors.New("内容鉴定未通过"))
return
}
artistId, _ := strconv.ParseUint(req.ArtistUuid, 10, 64)
infoResp, err = service.AccountFieeProvider.Info(context.Background(), &accountFiee.InfoRequest{
ID: artistId,
@ -108,19 +128,54 @@ func UpdateWorkVideo(ctx *gin.Context) {
var req *cast.UpdateWorkVideoReq
var infoResp *accountFiee.UserInfoResponse
var err error
var ok bool
if err = ctx.ShouldBind(&req); err != nil {
service.Error(ctx, err)
return
}
ok, _err := check.SecurityFile(req.CoverUrl)
if _err != nil {
service.Error(ctx, _err)
ok, err = check.SecurityText(req.Title)
if err != nil {
service.Error(ctx, err)
return
}
if !ok {
service.Error(ctx, errors.New("标题鉴定未通过"))
return
}
ok, err = check.SecurityText(req.Content)
if err != nil {
service.Error(ctx, err)
return
}
if !ok {
service.Error(ctx, errors.New("内容鉴定未通过"))
return
}
ok, err := check.SecurityFile(req.CoverUrl)
if err != nil {
service.Error(ctx, err)
return
}
if !ok {
service.Error(ctx, errors.New("图片鉴定未通过"))
return
}
if req.VideoUrl != "" {
//请求接口判断
fileResp, errs := service.FilesProvider.GetFileSecurityStatus(ctx, &files.GetFileSecurityStatusReq{
Url: req.VideoUrl,
FileName: "",
})
if errs != nil {
service.Error(ctx, err)
return
}
if fileResp.SecurityStatus != "none" {
service.Error(ctx, errors.New("视频鉴定未通过"))
return
}
}
if config.AppConfig.System.AppMode != "dev" {
artistId, _ := strconv.ParseUint(req.ArtistUuid, 10, 64)
infoResp, err = service.AccountFieeProvider.Info(context.Background(), &accountFiee.InfoRequest{

View File

@ -77,6 +77,21 @@ func SecurityFile(textVal string) (bool, error) {
}
return true, nil
}
func SecurityText(textVal string) (bool, error) {
aliConfig, err := pkgSecurity.GetGlobalConfig("./data/alibabacloud.env")
if err != nil {
return false, err
}
fmt.Println("开始获取STS Token")
err = aliConfig.GetSTSToken()
if err != nil {
return false, errors.New("获取STS Token失败")
}
if err = handleTextScan(aliConfig, textVal); err != nil {
return false, err
}
return true, nil
}
func securityScan(fileInfo *modelSecurity.FileInfo) (err error) {
//加载阿里云配置获取临时token
@ -113,7 +128,7 @@ func handleVideoScan(config *security.Config, fileInfo *modelSecurity.FileInfo)
fmt.Println("视频不能为空")
return errors.New("视频不能为空")
}
serviceType := security.VideoBaselineCheckGlobal
serviceType := security.VideoPostCheckByVLGlobal
dataID := "video_" + time.Now().Format("20060102150405")
fmt.Println("正在扫描视频(这可能需要几分钟)...")
@ -165,7 +180,7 @@ func handleImageScan(config *security.Config, fileInfo *modelSecurity.FileInfo)
return errors.New("文件不能为空")
}
serviceType := security.BaselineCheckGlobal
serviceType := security.PostImageCheckByVLGlobal
fmt.Println("正在扫描图片...")
result, err := scanner.ScanImageByURL(fileInfo.FileUrl, "image_"+time.Now().Format("20060102150405"), serviceType)
@ -208,6 +223,14 @@ func handleTextScan(config *security.Config, textVal string) (err error) {
return errors.New("扫描失败")
}
scanner.PrintResult(result)
for _, v := range result.Data {
for _, vv := range v.Results {
label := *vv.Label
if label != "nonLabel" {
return errors.New("风险等级过高")
}
}
}
fmt.Println(result)
return nil
}