feat: fix faceId loop error caused by async (#3651)

This commit is contained in:
DacongDA 2025-03-11 21:03:04 +08:00 committed by GitHub
parent 9610ce5b8c
commit 30789138e2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -289,20 +289,20 @@ const FaceRecognitionModal = (props) => {
<p>{i18next.t("general:Click to Upload")}</p>
</Dragger >
{
modelsLoaded ? <Button style={{width: "100%"}} onClick={() => {
modelsLoaded ? <Button style={{width: "100%"}} onClick={async() => {
let maxScore = 0;
files.forEach((file, fileIndex) => {
for (const file of files) {
const fileIndex = files.indexOf(file);
const img = new Image();
img.src = file.base64;
faceapi.detectAllFaces(img, new faceapi.TinyFaceDetectorOptions()).withFaceLandmarks().withFaceDescriptors().then(res2 => {
if (res2[0]?.detection.score > 0.9 && res2[0]?.detection.score > maxScore) {
maxScore = res2[0]?.detection.score;
setCurrentFaceId(res2[0]);
const faceIds = await faceapi.detectAllFaces(img, new faceapi.TinyFaceDetectorOptions()).withFaceLandmarks().withFaceDescriptors();
if (faceIds[0]?.detection.score > 0.9 && faceIds[0]?.detection.score > maxScore) {
maxScore = faceIds[0]?.detection.score;
setCurrentFaceId(faceIds[0]);
setCurrentFaceIndex(fileIndex);
}
});
});
if (currentFaceId?.length === 0) {
}
if (maxScore < 0.9) {
message.error(i18next.t("login:Face recognition failed"));
}
}}> {i18next.t("application:Generate faceId")}</Button> : null