From 1d72732fadf1507b7ea97cbc169a5effeb6b31ee Mon Sep 17 00:00:00 2001 From: Emnaghz Date: Mon, 7 Oct 2024 17:50:46 +0100 Subject: [PATCH] fix: add file type check --- .../app-components/attachment/AttachmentUploader.tsx | 11 +++++++++++ frontend/src/i18n/en/translation.json | 3 ++- frontend/src/i18n/fr/translation.json | 3 ++- 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/frontend/src/app-components/attachment/AttachmentUploader.tsx b/frontend/src/app-components/attachment/AttachmentUploader.tsx index 915ff657..3587367b 100644 --- a/frontend/src/app-components/attachment/AttachmentUploader.tsx +++ b/frontend/src/app-components/attachment/AttachmentUploader.tsx @@ -99,6 +99,17 @@ const AttachmentUploader: FC = ({ const file = event.target.files.item(0); if (file) { + const acceptedTypes = accept.split(','); + const isValidType = acceptedTypes.some((type) => + file.type === type || file.name.endsWith(type.replace('.*', '')) + ); + + if (!isValidType) { + toast.error(t("message.invalid_file_type")); + +return; + } + uploadAttachment(file); } } diff --git a/frontend/src/i18n/en/translation.json b/frontend/src/i18n/en/translation.json index 67c49592..4090c7ce 100644 --- a/frontend/src/i18n/en/translation.json +++ b/frontend/src/i18n/en/translation.json @@ -104,7 +104,8 @@ "title_length_exceeded": "You have reached the maximum length", "no_label_found": "No label found", "code_is_required": "Language code is required", - "text_is_required": "Text is required" + "text_is_required": "Text is required", + "invalid_file_type": "Invalid file type" }, "menu": { "terms": "Terms of Use", diff --git a/frontend/src/i18n/fr/translation.json b/frontend/src/i18n/fr/translation.json index 0c036ac1..a4998a35 100644 --- a/frontend/src/i18n/fr/translation.json +++ b/frontend/src/i18n/fr/translation.json @@ -104,7 +104,8 @@ "title_length_exceeded": "Vous avez atteint la longueur maximale", "no_label_found": "Aucune étiquette trouvée", "code_is_required": "Le code est requis", - "text_is_required": "Texte requis" + "text_is_required": "Texte requis", + "invalid_file_type": "Type de fichier invalide" }, "menu": { "terms": "Conditions d'utilisation",