51 lines
1.1 KiB
Go
51 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) 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
|
|
}
|