Skip to content

Commit

Permalink
feat: face online
Browse files Browse the repository at this point in the history
  • Loading branch information
Aaron3S authored and LeeEirc committed Dec 12, 2024
1 parent 7fff022 commit 136114a
Show file tree
Hide file tree
Showing 14 changed files with 5,397 additions and 2,294 deletions.
23 changes: 12 additions & 11 deletions cmd/impl/jms.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,17 +50,18 @@ func (j *JMServer) GetTokenAuthInfo(ctx context.Context, req *pb.TokenRequest) (
}
setting := j.uploader.GetTerminalSetting()
dbTokenInfo := pb.TokenAuthInfo{
KeyId: tokenAuthInfo.Id,
SecreteId: tokenAuthInfo.Value,
Asset: ConvertToProtobufAsset(tokenAuthInfo.Asset),
User: ConvertToProtobufUser(tokenAuthInfo.User),
FilterRules: ConvertToProtobufFilterRules(tokenAuthInfo.CommandFilterACLs),
Account: ConvertToProtobufAccount(tokenAuthInfo.Account),
Permission: ConvertToProtobufPermission(tokenAuthInfo.Actions),
ExpireInfo: ConvertToProtobufExpireInfo(tokenAuthInfo.ExpireAt),
Gateways: ConvertToProtobufGateways(gateways),
Setting: ConvertToPbSetting(&setting),
Platform: ConvertToPbPlatform(&tokenAuthInfo.Platform),
KeyId: tokenAuthInfo.Id,
SecreteId: tokenAuthInfo.Value,
Asset: ConvertToProtobufAsset(tokenAuthInfo.Asset),
User: ConvertToProtobufUser(tokenAuthInfo.User),
FilterRules: ConvertToProtobufFilterRules(tokenAuthInfo.CommandFilterACLs),
Account: ConvertToProtobufAccount(tokenAuthInfo.Account),
Permission: ConvertToProtobufPermission(tokenAuthInfo.Actions),
ExpireInfo: ConvertToProtobufExpireInfo(tokenAuthInfo.ExpireAt),
Gateways: ConvertToProtobufGateways(gateways),
Setting: ConvertToPbSetting(&setting),
Platform: ConvertToPbPlatform(&tokenAuthInfo.Platform),
FaceMonitorToken: tokenAuthInfo.FaceMonitorToken,
}
status.Ok = true
logger.Debugf("Get database auth info success by token: %s", req.Token)
Expand Down
41 changes: 41 additions & 0 deletions cmd/impl/jms_face_callback.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,44 @@ func (j *JMServer) FaceRecognitionCallback(ctx context.Context, req *pb.FaceReco
Status: &status,
}, nil
}

func (j *JMServer) FaceMonitorCallback(ctx context.Context, req *pb.FaceMonitorCallbackRequest) (*pb.FaceMonitorCallbackResponse, error) {
var status pb.Status

result := service.FaceMonitorResult{
Token: req.Token,
Success: req.Success,
ErrorMessage: req.ErrorMessage,
FaceCodes: req.FaceCodes,
IsFinished: req.IsFinished,
Action: req.Action,
}
if err := j.apiClient.SendFaceMonitorCallback(result); err != nil {
status.Ok = false
status.Err = err.Error()
} else {
status.Ok = true
}
return &pb.FaceMonitorCallbackResponse{
Status: &status,
}, nil
}

func (j *JMServer) JoinFaceMonitor(ctx context.Context, req *pb.JoinFaceMonitorRequest) (*pb.JoinFaceMonitorResponse, error) {

var status pb.Status

joinRequest := service.JoinFaceMonitorRequest{
FaceMonitorToken: req.FaceMonitorToken,
SessionId: req.SessionId,
}
if err := j.apiClient.JoinFaceMonitor(joinRequest); err != nil {
status.Ok = false
status.Err = err.Error()
} else {
status.Ok = true
}
return &pb.JoinFaceMonitorResponse{
Status: &status,
}, nil
}
30 changes: 30 additions & 0 deletions pkg/jms-sdk-go/service/jms_face_callback.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,33 @@ func (s *JMService) SendFaceRecognitionCallback(result FaceRecognitionResult) er
}
return nil
}

type FaceMonitorResult struct {
Token string `json:"token"`
IsFinished bool `json:"is_finished"`
Success bool `json:"success"`
ErrorMessage string `json:"error_message"`
Action string `json:"action"`
FaceCodes []string `json:"face_codes"`
}

func (s *JMService) SendFaceMonitorCallback(result FaceMonitorResult) error {
var resp = map[string]interface{}{}
if _, err := s.authClient.Post(FaceMonitorURL, &result, &resp); err != nil {
return err
}
return nil
}

type JoinFaceMonitorRequest struct {
FaceMonitorToken string `json:"face_monitor_token"`
SessionId string `json:"session_id"`
}

func (s *JMService) JoinFaceMonitor(result JoinFaceMonitorRequest) error {
var resp = map[string]interface{}{}
if _, err := s.authClient.Post(FaceMonitorContextUrl, &result, &resp); err != nil {
return err
}
return nil
}
4 changes: 3 additions & 1 deletion pkg/jms-sdk-go/service/url.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,5 +85,7 @@ const (
)

const (
FaceRecognitionURL = "/api/v1/authentication/face/callback/"
FaceRecognitionURL = "/api/v1/authentication/face/callback/"
FaceMonitorURL = "/api/v1/authentication/face-monitor/callback/"
FaceMonitorContextUrl = "/api/v1/authentication/face-monitor/context/"
)
Loading

0 comments on commit 136114a

Please sign in to comment.