tailly_back_v2/pkg/moderation/moderation.go
admin ef9bb2c484
All checks were successful
continuous-integration/drone/push Build is passing
v0.0.27 Изменен принцип загрузки изображения в s3
2025-08-28 09:55:17 +03:00

52 lines
1.1 KiB
Go

package moderation
import (
"context"
pb "tailly_back_v2/pkg/moderation/proto"
"google.golang.org/grpc"
)
type ModerationClient struct {
conn *grpc.ClientConn
client pb.ModerationServiceClient
}
func NewModerationClient(addr string) (*ModerationClient, error) {
conn, err := grpc.Dial(addr, grpc.WithInsecure())
if err != nil {
return nil, err
}
return &ModerationClient{
conn: conn,
client: pb.NewModerationServiceClient(conn),
}, nil
}
func (c *ModerationClient) CheckImage(ctx context.Context, imageData []byte) (bool, error) {
resp, err := c.client.CheckImage(ctx, &pb.ImageRequest{
ImageData: imageData,
})
if err != nil {
return false, err
}
return resp.OverallDecision == "allowed", nil
}
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
}
func (c *ModerationClient) Close() {
c.conn.Close()
}