public async Task SubmitSelfie()

in packages/ekyc-api/src/ekyc-api/Controllers/SessionController.cs [162:231]


        public async Task SubmitSelfie(string sessionId, string s3Key)
        {
            if (string.IsNullOrEmpty(sessionId))
                throw new HttpStatusException(HttpStatusCode.InternalServerError, "Session ID cannot be blank.");

            if (string.IsNullOrEmpty(s3Key))
                throw new HttpStatusException(HttpStatusCode.InternalServerError, "S3 key cannot be blank.");

            // Check if the session exists
            var sessionValid = await _sessionManager.SessionExistsAndIsValid(sessionId);

            if (!sessionValid)
                throw new HttpStatusException(HttpStatusCode.InternalServerError,
                    $"Session ID {sessionId} not found or has expired.");

            var config = new DynamoDBOperationConfig
            {
                OverrideTableName = Globals.SessionTableName
            };

            var item = await _dbContext.LoadAsync<SessionObject>(sessionId, config);

            if (item == null) throw new HttpStatusException(HttpStatusCode.InternalServerError, "Session not found.");

            var imaging = new Imaging(_amazonS3, _documentChecker);
            Image img;

            s3Key = sessionId + "/" + s3Key;

            _logger.LogDebug($"Using {s3Key} as selfie.");

            try
            {
                img = await imaging.GetImageFromStorage(s3Key);
            }
            catch (ImageFormatException)
            {
                throw new HttpStatusException(HttpStatusCode.InternalServerError, "Key provided is not a valid image.");
            }
            catch (Exception ex)
            {
                throw new HttpStatusException(HttpStatusCode.InternalServerError, ex.Message);
            }

            if (img == null)
                throw new HttpStatusException(HttpStatusCode.InternalServerError, "Image is not valid.");

            await _livenessChecker.VerifyImageSize(img);

            var eyesOpen = await _livenessChecker.VerifyEyesOpen(s3Key);

            if (!eyesOpen)
                throw new HttpStatusException(HttpStatusCode.InternalServerError,
                    "Please make sure your eyes are open.");

            var verification = await _livenessChecker.VerifySelfieFacePose(s3Key);

            if (!string.IsNullOrEmpty(verification))
                throw new HttpStatusException(HttpStatusCode.InternalServerError, verification);

            var faceIsInCentre = await _livenessChecker.VerifyFaceIsInCentre(s3Key);

            if (!faceIsInCentre)
                throw new HttpStatusException(HttpStatusCode.InternalServerError,
                    "Please ensure your face is in the centre of the image.");

            item.selfieImageKey = s3Key;

            await _dbContext.SaveAsync(item, config);
        }