v0.0.28 Добавлена модерация загруженного в S3 изображения по url перед сохранением в бд
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
f86590570c
commit
f77b03bee1
@ -11,6 +11,7 @@ import (
|
||||
"tailly_back_v2/internal/repository"
|
||||
"tailly_back_v2/internal/utils"
|
||||
"tailly_back_v2/pkg/S3"
|
||||
"tailly_back_v2/pkg/moderation"
|
||||
"time"
|
||||
|
||||
"github.com/99designs/gqlgen/graphql"
|
||||
@ -109,6 +110,23 @@ func (s *postService) Create(ctx context.Context, authorID int, title string, co
|
||||
|
||||
imageURL := fmt.Sprintf("https://s3.regru.cloud/tailly/%s", s3Key)
|
||||
|
||||
modClient, err := moderation.NewModerationClient("tailly_censor:50051")
|
||||
if err != nil {
|
||||
S3.DeleteFromS3(imageURL) // удаляем если ошибка модерации
|
||||
return nil, fmt.Errorf("%s: failed to create moderation client: %w", op, err)
|
||||
}
|
||||
defer modClient.Close()
|
||||
|
||||
allowed, err := modClient.CheckImageURL(ctx, imageURL)
|
||||
if err != nil {
|
||||
S3.DeleteFromS3(imageURL)
|
||||
return nil, fmt.Errorf("%s: image moderation failed: %w", op, err)
|
||||
}
|
||||
if !allowed {
|
||||
S3.DeleteFromS3(imageURL)
|
||||
return nil, errors.New("image rejected by moderation service")
|
||||
}
|
||||
|
||||
post := &domain.Post{
|
||||
Title: title,
|
||||
Content: imageURL,
|
||||
|
||||
@ -3,8 +3,9 @@ package moderation
|
||||
import (
|
||||
"context"
|
||||
|
||||
"google.golang.org/grpc"
|
||||
pb "tailly_back_v2/pkg/moderation/proto"
|
||||
|
||||
"google.golang.org/grpc"
|
||||
)
|
||||
|
||||
type ModerationClient struct {
|
||||
@ -38,3 +39,12 @@ func (c *ModerationClient) CheckImage(ctx context.Context, imageData []byte) (bo
|
||||
func (c *ModerationClient) Close() {
|
||||
c.conn.Close()
|
||||
}
|
||||
func (c *ModerationClient) CheckImageURL(ctx context.Context, imageURL string) (bool, error) {
|
||||
resp, err := c.client.CheckImage(ctx, &pb.ImageRequest{
|
||||
ImageUrl: imageURL, // ← Передаем URL вместо данных!
|
||||
})
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
return resp.OverallDecision == "allowed", nil
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user