diff --git a/backend/src/router.py b/backend/src/router.py index 27062009..1376540f 100644 --- a/backend/src/router.py +++ b/backend/src/router.py @@ -139,34 +139,6 @@ async def imageupload( logging.exception(e, extra=extras_logging) raise HTTPException(status_code=500, detail=str(e)) -@router.post("/identification-blank-gun") -async def imageblankgun( - image: UploadFile = File(...), -): - try: - img_bytes = image.file.read() - # Process image with ML models - alarm_model = is_alarm_weapon(img_bytes) - return { - "alarm_model": alarm_model, - "missing_text": False, - "low_quality": False, - } - - except LowQuality: - return { - "alarm_model": None, - "low_quality": True, - "missing_text": False, - } - except MissingText: - return { - "alarm_model": None, - "low_quality": False, - "missing_text": True, - } - except Exception as e: - raise HTTPException(status_code=500, detail=str(e)) @router.post("/identification-feedback") async def log_feedback(request: Request, user_id: Union[str, None] = Cookie(None)): diff --git a/frontend/cypress/e2e/blank-gun-detection.cy.js b/frontend/cypress/e2e/blank-gun-detection.cy.js new file mode 100644 index 00000000..f1d9f77e --- /dev/null +++ b/frontend/cypress/e2e/blank-gun-detection.cy.js @@ -0,0 +1,55 @@ +describe("Blank Gun Detection", () => { + it("should identificate real blank gun", () => { + cy.Identification(); + cy.getByDataTestid("select-file").as("fileInput"); + cy.intercept("POST", "/api/upload").as("upload"); + cy.get("@fileInput").selectFile("./cypress/images/blank-gun.jpg", { + force: true, + }); + cy.wait("@upload").then(({ response }) => { + expect(response.statusCode).to.eq(200); + }); + cy.wait(1000); + cy.getByDataTestid("next-step").click(); + cy.IdentificationPistoletOCR("Identification d'une arme d'alarme"); + cy.wait(5000); + cy.url().should("contain", "/guide-identification/resultat-final"); + cy.getByDataTestid("arm-category").should("contain", "Catégorie C"); + }); + + it("should identificate firearm with missing text", () => { + cy.Identification(); + cy.getByDataTestid("select-file").as("fileInput"); + cy.intercept("POST", "/api/upload").as("upload"); + cy.get("@fileInput").selectFile("./cypress/images/no-text.jpg", { + force: true, + }); + cy.wait("@upload").then(({ response }) => { + expect(response.statusCode).to.eq(200); + }); + cy.wait(1000); + cy.getByDataTestid("next-step").click(); + cy.IdentificationPistoletOCR("Marquages non détectés"); + cy.get('.fr-col-12 > [data-testid="next-step"]').click(); + cy.url().should("contain", "/guide-identification/resultat-final"); + cy.getByDataTestid("arm-category").should("contain", "Catégorie B"); + }); + + it("should identificate firearm with low quality", () => { + cy.Identification(); + cy.getByDataTestid("select-file").as("fileInput"); + cy.intercept("POST", "/api/upload").as("upload"); + cy.get("@fileInput").selectFile("./cypress/images/low-quality.jpg", { + force: true, + }); + cy.wait("@upload").then(({ response }) => { + expect(response.statusCode).to.eq(200); + }); + cy.wait(1000); + cy.getByDataTestid("next-step").click(); + cy.IdentificationPistoletOCR("Qualité d'image insuffisante"); + cy.get('.fr-col-12 > [data-testid="next-step"]').click(); + cy.url().should("contain", "/guide-identification/resultat-final"); + cy.getByDataTestid("arm-category").should("contain", "Catégorie B"); + }); +}); diff --git a/frontend/cypress/e2e/firearm-confidence.cy.js b/frontend/cypress/e2e/firearm-confidence.cy.js index f84e8222..23408247 100644 --- a/frontend/cypress/e2e/firearm-confidence.cy.js +++ b/frontend/cypress/e2e/firearm-confidence.cy.js @@ -1,7 +1,6 @@ describe("Firearm Confidence", () => { - it("should identificate firearm with high confidence", () => { + it.only("should identificate firearm with high confidence", () => { cy.Identification(); - cy.getByDataTestid("select-file").as("fileInput"); cy.intercept("POST", "/api/upload").as("upload"); cy.get("@fileInput").selectFile("./cypress/images/pistolet-semi-auto.jpg", { diff --git a/frontend/cypress/e2e/firearm-identification.cy.js b/frontend/cypress/e2e/firearm-identification.cy.js index 1b2ecc93..838ca590 100644 --- a/frontend/cypress/e2e/firearm-identification.cy.js +++ b/frontend/cypress/e2e/firearm-identification.cy.js @@ -11,6 +11,7 @@ describe("Firearm Identification", () => { }); cy.getByDataTestid("next-step").click(); cy.IdentificationPistoletSemiAuto(); + cy.wait(5000); cy.url().should("contain", "/guide-identification/resultat-final"); cy.getByDataTestid("arm-category").should("contain", "Catégorie B"); cy.getByDataTestid("return-to-home-end").click(); diff --git a/frontend/cypress/e2e/firearm-securing.cy.js b/frontend/cypress/e2e/firearm-securing.cy.js index bf3888ba..fb5538af 100644 --- a/frontend/cypress/e2e/firearm-securing.cy.js +++ b/frontend/cypress/e2e/firearm-securing.cy.js @@ -26,6 +26,7 @@ describe("Securing Firearm and Identification", () => { cy.contains("p", "Basegun a identifié votre arme"); cy.getByDataTestid("next-step").click(); cy.IdentificationPistoletSemiAuto(); + cy.wait(5000); cy.url().should("contain", "/guide-identification/resultat-final"); cy.getByDataTestid("arm-category").should("contain", "Catégorie B"); cy.getByDataTestid("return-to-home-end").click(); diff --git a/frontend/cypress/e2e/typology-revolver-identification.cy.js b/frontend/cypress/e2e/typology-revolver-identification.cy.js index 9e195b1f..d0d9d292 100644 --- a/frontend/cypress/e2e/typology-revolver-identification.cy.js +++ b/frontend/cypress/e2e/typology-revolver-identification.cy.js @@ -9,6 +9,7 @@ describe("Typology Revolver Identification", () => { cy.wait("@upload").then(({ response }) => { expect(response.statusCode).to.eq(200); }); + cy.wait(1000); cy.IdentificationRevolver(); cy.url().should("contain", "/guide-identification/resultat-final"); cy.getByDataTestid("arm-category").should("contain", "Catégorie B ou D"); diff --git a/frontend/cypress/images/blank-gun.jpg b/frontend/cypress/images/blank-gun.jpg new file mode 100755 index 00000000..936f38fc Binary files /dev/null and b/frontend/cypress/images/blank-gun.jpg differ diff --git a/frontend/cypress/images/low-quality.jpg b/frontend/cypress/images/low-quality.jpg new file mode 100644 index 00000000..6682df31 Binary files /dev/null and b/frontend/cypress/images/low-quality.jpg differ diff --git a/frontend/cypress/images/no-text.jpg b/frontend/cypress/images/no-text.jpg new file mode 100644 index 00000000..d11abd33 Binary files /dev/null and b/frontend/cypress/images/no-text.jpg differ diff --git a/frontend/cypress/images/pistolet-semi-auto.jpg b/frontend/cypress/images/pistolet-semi-auto.jpg old mode 100644 new mode 100755 index 5d95b0a4..4d76f304 Binary files a/frontend/cypress/images/pistolet-semi-auto.jpg and b/frontend/cypress/images/pistolet-semi-auto.jpg differ diff --git a/frontend/cypress/support/commands.js b/frontend/cypress/support/commands.js index f35f5d0b..60b68302 100644 --- a/frontend/cypress/support/commands.js +++ b/frontend/cypress/support/commands.js @@ -109,11 +109,6 @@ Cypress.Commands.add("IdentificationPistoletSemiAuto", () => { cy.contains("Cartouches").first().click(); cy.getByDataTestid("next-step").should("not.have.attr", "disabled"); cy.getByDataTestid("next-step").click(); - cy.url().should("contain", "/guide-identification/armes-alarme"); - cy.getByDataTestid("instruction-armeAlarme").should("contain", "Votre arme"); - cy.getByDataTestid("next-step").click(); - cy.getByDataTestid("aucune-correspondance").click(); - cy.getByDataTestid("next-step").click(); }); Cypress.Commands.add("IdentificationRevolver", () => { @@ -133,11 +128,8 @@ Cypress.Commands.add("IdentificationRevolver", () => { cy.contains("Balles").first().click(); cy.getByDataTestid("next-step").should("not.have.attr", "disabled"); cy.getByDataTestid("next-step").click(); - cy.url().should("contain", "/guide-identification/armes-alarme"); - cy.getByDataTestid("instruction-armeAlarme").should("contain", "Votre arme"); - cy.getByDataTestid("next-step").click(); - cy.getByDataTestid("aucune-correspondance").click(); - cy.getByDataTestid("next-step").click(); + cy.getByDataTestid("title-page").should("contain", "Marquages non détectés"); + cy.get('.fr-col-12 > [data-testid="next-step"]').click(); }); Cypress.Commands.add("arrierePlatRevolver", () => { @@ -251,6 +243,21 @@ Cypress.Commands.add("IdentificationShotgun", (typeOfMunition) => { cy.getByDataTestid("next-step").click(); }); +Cypress.Commands.add("IdentificationPistoletOCR", (header) => { + cy.url().should( + "contain", + "guide-identification/informations-complementaires", + ); + cy.getByDataTestid("next-step").click(); + cy.url().should("contain", "/guide-identification/munition-type"); + cy.getByDataTestid("next-step").should("have.attr", "disabled"); + cy.contains("Cartouches").first().click(); + cy.getByDataTestid("next-step").should("not.have.attr", "disabled"); + cy.getByDataTestid("next-step").click(); + cy.url().should("contain", "/guide-identification/armes-alarme"); + cy.getByDataTestid("title-page").should("contain", `${header}`); +}); + Cypress.Commands.add("ExpertContactPath", () => { cy.visit("/accueil", { onBeforeLoad: (win) => { diff --git a/frontend/src/api/api-client.ts b/frontend/src/api/api-client.ts index d9952014..5e865a3e 100644 --- a/frontend/src/api/api-client.ts +++ b/frontend/src/api/api-client.ts @@ -7,6 +7,7 @@ import { TUTORIAL_FEEDBACK_ROUTE, UPLOAD_PHOTO_FOR_DETECTION_ROUTE, GET_IRCGN_NUMBERS_ROUTE, + UPLOAD_PHOTO_FOR_ALARM_GUN_DETECTION, } from "./api-routes"; export const uploadPhotoForDetection = async (file: File) => { @@ -55,3 +56,11 @@ export const getContactDetails = async (accessToken: string) => { }, }); }; + +export const uploadPhotoForAlarmGunDetection = async (file: File) => { + const fd = new FormData(); + fd.append("image", file, file.name); + + const { data } = await axios.post(UPLOAD_PHOTO_FOR_ALARM_GUN_DETECTION, fd); + return data; +}; diff --git a/frontend/src/api/api-routes.ts b/frontend/src/api/api-routes.ts index 9d9eb42f..9854c660 100644 --- a/frontend/src/api/api-routes.ts +++ b/frontend/src/api/api-routes.ts @@ -4,3 +4,4 @@ export const IDENTIFICATION_FEEDBACK_ROUTE = "/identification-feedback"; export const IDENTIFICATION_DUMMY_ROUTE = "/identification-dummy"; export const ASK_FOR_OPINION_ROUTE = "/expert-contact"; export const GET_IRCGN_NUMBERS_ROUTE = "/contact-details"; +export const UPLOAD_PHOTO_FOR_ALARM_GUN_DETECTION = "/identification-alarm-gun"; diff --git a/frontend/src/assets/markings.png b/frontend/src/assets/markings.png new file mode 100644 index 00000000..25a19950 Binary files /dev/null and b/frontend/src/assets/markings.png differ diff --git a/frontend/src/assets/missing_marking.png b/frontend/src/assets/missing_marking.png deleted file mode 100644 index df6c4ab6..00000000 Binary files a/frontend/src/assets/missing_marking.png and /dev/null differ diff --git a/frontend/src/assets/missing_markings.png b/frontend/src/assets/missing_markings.png new file mode 100644 index 00000000..372c54a2 Binary files /dev/null and b/frontend/src/assets/missing_markings.png differ diff --git a/frontend/src/components.d.ts b/frontend/src/components.d.ts index e7c77bfa..2728f735 100644 --- a/frontend/src/components.d.ts +++ b/frontend/src/components.d.ts @@ -1,40 +1,40 @@ /* eslint-disable */ -/* prettier-ignore */ // @ts-nocheck // Generated by unplugin-vue-components // Read more: https://github.com/vuejs/core/pull/3399 -export {} +export {}; -declare module "vue" { +/* prettier-ignore */ +declare module 'vue' { export interface GlobalComponents { - AskingExpert: (typeof import("./components/AskingExpert.vue"))["default"]; - AuthCallback: (typeof import("./components/authentication/AuthCallback.vue"))["default"]; - AuthRedirect: (typeof import("./components/authentication/AuthRedirect.vue"))["default"]; - ContactExpert: (typeof import("./components/ContactExpert.vue"))["default"]; - copy: (typeof import("./components/authentification/AuthRedirect copy.vue"))["default"]; - DsfrAlert: (typeof import("@gouvminint/vue-dsfr"))["DsfrAlert"]; - DsfrButton: (typeof import("@gouvminint/vue-dsfr"))["DsfrButton"]; - DsfrCheckbox: (typeof import("@gouvminint/vue-dsfr"))["DsfrCheckbox"]; - DsfrFileUpload: (typeof import("@gouvminint/vue-dsfr"))["DsfrFileUpload"]; - DsfrHeader: (typeof import("@gouvminint/vue-dsfr"))["DsfrHeader"]; - DsfrInput: (typeof import("@gouvminint/vue-dsfr"))["DsfrInput"]; - DsfrModal: (typeof import("@gouvminint/vue-dsfr"))["DsfrModal"]; - DsfrPicture: (typeof import("@gouvminint/vue-dsfr"))["DsfrPicture"]; - DsfrRadioButton: (typeof import("@gouvminint/vue-dsfr"))["DsfrRadioButton"]; - DsfrRadioButtonSet: (typeof import("@gouvminint/vue-dsfr"))["DsfrRadioButtonSet"]; - DsfrSelect: (typeof import("@gouvminint/vue-dsfr"))["DsfrSelect"]; - DsfrTag: (typeof import("@gouvminint/vue-dsfr"))["DsfrTag"]; - HeaderMain: (typeof import("./components/HeaderMain.vue"))["default"]; - MissingCardAlert: (typeof import("./components/MissingCardAlert.vue"))["default"]; - OnboardingSwiper: (typeof import("./components/OnboardingSwiper.vue"))["default"]; - PopupContact: (typeof import("./components/PopupContact.vue"))["default"]; - PopupVideo: (typeof import("./components/PopupVideo.vue"))["default"]; - ResultPage: (typeof import("./components/ResultPage.vue"))["default"]; - RouterLink: (typeof import("vue-router"))["RouterLink"]; - RouterView: (typeof import("vue-router"))["RouterView"]; - SnackbarAlert: (typeof import("./components/SnackbarAlert.vue"))["default"]; - StepsGuide: (typeof import("./components/StepsGuide.vue"))["default"]; - User: (typeof import("./components/authentication/User.vue"))["default"]; - VIcon: (typeof import("@gouvminint/vue-dsfr"))["VIcon"]; + AskingExpert: typeof import('./components/AskingExpert.vue')['default'] + AuthCallback: (typeof import("./components/authentication/AuthCallback.vue"))["default"] + AuthRedirect: (typeof import("./components/authentication/AuthRedirect.vue"))["default"] + ContactExpert: typeof import('./components/ContactExpert.vue')['default'] + copy: (typeof import("./components/authentification/AuthRedirect copy.vue"))["default"] + DsfrAlert: typeof import('@gouvminint/vue-dsfr')['DsfrAlert'] + DsfrButton: typeof import('@gouvminint/vue-dsfr')['DsfrButton'] + DsfrCheckbox: typeof import('@gouvminint/vue-dsfr')['DsfrCheckbox'] + DsfrFileUpload: typeof import('@gouvminint/vue-dsfr')['DsfrFileUpload'] + DsfrHeader: typeof import('@gouvminint/vue-dsfr')['DsfrHeader'] + DsfrInput: typeof import('@gouvminint/vue-dsfr')['DsfrInput'] + DsfrModal: typeof import('@gouvminint/vue-dsfr')['DsfrModal'] + DsfrPicture: typeof import('@gouvminint/vue-dsfr')['DsfrPicture'] + DsfrRadioButton: typeof import('@gouvminint/vue-dsfr')['DsfrRadioButton'] + DsfrRadioButtonSet: typeof import('@gouvminint/vue-dsfr')['DsfrRadioButtonSet'] + DsfrSelect: typeof import('@gouvminint/vue-dsfr')['DsfrSelect'] + DsfrTag: typeof import('@gouvminint/vue-dsfr')['DsfrTag'] + HeaderMain: typeof import('./components/HeaderMain.vue')['default'] + MissingCardAlert: typeof import('./components/MissingCardAlert.vue')['default'] + OnboardingSwiper: typeof import('./components/OnboardingSwiper.vue')['default'] + PopupContact: typeof import('./components/PopupContact.vue')['default'] + PopupVideo: typeof import('./components/PopupVideo.vue')['default'] + ResultPage: typeof import('./components/ResultPage.vue')['default'] + RouterLink: typeof import('vue-router')['RouterLink'] + RouterView: typeof import('vue-router')['RouterView'] + SnackbarAlert: typeof import('./components/SnackbarAlert.vue')['default'] + StepsGuide: typeof import('./components/StepsGuide.vue')['default'] + User: (typeof import("./components/authentication/User.vue"))["default"] + VIcon: typeof import('@gouvminint/vue-dsfr')['VIcon'] } } diff --git a/frontend/src/router/index.ts b/frontend/src/router/index.ts index d36b5b25..a0f8eca8 100644 --- a/frontend/src/router/index.ts +++ b/frontend/src/router/index.ts @@ -9,7 +9,7 @@ import { clearLocalStorage } from "@/utils/storage-utils.js"; import { mgr } from "@/utils/authentication"; import MissingCardPage from "@/views/MissingCardPage.vue"; -import IdentificationQualityImage from "@/views/GuideIdentificationFirearm/IdentificationQualityImage.vue"; +import IdentificationAlarmGun from "@/views/GuideIdentificationFirearm/IdentificationAlarmGun.vue"; import ExpertiseForm from "@/views/GuideAskingExpertise/ExpertiseForm.vue"; const HomePage = () => import("@/views/HomePage.vue"); @@ -136,9 +136,9 @@ const routes: RouteRecordRaw[] = [ component: IdentificationSelectAmmo, }, { - path: "qualite-image", - name: "IdentificationQualityImage", - component: IdentificationQualityImage, + path: "armes-alarme", + name: "IdentificationAlarmGun", + component: IdentificationAlarmGun, }, { path: "resultat-final", @@ -263,7 +263,7 @@ const routes: RouteRecordRaw[] = [ } } catch (error) { console.error("Erreur signin callback:", error); - next({ name: "ErrorPage" }); + next({ name: "AuthRedirect" }); } }, }, diff --git a/frontend/src/stores/result.ts b/frontend/src/stores/result.ts index 7d18c2b3..eccaea91 100644 --- a/frontend/src/stores/result.ts +++ b/frontend/src/stores/result.ts @@ -10,15 +10,12 @@ export const useStore = defineStore("result", { const gunBarrelLength = ref(null); const img = ref(null); const imgUrl = ref(null); - const unresizeImage = ref(null); const securingTutorial = ref(false); const selectedOptions = ref([]); const selectedAmmo = ref(undefined); - const selectedAlarmGun = ref(undefined); - const alarmModel = ref(null); - const isAlarmGunMissingText = ref(null); - const isAlarmGunLowQuality = ref(null); + const isAlarmGun = ref(false); + const alarmGunException = ref(undefined); const isDummy = computed(() => !!(selectedAmmo.value === "billes")); const isModalTransparentAmmoOpened = ref(null); @@ -30,15 +27,12 @@ export const useStore = defineStore("result", { gunBarrelLength.value = null; img.value = null; imgUrl.value = null; - unresizeImage.value = null; securingTutorial.value = false; selectedOptions.value = []; selectedAmmo.value = undefined; - selectedAlarmGun.value = undefined; - alarmModel.value = null; - isAlarmGunMissingText.value = null; - isAlarmGunLowQuality.value = null; + isAlarmGun.value = false; + alarmGunException.value = undefined; isModalTransparentAmmoOpened.value = null; } @@ -50,14 +44,11 @@ export const useStore = defineStore("result", { gunBarrelLength, img, imgUrl, - unresizeImage, securingTutorial, selectedOptions, selectedAmmo, - selectedAlarmGun, - alarmModel, - isAlarmGunMissingText, - isAlarmGunLowQuality, + isAlarmGun, + alarmGunException, isDummy, isModalTransparentAmmoOpened, $reset, diff --git a/frontend/src/utils/firearms-utils/index.ts b/frontend/src/utils/firearms-utils/index.ts index 7121afb5..d503f40d 100644 --- a/frontend/src/utils/firearms-utils/index.ts +++ b/frontend/src/utils/firearms-utils/index.ts @@ -34,7 +34,7 @@ export const TYPOLOGIES = { const IdentificationTypologyResult = "IdentificationTypologyResult"; const IdentificationFurtherInformations = "IdentificationFurtherInformations"; const IdentificationSelectAmmo = "IdentificationSelectAmmo"; -const IdentificationQualityImage = "IdentificationQualityImage"; +const IdentificationAlarmGun = "IdentificationAlarmGun"; const IdentificationFinalResult = "IdentificationFinalResult"; export const identificationGuideSteps = [ @@ -48,7 +48,7 @@ export const identificationGuideStepsWithArmeAlarme = [ IdentificationTypologyResult, IdentificationFurtherInformations, IdentificationSelectAmmo, - IdentificationQualityImage, + IdentificationAlarmGun, IdentificationFinalResult, ] as const; @@ -69,7 +69,7 @@ export const identificationRoutePathsWithArmeAlarme = [ "resultat-typologie", "informations-complementaires", "munition-type", - "qualite-image", + "armes-alarme", "resultat-final", ] as const; @@ -81,7 +81,7 @@ export function isAlarmGun() { ) { return false; } - return store.alarmModel === "Alarm_model" ? true : undefined; + return store.isAlarmGun; } export const MEASURED_GUNS_TYPOLOGIES = [ diff --git a/frontend/src/views/GuideIdentificationFirearm/GuideIdentificationFirearm.vue b/frontend/src/views/GuideIdentificationFirearm/GuideIdentificationFirearm.vue index 6fa6c421..c43145d1 100644 --- a/frontend/src/views/GuideIdentificationFirearm/GuideIdentificationFirearm.vue +++ b/frontend/src/views/GuideIdentificationFirearm/GuideIdentificationFirearm.vue @@ -9,7 +9,7 @@ import { isAlarmGun, } from "@/utils/firearms-utils/index"; import { useStore } from "@/stores/result"; -import { uploadPhotoForBlankGunDetection } from "@/api/api-client"; +import { uploadPhotoForAlarmGunDetection } from "@/api/api-client"; const store = useStore(); const router = useRouter(); @@ -17,16 +17,19 @@ const route = useRoute(); const confidenceLevel = computed(() => store.confidenceLevel); const typology = computed(() => store.typology); -const alarmModel = computed(() => store.alarmModel); -const isAlarmGunLowQuality = computed(() => store.isAlarmGunLowQuality); -const isAlarmGunMissingText = computed(() => store.isAlarmGunMissingText); +const alarmGunException = computed(() => store.alarmGunException); const currentStep = ref(1); const isLowConfidence = confidenceLevel.value === "low"; const steps = computed(() => { if (TYPOLOGIES[typology]?.dummyOptions || !isLowConfidence) { - if (isAlarmGun() !== false) { + if ( + isAlarmGun() || + (!isAlarmGun() && + alarmGunException.value !== undefined && + store.selectedAmmo !== "billes") + ) { return [ "Typologie de l'arme", "Compléments", @@ -74,48 +77,37 @@ const arrowOrCircleIcon = () => const calculateRoute = (store) => { return store.selectedAmmo === "billes" ? { name: "IdentificationFinalResult" } - : { name: "IdentificationQualityImage" }; + : { name: "IdentificationAlarmGun" }; }; -function handlePreviousButtonClick() { +const handlePreviousButtonClick = () => { currentStep.value--; - if (isAlarmGun() !== false) { + if (isAlarmGun() || (!isAlarmGun() && alarmGunException !== undefined)) { goToNewRouteWithArmeAlarme(); } else { goToNewRoute(); } -} +}; async function onFileSelected(event) { const uploadedFile = event.target.files[0]; - if (!uploadedFile) { - console.error("Aucun fichier sélectionné."); - return; - } - - console.log("Fichier sélectionné :", uploadedFile); - try { - const result = await uploadPhotoForBlankGunDetection(uploadedFile); - console.log("Résultat de l'envoi :", result); + const result = await uploadPhotoForAlarmGunDetection(uploadedFile); if (result) { - const { alarm_model, missing_text, low_quality } = result; - if (alarm_model === "Alarm_model") { - store.$patch({ alarmModel: alarm_model }); - console.log("Modèle d'arme d'alarme détecté :", alarm_model); - - currentStep.value++; - router.push({ name: "IdentificationFinalResult" }); - } else if (low_quality === true) { - store.$patch({ isAlarmGunLowQuality: true }); - } else if (missing_text === true) { - store.$patch({ isAlarmGunMissingText: true }); + const { is_alarm_model, exception } = result; + if (is_alarm_model === true) { + store.$patch({ isAlarmGun: is_alarm_model }); + } else if (exception !== undefined) { + store.$patch({ + isAlarmGun: is_alarm_model, + alarmGunException: exception, + }); } - } else { - console.error("La réponse est indéfinie ou mal formée :", result); } + currentStep.value++; + router.push({ name: "IdentificationFinalResult" }); } catch (error) { console.error("Erreur lors de l'envoi de l'image :", error); } @@ -123,26 +115,37 @@ async function onFileSelected(event) { const handledImageTypes = "image/jpeg, image/png, image/jpg"; -const footerValue = computed(() => { - if (isAlarmGunLowQuality) { +const footerAlarmGun = computed(() => { + if (alarmGunException === "LowQuality") { return { next: "Pas de marquages, passer à l'étape suivante", - picture: "Reprendre la photo", + uploadPicture: "Reprendre la photo", }; } else { return { next: "Non, passer à l'étape suivante", - picture: "Oui, en prendre une photo rapprochée", + uploadPicture: "Oui, en prendre une photo rapprochée", }; } }); -watch(alarmModel, (newVal) => { - if (newVal === "Alarm_model" || newVal === "Not_alarm") { - setTimeout(() => { +let alarmTimeout = ref | null>(null); +const alarmGunMounted = () => { + if ( + isAlarmGun() || + (isAlarmGun() === false && alarmGunException === undefined) + ) { + alarmTimeout = setTimeout(() => { + router.push({ name: "IdentificationFinalResult" }); currentStep.value++; }, 5000); } +}; + +onBeforeUnmount(() => { + if (alarmTimeout) { + clearTimeout(alarmTimeout); + } }); @@ -190,7 +193,7 @@ watch(alarmModel, (newVal) => {