Sub2API v1.0 - AI API 网关(二开初始版本,基于上游 Wei-Shaw/sub2api)
Release / update-version (push) Has been cancelled
Release / build-frontend (push) Has been cancelled
Release / release (push) Has been cancelled
Release / sync-version-file (push) Has been cancelled
CI / shell (push) Canceled after 0s
CI / test (push) Canceled after 0s
CI / frontend (push) Canceled after 0s
CI / golangci-lint (push) Canceled after 0s
Security Scan / backend-security (push) Canceled after 0s
Security Scan / frontend-security (push) Canceled after 0s
Release / update-version (push) Has been cancelled
Release / build-frontend (push) Has been cancelled
Release / release (push) Has been cancelled
Release / sync-version-file (push) Has been cancelled
CI / shell (push) Canceled after 0s
CI / test (push) Canceled after 0s
CI / frontend (push) Canceled after 0s
CI / golangci-lint (push) Canceled after 0s
Security Scan / backend-security (push) Canceled after 0s
Security Scan / frontend-security (push) Canceled after 0s
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
package securityaudit
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/Wei-Shaw/sub2api/internal/service"
|
||||
)
|
||||
|
||||
type LegacyModerationAdapter struct {
|
||||
service *service.ContentModerationService
|
||||
}
|
||||
|
||||
func NewLegacyModerationAdapter(svc *service.ContentModerationService) LegacyEngine {
|
||||
return &LegacyModerationAdapter{service: svc}
|
||||
}
|
||||
|
||||
func (a *LegacyModerationAdapter) Check(ctx context.Context, req Request) (*LegacyDecision, error) {
|
||||
if a == nil || a.service == nil {
|
||||
return nil, nil
|
||||
}
|
||||
decision, err := a.service.Check(ctx, service.ContentModerationCheckInput{
|
||||
RequestID: req.RequestID, UserID: req.UserID, UserEmail: req.UserEmail,
|
||||
APIKeyID: req.APIKeyID, APIKeyName: req.APIKeyName, GroupID: cloneInt64Ptr(req.GroupID),
|
||||
GroupName: req.GroupName, Endpoint: req.Endpoint, Provider: req.Provider,
|
||||
Model: req.Model, Protocol: req.Protocol, Body: req.Body,
|
||||
})
|
||||
if err != nil || decision == nil {
|
||||
return nil, err
|
||||
}
|
||||
return &LegacyDecision{
|
||||
Allowed: decision.Allowed, Blocked: decision.Blocked, Flagged: decision.Flagged,
|
||||
Message: decision.Message, StatusCode: decision.StatusCode,
|
||||
ErrorCode: "content_policy_violation", Action: decision.Action,
|
||||
}, nil
|
||||
}
|
||||
Reference in New Issue
Block a user