@opexa/portal-components 0.0.259 → 0.0.261
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/client/hooks/useCamera.d.ts +11 -16
- package/dist/client/hooks/useCamera.js +29 -57
- package/dist/client/hooks/useUploadFileMutation.d.ts +4 -0
- package/dist/client/hooks/useUploadFileMutation.js +24 -0
- package/dist/client/hooks/useUploadImageFileMutation.d.ts +2 -2
- package/dist/client/hooks/useUploadImageFileMutation.js +2 -2
- package/dist/client/hooks/useUploadPrivateImageFileMutation.d.ts +4 -0
- package/dist/client/hooks/useUploadPrivateImageFileMutation.js +24 -0
- package/dist/components/Bonus/Bonus.client.js +1 -1
- package/dist/components/Cashback/Cashback.client.js +1 -1
- package/dist/components/CustomPromo/CustomPromo.js +1 -1
- package/dist/components/DepositWithdrawal/Deposit/OnlineBankDeposit/OnlineBankDepositContext.d.ts +2 -2
- package/dist/components/DepositWithdrawal/Deposit/OnlineBankDeposit/useOnlineBankDeposit.d.ts +1 -1
- package/dist/components/DepositWithdrawal/Deposit/QRPHDeposit/QRPHDepositContext.d.ts +2 -2
- package/dist/components/DepositWithdrawal/Deposit/QRPHDeposit/useQRPHDeposit.d.ts +1 -1
- package/dist/components/Disclaimer/Disclaimer.d.ts +1 -1
- package/dist/components/Disclaimer/DisclaimerV2.d.ts +1 -1
- package/dist/components/Disclaimer/DisclaimerV2.js +7 -5
- package/dist/components/GameLaunch/GameLaunch.lazy.js +1 -1
- package/dist/components/GamesSearch/GamesSearch.js +1 -1
- package/dist/components/Jackpots/JackpotsCarousel/JackpotsCarouselItem.module.css +184 -184
- package/dist/components/Jackpots/JackpotsList/JackpotsListItem.module.css +184 -184
- package/dist/components/KYC/AutoOpen.js +3 -8
- package/dist/components/KYC/utils.js +18 -18
- package/dist/components/Messages/Message.js +3 -2
- package/dist/components/Messages/MessagePopup.js +3 -2
- package/dist/components/News/News.js +1 -1
- package/dist/components/PortalProvider/FeatureFlag.js +1 -1
- package/dist/components/Promo/Promo.client.js +1 -1
- package/dist/components/Search/Search.lazy.js +1 -1
- package/dist/components/SignUp/SignUpForm.js +0 -4
- package/dist/components/SignUp/SignUpPagcor/CaptureIdDocument.d.ts +1 -0
- package/dist/components/SignUp/SignUpPagcor/CaptureIdDocument.js +198 -0
- package/dist/components/SignUp/SignUpPagcor/CaptureSelfie.d.ts +1 -0
- package/dist/components/SignUp/SignUpPagcor/CaptureSelfie.js +251 -0
- package/dist/components/SignUp/SignUpPagcor/ImageUploader.d.ts +10 -0
- package/dist/components/SignUp/SignUpPagcor/ImageUploader.js +41 -0
- package/dist/components/SignUp/SignUpPagcor/SignUpFormPagcor.d.ts +1 -0
- package/dist/components/SignUp/SignUpPagcor/SignUpFormPagcor.js +429 -0
- package/dist/components/SignUp/SignUpPagcor/SignUpPagcor.lazy.d.ts +13 -0
- package/dist/components/SignUp/SignUpPagcor/SignUpPagcor.lazy.js +26 -0
- package/dist/components/SignUp/SignUpPagcor/SignUpPagcorContext.d.ts +7 -0
- package/dist/components/SignUp/SignUpPagcor/SignUpPagcorContext.js +2 -0
- package/dist/components/SignUp/SignUpPagcor/useImageUploader.d.ts +11 -0
- package/dist/components/SignUp/SignUpPagcor/useImageUploader.js +20 -0
- package/dist/components/Tournaments/TournamentsCarousel/TournamentsCarouselItem.module.css +184 -184
- package/dist/components/Tournaments/TournamentsList/TournamentItem.module.css +184 -184
- package/dist/components/shared/IdFrontImageField/IdFrontImageField.client.d.ts +15 -0
- package/dist/components/shared/IdFrontImageField/IdFrontImageField.client.js +140 -0
- package/dist/components/shared/IdFrontImageField/IdFrontImageField.d.ts +2 -0
- package/dist/components/shared/IdFrontImageField/IdFrontImageField.js +11 -0
- package/dist/components/shared/IdFrontImageField/IdFrontImageFieldContext.d.ts +6 -0
- package/dist/components/shared/IdFrontImageField/IdFrontImageFieldContext.js +2 -0
- package/dist/components/shared/IdFrontImageField/index.d.ts +1 -0
- package/dist/components/shared/IdFrontImageField/index.js +1 -0
- package/dist/components/shared/IdFrontImageField/useIdFrontImageField.d.ts +22 -0
- package/dist/components/shared/IdFrontImageField/useIdFrontImageField.js +111 -0
- package/dist/components/shared/SelfieImageField/SelfieImageField.client.d.ts +15 -0
- package/dist/components/shared/SelfieImageField/SelfieImageField.client.js +170 -0
- package/dist/components/shared/SelfieImageField/SelfieImageField.d.ts +2 -0
- package/dist/components/shared/SelfieImageField/SelfieImageField.js +11 -0
- package/dist/components/shared/SelfieImageField/SelfieImageFieldContext.d.ts +6 -0
- package/dist/components/shared/SelfieImageField/SelfieImageFieldContext.js +2 -0
- package/dist/components/shared/SelfieImageField/index.d.ts +1 -0
- package/dist/components/shared/SelfieImageField/index.js +1 -0
- package/dist/components/shared/SelfieImageField/useSelfieImageField.d.ts +23 -0
- package/dist/components/shared/SelfieImageField/useSelfieImageField.js +208 -0
- package/dist/handlers/deleteSession.d.ts +9 -0
- package/dist/handlers/deleteSession.js +19 -0
- package/dist/handlers/getHealthCheck.d.ts +9 -0
- package/dist/handlers/getHealthCheck.js +16 -0
- package/dist/handlers/getSession.d.ts +10 -0
- package/dist/handlers/getSession.js +63 -0
- package/dist/handlers/index.d.ts +40 -0
- package/dist/handlers/index.js +56 -0
- package/dist/handlers/patchSession.d.ts +10 -0
- package/dist/handlers/patchSession.js +26 -0
- package/dist/handlers/postAuthenticate.d.ts +10 -0
- package/dist/handlers/postAuthenticate.js +51 -0
- package/dist/handlers/postSession.d.ts +17 -0
- package/dist/handlers/postSession.js +78 -0
- package/dist/handlers/postTransformIdFrontImage.d.ts +3 -0
- package/dist/handlers/postTransformIdFrontImage.js +67 -0
- package/dist/handlers/postTransformSelfieImage.d.ts +3 -0
- package/dist/handlers/postTransformSelfieImage.js +71 -0
- package/dist/services/file.d.ts +17 -12
- package/dist/services/file.js +21 -1
- package/dist/services/queries.d.ts +3 -1
- package/dist/services/queries.js +2568 -2532
- package/dist/styles/theme.css +694 -694
- package/dist/ui/DatePicker/DatePicker.d.ts +72 -72
- package/dist/ui/DatePicker/datePicker.recipe.d.ts +3 -3
- package/dist/utils/mutationKeys.d.ts +2 -0
- package/dist/utils/mutationKeys.js +8 -0
- package/dist/utils/resizeImageSize.d.ts +1 -0
- package/dist/utils/resizeImageSize.js +5 -0
- package/package.json +166 -165
- package/dist/client/hooks/index.d.ts +0 -65
- package/dist/client/hooks/index.js +0 -65
- package/dist/client/services/index.d.ts +0 -4
- package/dist/client/services/index.js +0 -4
- package/dist/client/utils/index.d.ts +0 -3
- package/dist/client/utils/index.js +0 -3
- package/dist/components/CashbackBonus/CashbackBonus.client.d.ts +0 -2
- package/dist/components/CashbackBonus/CashbackBonus.client.js +0 -9
- package/dist/components/CashbackBonus/CashbackBonus.d.ts +0 -10
- package/dist/components/CashbackBonus/CashbackBonus.js +0 -5
- package/dist/components/CashbackBonus/index.d.ts +0 -1
- package/dist/components/CashbackBonus/index.js +0 -1
- package/dist/components/Empty.d.ts +0 -9
- package/dist/components/Empty.js +0 -7
- package/dist/components/Games/GameContext.d.ts +0 -2
- package/dist/components/Games/GameContext.js +0 -2
- package/dist/components/InfiniteScroll.d.ts +0 -10
- package/dist/components/InfiniteScroll.js +0 -25
- package/dist/components/JackpotCounter/JackpotCounter.client.d.ts +0 -2
- package/dist/components/JackpotCounter/JackpotCounter.client.js +0 -66
- package/dist/components/JackpotCounter/JackpotCounter.d.ts +0 -17
- package/dist/components/JackpotCounter/JackpotCounter.js +0 -21
- package/dist/components/JackpotCounter/JackpotCounterItem.d.ts +0 -18
- package/dist/components/JackpotCounter/JackpotCounterItem.js +0 -109
- package/dist/components/JackpotCounter/JackpotCounterItem.module.css +0 -184
- package/dist/components/JackpotCounter/index.d.ts +0 -1
- package/dist/components/JackpotCounter/index.js +0 -1
- package/dist/components/Jackpots/JackpotDesktop.d.ts +0 -1
- package/dist/components/Jackpots/JackpotDesktop.js +0 -45
- package/dist/components/Jackpots/JackpotGameProviders.d.ts +0 -5
- package/dist/components/Jackpots/JackpotGameProviders.js +0 -41
- package/dist/components/Jackpots/JackpotItemDesktop.d.ts +0 -9
- package/dist/components/Jackpots/JackpotItemDesktop.js +0 -43
- package/dist/components/Jackpots/JackpotItemMobile.d.ts +0 -9
- package/dist/components/Jackpots/JackpotItemMobile.js +0 -44
- package/dist/components/Jackpots/JackpotMobile.d.ts +0 -1
- package/dist/components/Jackpots/JackpotMobile.js +0 -46
- package/dist/components/Jackpots/JackpotRules.d.ts +0 -5
- package/dist/components/Jackpots/JackpotRules.js +0 -11
- package/dist/components/Jackpots/Jackpots.client.d.ts +0 -2
- package/dist/components/Jackpots/Jackpots.client.js +0 -29
- package/dist/components/Jackpots/JackpotsContext.d.ts +0 -4
- package/dist/components/Jackpots/JackpotsContext.js +0 -3
- package/dist/components/Jackpots/useJackpotData.d.ts +0 -14
- package/dist/components/Jackpots/useJackpotData.js +0 -93
- package/dist/components/Jackpots/useJackpotItemData.d.ts +0 -20
- package/dist/components/Jackpots/useJackpotItemData.js +0 -87
- package/dist/components/KYC/Header.d.ts +0 -1
- package/dist/components/KYC/Header.js +0 -8
- package/dist/components/KYC/Step1.d.ts +0 -1
- package/dist/components/KYC/Step1.js +0 -13
- package/dist/components/KYC/Step2.d.ts +0 -1
- package/dist/components/KYC/Step2.js +0 -13
- package/dist/components/KYC/Step3.d.ts +0 -1
- package/dist/components/KYC/Step3.js +0 -13
- package/dist/components/KYC/Step4.d.ts +0 -1
- package/dist/components/KYC/Step4.js +0 -7
- package/dist/components/Messages/MessageItem.d.ts +0 -4
- package/dist/components/Messages/MessageItem.js +0 -34
- package/dist/components/Promo/PromoContent.d.ts +0 -2
- package/dist/components/Promo/PromoContent.js +0 -9
- package/dist/components/Promos/PromoCarousel.d.ts +0 -2
- package/dist/components/Promos/PromoCarousel.js +0 -41
- package/dist/components/Promos/PromoGrid.d.ts +0 -2
- package/dist/components/Promos/PromoGrid.js +0 -12
- package/dist/components/Promos/PromoItem.d.ts +0 -7
- package/dist/components/Promos/PromoItem.js +0 -10
- package/dist/components/TournamentCounter/TournamentCounter.client.d.ts +0 -2
- package/dist/components/TournamentCounter/TournamentCounter.client.js +0 -50
- package/dist/components/TournamentCounter/TournamentCounter.d.ts +0 -8
- package/dist/components/TournamentCounter/TournamentCounter.js +0 -21
- package/dist/components/TournamentCounter/TournamentCounterItem.d.ts +0 -8
- package/dist/components/TournamentCounter/TournamentCounterItem.js +0 -106
- package/dist/components/TournamentCounter/index.d.ts +0 -1
- package/dist/components/TournamentCounter/index.js +0 -1
- package/dist/components/Tournaments/TournamentDesktop.d.ts +0 -1
- package/dist/components/Tournaments/TournamentDesktop.js +0 -57
- package/dist/components/Tournaments/TournamentGameProviders.d.ts +0 -5
- package/dist/components/Tournaments/TournamentGameProviders.js +0 -38
- package/dist/components/Tournaments/TournamentItemDesktop.d.ts +0 -7
- package/dist/components/Tournaments/TournamentItemDesktop.js +0 -56
- package/dist/components/Tournaments/TournamentItemMobile.d.ts +0 -7
- package/dist/components/Tournaments/TournamentItemMobile.js +0 -54
- package/dist/components/Tournaments/TournamentMobile.d.ts +0 -1
- package/dist/components/Tournaments/TournamentMobile.js +0 -55
- package/dist/components/Tournaments/TournamentRules.d.ts +0 -5
- package/dist/components/Tournaments/TournamentRules.js +0 -11
- package/dist/components/Tournaments/Tournaments.client.d.ts +0 -2
- package/dist/components/Tournaments/Tournaments.client.js +0 -20
- package/dist/components/Tournaments/TournamentsContext.d.ts +0 -4
- package/dist/components/Tournaments/TournamentsContext.js +0 -3
- package/dist/components/Tournaments/useTournamentData.d.ts +0 -10
- package/dist/components/Tournaments/useTournamentData.js +0 -72
- package/dist/components/Tournaments/useTournamentItemData.d.ts +0 -16
- package/dist/components/Tournaments/useTournamentItemData.js +0 -64
- package/dist/components/index.d.ts +0 -33
- package/dist/components/index.js +0 -33
- package/dist/constants/endpoints.d.ts +0 -10
- package/dist/constants/endpoints.js +0 -41
- package/dist/constants/envVars.d.ts +0 -5
- package/dist/constants/envVars.js +0 -28
- package/dist/constants/gameProviders.d.ts +0 -76
- package/dist/constants/gameProviders.js +0 -361
- package/dist/constants/gameTypes.d.ts +0 -3
- package/dist/constants/gameTypes.js +0 -64
- package/dist/constants/headerKeys.d.ts +0 -2
- package/dist/constants/headerKeys.js +0 -2
- package/dist/constants/secretQuestions.d.ts +0 -3
- package/dist/constants/secretQuestions.js +0 -24
- package/dist/constants/storageKeys.d.ts +0 -2
- package/dist/constants/storageKeys.js +0 -2
- package/dist/icons/index.d.ts +0 -65
- package/dist/icons/index.js +0 -65
- package/dist/images/hacksaw-gaming.png +0 -0
- package/dist/server/services/index.d.ts +0 -4
- package/dist/server/services/index.js +0 -4
- package/dist/server/utils/index.d.ts +0 -29
- package/dist/server/utils/index.js +0 -29
- package/dist/ui/Presence.d.ts +0 -2
- package/dist/ui/Presence.js +0 -7
- package/dist/ui/Prose.d.ts +0 -2
- package/dist/ui/Prose.js +0 -5
- package/dist/ui/index.d.ts +0 -26
- package/dist/ui/index.js +0 -26
- package/dist/utils/createErrorFromCode.d.ts +0 -2
- package/dist/utils/createErrorFromCode.js +0 -11
- package/dist/utils/index.d.ts +0 -17
- package/dist/utils/index.js +0 -17
- package/dist/utils/isMobile.d.ts +0 -5
- package/dist/utils/isMobile.js +0 -9
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { useFieldContext } from '@ark-ui/react';
|
|
2
|
+
import { useRef } from 'react';
|
|
3
|
+
import invariant from 'tiny-invariant';
|
|
4
|
+
import { useMediaQuery } from 'usehooks-ts';
|
|
5
|
+
import { useCamera } from '../../../client/hooks/useCamera.js';
|
|
6
|
+
import { useControllableState } from '../../../client/hooks/useControllableState.js';
|
|
7
|
+
import { useDisclosure } from '../../../client/hooks/useDisclosure.js';
|
|
8
|
+
import { useFileQuery } from '../../../client/hooks/useFileQuery.js';
|
|
9
|
+
import { useUploadPrivateImageFileMutation } from '../../../client/hooks/useUploadPrivateImageFileMutation.js';
|
|
10
|
+
import { toaster } from '../../../client/utils/toaster.js';
|
|
11
|
+
export function useIdFrontImageField(props) {
|
|
12
|
+
const field = useFieldContext();
|
|
13
|
+
const [value, setValue] = useControllableState({
|
|
14
|
+
value: props.value,
|
|
15
|
+
defaultValue: props.defaultValue ?? '',
|
|
16
|
+
onChange: props.onChange,
|
|
17
|
+
});
|
|
18
|
+
const query = useFileQuery(value, {
|
|
19
|
+
refetchInterval({ state }) {
|
|
20
|
+
return !state.data || state.data.status === 'UPLOADING' ? 1000 : false;
|
|
21
|
+
},
|
|
22
|
+
});
|
|
23
|
+
const mutation = useUploadPrivateImageFileMutation({
|
|
24
|
+
onSuccess(id) {
|
|
25
|
+
setValue(id);
|
|
26
|
+
},
|
|
27
|
+
onMutate() {
|
|
28
|
+
setValue('');
|
|
29
|
+
},
|
|
30
|
+
onError(error) {
|
|
31
|
+
toaster.error({
|
|
32
|
+
title: 'Upload Failed',
|
|
33
|
+
description: error.message,
|
|
34
|
+
});
|
|
35
|
+
},
|
|
36
|
+
onSettled() {
|
|
37
|
+
if (inputRef.current) {
|
|
38
|
+
inputRef.current.value = '';
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
});
|
|
42
|
+
const inputRef = useRef(null);
|
|
43
|
+
const maskRef = useRef(null);
|
|
44
|
+
const guideRef = useRef(null);
|
|
45
|
+
const desktop = useMediaQuery('(min-width: 1024px)');
|
|
46
|
+
const camera = useCamera({
|
|
47
|
+
video: {
|
|
48
|
+
facingMode: desktop ? 'user' : 'environment',
|
|
49
|
+
},
|
|
50
|
+
async transform(ctx) {
|
|
51
|
+
const body = new FormData();
|
|
52
|
+
const guideRect = guideRef.current?.getBoundingClientRect();
|
|
53
|
+
const videoRect = ctx.video.getBoundingClientRect();
|
|
54
|
+
invariant(guideRect, "'guideRef.getBoundingClientRect()' fails");
|
|
55
|
+
const scaleX = ctx.image.width / videoRect.width;
|
|
56
|
+
const scaleY = ctx.image.height / videoRect.height;
|
|
57
|
+
const cropTop = (guideRect.top - videoRect.top) * scaleY;
|
|
58
|
+
const cropLeft = (guideRect.left - videoRect.left) * scaleX;
|
|
59
|
+
const cropWidth = guideRect.width * scaleX;
|
|
60
|
+
const cropHeight = guideRect.height * scaleY;
|
|
61
|
+
body.append('image', ctx.file);
|
|
62
|
+
body.append('cropTop', cropTop.toString());
|
|
63
|
+
body.append('cropLeft', cropLeft.toString());
|
|
64
|
+
body.append('cropWidth', cropWidth.toString());
|
|
65
|
+
body.append('cropHeight', cropHeight.toString());
|
|
66
|
+
const response = await fetch('/api/transformers/id-front-image', {
|
|
67
|
+
method: 'POST',
|
|
68
|
+
body,
|
|
69
|
+
});
|
|
70
|
+
const blob = await response.blob();
|
|
71
|
+
const file = new File([blob], ctx.file.name, {
|
|
72
|
+
type: ctx.file.type,
|
|
73
|
+
endings: 'native',
|
|
74
|
+
lastModified: Date.now(),
|
|
75
|
+
});
|
|
76
|
+
const url = URL.createObjectURL(file);
|
|
77
|
+
const image = new Image();
|
|
78
|
+
image.src = url;
|
|
79
|
+
image.alt = '';
|
|
80
|
+
image.width = ctx.image.width;
|
|
81
|
+
image.height = ctx.image.height;
|
|
82
|
+
return {
|
|
83
|
+
ok: true,
|
|
84
|
+
data: {
|
|
85
|
+
url,
|
|
86
|
+
file,
|
|
87
|
+
image,
|
|
88
|
+
},
|
|
89
|
+
};
|
|
90
|
+
},
|
|
91
|
+
});
|
|
92
|
+
const disclosure = useDisclosure({
|
|
93
|
+
onOpenChange(open) {
|
|
94
|
+
if (open) {
|
|
95
|
+
camera.open();
|
|
96
|
+
}
|
|
97
|
+
},
|
|
98
|
+
});
|
|
99
|
+
return {
|
|
100
|
+
field,
|
|
101
|
+
value,
|
|
102
|
+
setValue,
|
|
103
|
+
query,
|
|
104
|
+
mutation,
|
|
105
|
+
camera,
|
|
106
|
+
disclosure,
|
|
107
|
+
inputRef,
|
|
108
|
+
guideRef,
|
|
109
|
+
maskRef,
|
|
110
|
+
};
|
|
111
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { type CSSProperties, type RefObject } from 'react';
|
|
2
|
+
import { type ValidateFileError } from '../../../utils/validateFile';
|
|
3
|
+
import { type UseSelfieImageFieldProps } from './useSelfieImageField';
|
|
4
|
+
export interface SelfieImageFieldProps extends UseSelfieImageFieldProps {
|
|
5
|
+
ref?: RefObject<HTMLDivElement | null>;
|
|
6
|
+
id?: string;
|
|
7
|
+
style?: CSSProperties;
|
|
8
|
+
className?: string;
|
|
9
|
+
invalid?: boolean;
|
|
10
|
+
readOnly?: boolean;
|
|
11
|
+
disabled?: boolean;
|
|
12
|
+
required?: boolean;
|
|
13
|
+
onError?: (error: ValidateFileError<'FaceNotFoundError'>) => void;
|
|
14
|
+
}
|
|
15
|
+
export declare function SelfieImageField__client(props: SelfieImageFieldProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import Image from 'next/image';
|
|
3
|
+
import { useEffect, useId, useState, } from 'react';
|
|
4
|
+
import { twMerge } from 'tailwind-merge';
|
|
5
|
+
import { Camera01Icon } from '../../../icons/Camera01Icon.js';
|
|
6
|
+
import { CameraOffIcon } from '../../../icons/CameraOffIcon.js';
|
|
7
|
+
import { CheckCircleIcon } from '../../../icons/CheckCircleIcon.js';
|
|
8
|
+
import { RefreshCcw01Icon } from '../../../icons/RefreshCcw01Icon.js';
|
|
9
|
+
import { Spinner02Icon } from '../../../icons/Spinner02Icon.js';
|
|
10
|
+
import { UploadCloud02Icon } from '../../../icons/UploadCloud02Icon.js';
|
|
11
|
+
import { XIcon } from '../../../icons/XIcon.js';
|
|
12
|
+
import { Button } from '../../../ui/Button/index.js';
|
|
13
|
+
import { Dialog } from '../../../ui/Dialog/index.js';
|
|
14
|
+
import { Portal } from '../../../ui/Portal/index.js';
|
|
15
|
+
import { createSplitProps } from '../../../utils/createSplitProps.js';
|
|
16
|
+
import { validateFile, } from '../../../utils/validateFile.js';
|
|
17
|
+
import { SelfieImageFieldProvider, useSelfieImageFieldContext, } from './SelfieImageFieldContext.js';
|
|
18
|
+
import { useSelfieImageField, } from './useSelfieImageField.js';
|
|
19
|
+
export function SelfieImageField__client(props) {
|
|
20
|
+
const [useSelfieImageFieldProps, localProps] = createSplitProps([
|
|
21
|
+
'value',
|
|
22
|
+
'onChange',
|
|
23
|
+
'defaultValue',
|
|
24
|
+
])(props);
|
|
25
|
+
const context = useSelfieImageField(useSelfieImageFieldProps);
|
|
26
|
+
return (_jsxs(SelfieImageFieldProvider, { value: context, children: [_jsxs("div", { ref: localProps.ref, id: localProps.id, style: localProps.style, className: twMerge('group', 'border', 'border-border-primary', 'bg-bg-primary', 'relative', 'w-full', 'aspect-[352/180]', 'shrink-0', 'rounded-xl', 'p-xl', localProps.className), onDragOver: (e) => e.preventDefault(), onDragEnter: (e) => e.preventDefault(), onDragLeave: (e) => e.preventDefault(), onDrop: async (e) => {
|
|
27
|
+
e.preventDefault();
|
|
28
|
+
const file = e.dataTransfer.files?.[0];
|
|
29
|
+
if (!file)
|
|
30
|
+
return;
|
|
31
|
+
const error = validateFile(file);
|
|
32
|
+
if (error)
|
|
33
|
+
return localProps.onError?.(error);
|
|
34
|
+
context.mutation.mutate({ file });
|
|
35
|
+
}, "aria-describedby": context.field?.ariaDescribedby, children: [_jsx("input", { id: context.field?.ids?.control, ref: context.inputRef, type: "file", accept: "image/png, image/jpeg", onChange: async (e) => {
|
|
36
|
+
const file = e.target.files?.[0];
|
|
37
|
+
if (!file)
|
|
38
|
+
return;
|
|
39
|
+
const error = validateFile(file);
|
|
40
|
+
if (error)
|
|
41
|
+
return localProps.onError?.(error);
|
|
42
|
+
context.mutation.mutate({ file });
|
|
43
|
+
}, disabled: context.field?.disabled ||
|
|
44
|
+
context.query.isLoading ||
|
|
45
|
+
context.mutation.isPending ||
|
|
46
|
+
localProps.disabled, readOnly: context.field?.readOnly || localProps.readOnly, required: context.field?.required || localProps.required, className: "sr-only" }), !context.query.data?.url && (_jsxs("div", { className: "flex size-full flex-col justify-center", children: [_jsx("div", { className: "border-border-primary shadow-xs mx-auto flex size-8 items-center justify-center rounded-sm border", children: _jsx(UploadCloud02Icon, { className: "text-text-placeholder-subtle size-4" }) }), _jsxs("h2", { className: "text-text-tertiary-600 mt-lg", children: [_jsxs("span", { className: "block text-center text-sm", children: [_jsx("button", { type: "button", onClick: () => {
|
|
47
|
+
context.inputRef.current?.click();
|
|
48
|
+
}, disabled: context.field?.disabled ||
|
|
49
|
+
context.field?.readOnly ||
|
|
50
|
+
context.query.isLoading ||
|
|
51
|
+
context.mutation.isPending ||
|
|
52
|
+
localProps.disabled ||
|
|
53
|
+
localProps.readOnly, className: "text-button-secondary-fg font-semibold disabled:opacity-60", children: "Click to upload" }), ' ', "or drag and drop"] }), _jsx("span", { className: "mt-xs block text-center text-xs", children: "PNG, JPG or JPEG (max. 10mb)" }), _jsx("span", { className: "m-txs block text-center text-xs", children: "or" })] }), _jsx(Button, { size: "sm", variant: "outline", className: "mx-auto mt-md w-auto", onClick: () => {
|
|
54
|
+
context.disclosure.setOpen(true);
|
|
55
|
+
}, disabled: context.field?.disabled ||
|
|
56
|
+
context.field?.readOnly ||
|
|
57
|
+
context.query.isLoading ||
|
|
58
|
+
context.mutation.isPending ||
|
|
59
|
+
localProps.disabled ||
|
|
60
|
+
localProps.readOnly, children: "Take a photo" })] })), context.query.data?.url && (_jsxs("div", { className: "relative", children: [_jsx(Image, { src: context.query.data.url, alt: "", width: 600, height: 600, unoptimized: true, className: "h-auto w-full rounded-md" }), _jsx("button", { type: "button", className: "backdrop-blur-xs absolute right-2 top-2 rounded-full bg-white/10 p-1", onClick: () => {
|
|
61
|
+
context.setValue('');
|
|
62
|
+
}, children: _jsx(XIcon, { className: "size-5" }) })] }))] }), _jsx(Camera, {})] }));
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* -------------------------------------
|
|
66
|
+
* Camera
|
|
67
|
+
* -------------------------------------
|
|
68
|
+
*/
|
|
69
|
+
function Camera() {
|
|
70
|
+
const context = useSelfieImageFieldContext();
|
|
71
|
+
return (_jsx(Dialog.Root, { open: context.disclosure.open, onOpenChange: (details) => {
|
|
72
|
+
context.disclosure.setOpen(details.open);
|
|
73
|
+
}, closeOnEscape: false, closeOnInteractOutside: false, onExitComplete: context.camera.close, children: _jsxs(Portal, { children: [_jsx(Dialog.Backdrop, { className: "!z-[calc(var(--z-dialog)+1)]" }), _jsx(Dialog.Positioner, { className: "!z-[calc(var(--z-dialog)+2)] flex items-center justify-center overflow-y-auto py-4", children: _jsxs(Dialog.Content, { className: "bg-bg-primary-alt mx-auto w-[calc(100dvw-1rem)] max-w-[calc(100dvw-1rem)] overflow-y-auto rounded-lg px-4 py-5 lg:w-[747px] lg:max-w-[747px] lg:px-3xl lg:py-4xl", children: [_jsx(Dialog.CloseTrigger, { children: _jsx(XIcon, {}) }), _jsx(Dialog.Title, { className: "text-center font-semibold lg:text-xl", children: "Take a Selfie Holding Your ID" }), _jsx(Dialog.Description, { className: "text-text-tertiary-600 mt-md text-center text-xs lg:text-base", children: "Make sure your face and ID are clearly visible, with no glare\u00A0or\u00A0blur." }), _jsxs("div", { className: "relative mt-5 lg:mt-10 lg:px-3xl", children: [_jsx(Video, {}), context.camera.error && (_jsxs("div", { className: "border-border-disabled flex aspect-[4/3] flex-col items-center justify-center rounded-md border bg-black px-4 lg:aspect-video", children: [_jsx(CameraOffIcon, { className: "text-text-placeholder-subtle size-10 text-center lg:size-12" }), _jsx("h2", { className: "mt-3 text-sm font-semibold lg:mt-4 lg:text-base", children: context.camera.error.name }), _jsx("p", { className: "text-text-tertiary-600 mt-0.5 text-center text-xs lg:mt-1 lg:text-sm", children: context.camera.error.message }), _jsx(Button, { size: "xs", variant: "outline", colorScheme: "gray", fullWidth: false, className: "mt-4 lg:mt-5", onClick: () => {
|
|
74
|
+
context.camera.reopen();
|
|
75
|
+
}, children: "Try again" })] })), context.camera.loading && (_jsx("div", { className: "border-border-disabled flex aspect-[4/3] flex-col items-center justify-center rounded-md border bg-black px-4 lg:aspect-video", children: _jsx(Spinner02Icon, { className: "text-text-placeholder size-8" }) })), context.camera.data && (_jsx("div", { className: "border-border-disabled aspect-[4/3] w-full overflow-hidden rounded-md border bg-black lg:aspect-video", children: _jsx(Image, { src: context.camera.data.url, alt: "", width: 600, height: 600, unoptimized: true, className: "mx-auto mt-2 block h-[calc(100%-1rem)] w-auto" }) }))] }), !context.camera.data && (_jsx("div", { className: "mt-5 lg:mt-10", children: _jsxs(Button, { className: "disabled:bg-bg-disabled disabled:text-text-disabled mx-auto w-full px-xl py-lg lg:w-[10rem]", onClick: () => {
|
|
76
|
+
context.camera.snap();
|
|
77
|
+
}, disabled: context.camera.loading ||
|
|
78
|
+
context.camera.snapping ||
|
|
79
|
+
!!context.camera.error ||
|
|
80
|
+
!context.faceFound, children: [context.camera.snapping ? (_jsx(Spinner02Icon, { className: "size-5" })) : (_jsx(Camera01Icon, { className: "size-5" })), "Capture"] }) })), context.camera.data && (_jsxs("div", { className: "mt-5 flex gap-3 lg:mt-10 lg:justify-center", children: [_jsxs(Button, { onClick: () => {
|
|
81
|
+
const file = context.camera.data?.file;
|
|
82
|
+
if (!file)
|
|
83
|
+
return;
|
|
84
|
+
context.mutation.mutate({ file });
|
|
85
|
+
context.disclosure.setOpen(false);
|
|
86
|
+
}, className: "w-full lg:w-[10rem]", children: [_jsx(CheckCircleIcon, { className: "size-5" }), "Use Photo"] }), _jsxs(Button, { variant: "outline", colorScheme: "gray", onClick: () => {
|
|
87
|
+
context.camera.reset();
|
|
88
|
+
}, className: "w-full lg:w-[10rem]", children: [_jsx(RefreshCcw01Icon, { className: "size-5" }), " Retake"] })] }))] }) })] }) }));
|
|
89
|
+
}
|
|
90
|
+
/*
|
|
91
|
+
* -------------------------------------
|
|
92
|
+
* Video
|
|
93
|
+
* -------------------------------------
|
|
94
|
+
*/
|
|
95
|
+
function Video() {
|
|
96
|
+
const id = useId();
|
|
97
|
+
const context = useSelfieImageFieldContext();
|
|
98
|
+
const [maskBox, setMaskBox] = useState({
|
|
99
|
+
x: 0,
|
|
100
|
+
y: 0,
|
|
101
|
+
width: 0,
|
|
102
|
+
height: 0,
|
|
103
|
+
});
|
|
104
|
+
useEffect(() => {
|
|
105
|
+
const update = () => {
|
|
106
|
+
const guide = context.guideRef.current;
|
|
107
|
+
const mask = context.maskRef.current;
|
|
108
|
+
if (!guide || !mask)
|
|
109
|
+
return;
|
|
110
|
+
const guideRect = guide.getBoundingClientRect();
|
|
111
|
+
const maskRect = mask.getBoundingClientRect();
|
|
112
|
+
const x = guideRect.left - maskRect.left;
|
|
113
|
+
const y = guideRect.top - maskRect.top;
|
|
114
|
+
const width = guideRect.width;
|
|
115
|
+
const height = guideRect.height;
|
|
116
|
+
if (width && height) {
|
|
117
|
+
setMaskBox({
|
|
118
|
+
x,
|
|
119
|
+
y,
|
|
120
|
+
width,
|
|
121
|
+
height,
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
};
|
|
125
|
+
const observer = new ResizeObserver(update);
|
|
126
|
+
if (context.guideRef.current)
|
|
127
|
+
observer.observe(context.guideRef.current);
|
|
128
|
+
if (context.maskRef.current)
|
|
129
|
+
observer.observe(context.maskRef.current);
|
|
130
|
+
requestAnimationFrame(update);
|
|
131
|
+
return () => observer.disconnect();
|
|
132
|
+
}, [context.guideRef, context.maskRef]);
|
|
133
|
+
const [videoSize, setVideoSize] = useState({
|
|
134
|
+
width: 0,
|
|
135
|
+
height: 0,
|
|
136
|
+
});
|
|
137
|
+
useEffect(() => {
|
|
138
|
+
const video = context.camera.videoRef.current;
|
|
139
|
+
if (!video)
|
|
140
|
+
return;
|
|
141
|
+
const updateVideoWidth = () => {
|
|
142
|
+
const rect = video.getBoundingClientRect();
|
|
143
|
+
setVideoSize({
|
|
144
|
+
width: rect.width,
|
|
145
|
+
height: rect.height,
|
|
146
|
+
});
|
|
147
|
+
};
|
|
148
|
+
video.addEventListener('loadedmetadata', updateVideoWidth);
|
|
149
|
+
video.addEventListener('resize', updateVideoWidth);
|
|
150
|
+
return () => {
|
|
151
|
+
video.removeEventListener('loadedmetadata', updateVideoWidth);
|
|
152
|
+
video.removeEventListener('resize', updateVideoWidth);
|
|
153
|
+
};
|
|
154
|
+
}, [context.camera.videoRef]);
|
|
155
|
+
const guideWidth = videoSize.width <= 0 || videoSize.height <= 0
|
|
156
|
+
? 0
|
|
157
|
+
: videoSize.width > videoSize.height
|
|
158
|
+
? videoSize.height
|
|
159
|
+
: videoSize.width;
|
|
160
|
+
return (_jsxs("div", { className: twMerge('relative h-auto w-full overflow-hidden', !context.camera.data && !context.camera.error && !context.camera.loading
|
|
161
|
+
? 'block'
|
|
162
|
+
: 'hidden'), children: [_jsx("video", { ...context.camera.videoProps }), _jsx("svg", { className: "pointer-events-none absolute -inset-4 size-[200%]", children: _jsx("defs", { children: _jsxs("mask", { id: id, maskUnits: "userSpaceOnUse", children: [_jsx("rect", { x: "0", y: "0", width: "200%", height: "200%", fill: "white" }), _jsx("rect", { x: maskBox.x, y: maskBox.y, width: maskBox.width, height: maskBox.height, fill: "black", rx: "8", ry: "8" })] }) }) }), _jsx("div", { ref: context.maskRef, className: "absolute -inset-4 size-[200%] bg-black/60 backdrop-blur-sm", style: {
|
|
163
|
+
mask: `url(#${id})`,
|
|
164
|
+
WebkitMask: `url(#${id})`,
|
|
165
|
+
maskRepeat: 'no-repeat',
|
|
166
|
+
WebkitMaskRepeat: 'no-repeat',
|
|
167
|
+
} }), _jsx("div", { ref: context.guideRef, className: twMerge('border-utility-warning-700 absolute left-1/2 top-1/2 z-20 aspect-square -translate-x-1/2 -translate-y-1/2 rounded-md border-4 border-dashed', context.faceFound && 'border-utility-success-700', guideWidth <= 0 ? 'hidden' : 'block'), style: {
|
|
168
|
+
width: `calc(${guideWidth}px - 2rem)`,
|
|
169
|
+
} })] }));
|
|
170
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
+
import dynamic from 'next/dynamic';
|
|
4
|
+
import { Spinner02Icon } from '../../../icons/Spinner02Icon.js';
|
|
5
|
+
const Component = dynamic(() => import('./SelfieImageField.client.js').then((mod) => mod.SelfieImageField__client), {
|
|
6
|
+
ssr: false,
|
|
7
|
+
loading: () => (_jsx("div", { className: "border-border-primary bg-bg-primary flex aspect-[352/180] w-full shrink-0 items-center justify-center rounded-xl border", children: _jsx(Spinner02Icon, { className: "text-text-quinary size-8" }) })),
|
|
8
|
+
});
|
|
9
|
+
export function SelfieImageField(props) {
|
|
10
|
+
return _jsx(Component, { ...props });
|
|
11
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { UseSelfieImageFieldReturn } from './useSelfieImageField';
|
|
2
|
+
export declare const SelfieImageFieldProvider: (props: {
|
|
3
|
+
value: UseSelfieImageFieldReturn;
|
|
4
|
+
} & {
|
|
5
|
+
children?: import("react").ReactNode | undefined;
|
|
6
|
+
}) => React.ReactNode, useSelfieImageFieldContext: () => UseSelfieImageFieldReturn;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './SelfieImageField';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './SelfieImageField.js';
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export interface UseSelfieImageFieldProps {
|
|
2
|
+
value?: string;
|
|
3
|
+
onChange?: (value: string) => void;
|
|
4
|
+
defaultValue?: string;
|
|
5
|
+
}
|
|
6
|
+
export interface UseSelfieImageFieldReturn extends ReturnType<typeof useSelfieImageField> {
|
|
7
|
+
}
|
|
8
|
+
export declare function useSelfieImageField(props: UseSelfieImageFieldProps): {
|
|
9
|
+
field: import("@ark-ui/react").UseFieldContext;
|
|
10
|
+
value: string;
|
|
11
|
+
setValue: import("react").Dispatch<import("react").SetStateAction<string>>;
|
|
12
|
+
query: import("@tanstack/react-query").UseQueryResult<import("../../../types").File | null, Error>;
|
|
13
|
+
mutation: import("@tanstack/react-query").UseMutationResult<string, Error, {
|
|
14
|
+
file: globalThis.File;
|
|
15
|
+
id?: string | undefined;
|
|
16
|
+
}, unknown>;
|
|
17
|
+
camera: import("../../../client/hooks/useCamera").UseCameraReturn<"FaceNotFoundError">;
|
|
18
|
+
disclosure: import("../../../client/hooks/useDisclosure").UseDisclosureReturn;
|
|
19
|
+
inputRef: import("react").RefObject<HTMLInputElement | null>;
|
|
20
|
+
guideRef: import("react").RefObject<HTMLDivElement | null>;
|
|
21
|
+
maskRef: import("react").RefObject<HTMLDivElement | null>;
|
|
22
|
+
faceFound: boolean;
|
|
23
|
+
};
|
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
import { useFieldContext } from '@ark-ui/react';
|
|
2
|
+
import { FaceDetector, FilesetResolver } from '@mediapipe/tasks-vision';
|
|
3
|
+
import { useRef, useState } from 'react';
|
|
4
|
+
import invariant from 'tiny-invariant';
|
|
5
|
+
import { useInterval } from 'usehooks-ts';
|
|
6
|
+
import { useCamera } from '../../../client/hooks/useCamera.js';
|
|
7
|
+
import { useControllableState } from '../../../client/hooks/useControllableState.js';
|
|
8
|
+
import { useDisclosure } from '../../../client/hooks/useDisclosure.js';
|
|
9
|
+
import { useFileQuery } from '../../../client/hooks/useFileQuery.js';
|
|
10
|
+
import { useUploadPrivateImageFileMutation } from '../../../client/hooks/useUploadPrivateImageFileMutation.js';
|
|
11
|
+
import { toaster } from '../../../client/utils/toaster.js';
|
|
12
|
+
export function useSelfieImageField(props) {
|
|
13
|
+
const field = useFieldContext();
|
|
14
|
+
const [value, setValue] = useControllableState({
|
|
15
|
+
value: props.value,
|
|
16
|
+
defaultValue: props.defaultValue ?? '',
|
|
17
|
+
onChange: props.onChange,
|
|
18
|
+
});
|
|
19
|
+
const query = useFileQuery(value, {
|
|
20
|
+
refetchInterval({ state }) {
|
|
21
|
+
return !state.data || state.data.status === 'UPLOADING' ? 1000 : false;
|
|
22
|
+
},
|
|
23
|
+
});
|
|
24
|
+
const mutation = useUploadPrivateImageFileMutation({
|
|
25
|
+
onSuccess(id) {
|
|
26
|
+
setValue(id);
|
|
27
|
+
},
|
|
28
|
+
onMutate() {
|
|
29
|
+
setValue('');
|
|
30
|
+
},
|
|
31
|
+
onError(error) {
|
|
32
|
+
toaster.error({
|
|
33
|
+
title: 'Upload Failed',
|
|
34
|
+
description: error.message,
|
|
35
|
+
});
|
|
36
|
+
},
|
|
37
|
+
onSettled() {
|
|
38
|
+
if (inputRef.current) {
|
|
39
|
+
inputRef.current.value = '';
|
|
40
|
+
}
|
|
41
|
+
},
|
|
42
|
+
});
|
|
43
|
+
const inputRef = useRef(null);
|
|
44
|
+
const maskRef = useRef(null);
|
|
45
|
+
const guideRef = useRef(null);
|
|
46
|
+
const camera = useCamera({
|
|
47
|
+
async transform(ctx) {
|
|
48
|
+
const hasFace = await validateFaceFromImage(ctx.image);
|
|
49
|
+
if (!hasFace) {
|
|
50
|
+
return {
|
|
51
|
+
ok: false,
|
|
52
|
+
error: {
|
|
53
|
+
name: 'FaceNotFoundError',
|
|
54
|
+
message: 'No face detected in the image. Please try again.',
|
|
55
|
+
},
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
const body = new FormData();
|
|
59
|
+
const guideRect = guideRef.current?.getBoundingClientRect();
|
|
60
|
+
const videoRect = ctx.video.getBoundingClientRect();
|
|
61
|
+
invariant(guideRect, "'guideRef.getBoundingClientRect()' fails");
|
|
62
|
+
const scaleX = ctx.image.width / videoRect.width;
|
|
63
|
+
const scaleY = ctx.image.height / videoRect.height;
|
|
64
|
+
const cropTop = (guideRect.top - videoRect.top) * scaleY;
|
|
65
|
+
const cropLeft = (guideRect.left - videoRect.left) * scaleX;
|
|
66
|
+
const cropWidth = guideRect.width * scaleX;
|
|
67
|
+
const cropHeight = guideRect.height * scaleY;
|
|
68
|
+
body.append('image', ctx.file);
|
|
69
|
+
body.append('cropTop', cropTop.toString());
|
|
70
|
+
body.append('cropLeft', cropLeft.toString());
|
|
71
|
+
body.append('cropWidth', cropWidth.toString());
|
|
72
|
+
body.append('cropHeight', cropHeight.toString());
|
|
73
|
+
const response = await fetch('/api/transformers/selfie-image', {
|
|
74
|
+
method: 'POST',
|
|
75
|
+
body,
|
|
76
|
+
});
|
|
77
|
+
const blob = await response.blob();
|
|
78
|
+
const file = new File([blob], ctx.file.name, {
|
|
79
|
+
type: ctx.file.type,
|
|
80
|
+
endings: 'native',
|
|
81
|
+
lastModified: Date.now(),
|
|
82
|
+
});
|
|
83
|
+
const url = URL.createObjectURL(file);
|
|
84
|
+
const image = new Image();
|
|
85
|
+
image.src = url;
|
|
86
|
+
image.alt = '';
|
|
87
|
+
image.width = ctx.image.width;
|
|
88
|
+
image.height = ctx.image.height;
|
|
89
|
+
return {
|
|
90
|
+
ok: true,
|
|
91
|
+
data: {
|
|
92
|
+
url,
|
|
93
|
+
file,
|
|
94
|
+
image,
|
|
95
|
+
},
|
|
96
|
+
};
|
|
97
|
+
},
|
|
98
|
+
});
|
|
99
|
+
const disclosure = useDisclosure({
|
|
100
|
+
onOpenChange(open) {
|
|
101
|
+
if (open) {
|
|
102
|
+
camera.open();
|
|
103
|
+
}
|
|
104
|
+
},
|
|
105
|
+
});
|
|
106
|
+
const [faceFound, setFaceFound] = useState(false);
|
|
107
|
+
useInterval(async () => {
|
|
108
|
+
if (!camera.videoRef.current || !guideRef.current) {
|
|
109
|
+
return setFaceFound(false);
|
|
110
|
+
}
|
|
111
|
+
setFaceFound(await validateFaceFromVideo(camera.videoRef.current, guideRef.current));
|
|
112
|
+
}, disclosure.open && !camera.data && !camera.error && !camera.loading
|
|
113
|
+
? 1000
|
|
114
|
+
: null);
|
|
115
|
+
return {
|
|
116
|
+
field,
|
|
117
|
+
value,
|
|
118
|
+
setValue,
|
|
119
|
+
query,
|
|
120
|
+
mutation,
|
|
121
|
+
camera,
|
|
122
|
+
disclosure,
|
|
123
|
+
inputRef,
|
|
124
|
+
guideRef,
|
|
125
|
+
maskRef,
|
|
126
|
+
faceFound,
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
let __image_face_detector__;
|
|
130
|
+
let __video_face_detector__;
|
|
131
|
+
/* eslint-disable-next-line @typescript-eslint/no-explicit-any */
|
|
132
|
+
let __vision__;
|
|
133
|
+
async function getImageFaceDetector() {
|
|
134
|
+
if (!__image_face_detector__) {
|
|
135
|
+
if (!__vision__) {
|
|
136
|
+
__vision__ = await FilesetResolver.forVisionTasks('https://cdn.jsdelivr.net/npm/@mediapipe/tasks-vision@0.10.0/wasm');
|
|
137
|
+
}
|
|
138
|
+
const detector = await FaceDetector.createFromOptions(__vision__, {
|
|
139
|
+
runningMode: 'IMAGE',
|
|
140
|
+
minDetectionConfidence: 0.75,
|
|
141
|
+
baseOptions: {
|
|
142
|
+
delegate: 'GPU',
|
|
143
|
+
modelAssetPath: 'https://storage.googleapis.com/mediapipe-models/face_detector/blaze_face_short_range/float16/1/blaze_face_short_range.tflite',
|
|
144
|
+
},
|
|
145
|
+
});
|
|
146
|
+
__image_face_detector__ = detector;
|
|
147
|
+
return detector;
|
|
148
|
+
}
|
|
149
|
+
return __image_face_detector__;
|
|
150
|
+
}
|
|
151
|
+
async function getVideoFaceDetector() {
|
|
152
|
+
if (!__video_face_detector__) {
|
|
153
|
+
if (!__vision__) {
|
|
154
|
+
__vision__ = await FilesetResolver.forVisionTasks('https://cdn.jsdelivr.net/npm/@mediapipe/tasks-vision@0.10.0/wasm');
|
|
155
|
+
}
|
|
156
|
+
const detector = await FaceDetector.createFromOptions(__vision__, {
|
|
157
|
+
runningMode: 'VIDEO',
|
|
158
|
+
minDetectionConfidence: 0.75,
|
|
159
|
+
baseOptions: {
|
|
160
|
+
delegate: 'GPU',
|
|
161
|
+
modelAssetPath: 'https://storage.googleapis.com/mediapipe-models/face_detector/blaze_face_short_range/float16/1/blaze_face_short_range.tflite',
|
|
162
|
+
},
|
|
163
|
+
});
|
|
164
|
+
__video_face_detector__ = detector;
|
|
165
|
+
return detector;
|
|
166
|
+
}
|
|
167
|
+
return __video_face_detector__;
|
|
168
|
+
}
|
|
169
|
+
async function validateFaceFromImage(image) {
|
|
170
|
+
const detector = await getImageFaceDetector();
|
|
171
|
+
try {
|
|
172
|
+
const result = detector.detect(image);
|
|
173
|
+
return result.detections.length > 0;
|
|
174
|
+
}
|
|
175
|
+
catch (e) {
|
|
176
|
+
console.error(e);
|
|
177
|
+
return false;
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
async function validateFaceFromVideo(video, guide) {
|
|
181
|
+
if (video.readyState < 2)
|
|
182
|
+
return false;
|
|
183
|
+
const detector = await getVideoFaceDetector();
|
|
184
|
+
const result = detector.detectForVideo(video, performance.now());
|
|
185
|
+
const detection = result.detections.at(0);
|
|
186
|
+
if (!detection)
|
|
187
|
+
return false;
|
|
188
|
+
const category = detection.categories.at(0);
|
|
189
|
+
if (!category || category.score < 0.75)
|
|
190
|
+
return false;
|
|
191
|
+
const videoRect = video.getBoundingClientRect(); // DOM position & size
|
|
192
|
+
const guideRect = guide.getBoundingClientRect();
|
|
193
|
+
if (!detection.boundingBox)
|
|
194
|
+
return false;
|
|
195
|
+
const faceLeft = videoRect.left +
|
|
196
|
+
(detection.boundingBox.originX / video.videoWidth) * videoRect.width;
|
|
197
|
+
const faceTop = videoRect.top +
|
|
198
|
+
(detection.boundingBox.originY / video.videoHeight) * videoRect.height;
|
|
199
|
+
const faceRight = faceLeft +
|
|
200
|
+
(detection.boundingBox.width / video.videoWidth) * videoRect.width;
|
|
201
|
+
const faceBottom = faceTop +
|
|
202
|
+
(detection.boundingBox.height / video.videoHeight) * videoRect.height;
|
|
203
|
+
const isInside = faceLeft >= guideRect.left &&
|
|
204
|
+
faceTop >= guideRect.top &&
|
|
205
|
+
faceRight <= guideRect.right &&
|
|
206
|
+
faceBottom <= guideRect.bottom;
|
|
207
|
+
return isInside;
|
|
208
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { NextResponse } from 'next/server';
|
|
2
|
+
import { ACCESS_TOKEN_COOKIE_NAME, REFRESH_TOKEN_COOKIE_NAME, } from '../constants/index.js';
|
|
3
|
+
import { destroySession } from '../services/auth.js';
|
|
4
|
+
export async function deleteSession(request) {
|
|
5
|
+
const accessToken = request.cookies.get(ACCESS_TOKEN_COOKIE_NAME)?.value;
|
|
6
|
+
if (accessToken) {
|
|
7
|
+
await destroySession({
|
|
8
|
+
headers: {
|
|
9
|
+
Authorization: `Bearer ${accessToken}`,
|
|
10
|
+
},
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
const response = NextResponse.json({
|
|
14
|
+
ok: true,
|
|
15
|
+
});
|
|
16
|
+
response.cookies.delete(ACCESS_TOKEN_COOKIE_NAME);
|
|
17
|
+
response.cookies.delete(REFRESH_TOKEN_COOKIE_NAME);
|
|
18
|
+
return response;
|
|
19
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { NextResponse } from 'next/server';
|
|
2
|
+
export async function getHealthCheck(req) {
|
|
3
|
+
return NextResponse.json({
|
|
4
|
+
ok: true,
|
|
5
|
+
data: {
|
|
6
|
+
userAgent: req.headers.get('user-agent') ?? 'UNKNOWN',
|
|
7
|
+
},
|
|
8
|
+
}, {
|
|
9
|
+
headers: {
|
|
10
|
+
'Access-Control-Allow-Origin': '*',
|
|
11
|
+
'Cache-Control': 'no-cache, no-store, must-revalidate',
|
|
12
|
+
Pragma: 'no-cache',
|
|
13
|
+
Expires: '0',
|
|
14
|
+
},
|
|
15
|
+
});
|
|
16
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { NextResponse, type NextRequest } from 'next/server';
|
|
2
|
+
import type { Session } from '../types';
|
|
3
|
+
export declare function getSession(request: NextRequest): Promise<NextResponse<{
|
|
4
|
+
ok: false;
|
|
5
|
+
message: string;
|
|
6
|
+
__error?: unknown;
|
|
7
|
+
} | {
|
|
8
|
+
ok: true;
|
|
9
|
+
data: Session;
|
|
10
|
+
}>>;
|