From 591658ea679005e9f3dcb2501b7c459d40d43ee4 Mon Sep 17 00:00:00 2001 From: visp-odoo Date: Wed, 24 Jan 2024 10:14:08 +0000 Subject: [PATCH] [FIX] web_editor: show toaster notification error on uploading folder Steps to reproduce: OS: Ubuntu 20.04.4 LTS with nautilus Browser: Google Chrome Version 123.0.6312.58 - type /file command in knowledge - select a folder and click on open - traceback occurs Before this commit: When a user attempts to upload a folder using /file command, the processing begins, but the folder is not actually uploaded because the `getDataURLFromFile` return promise which is not fulfiled. Additionally, there is no indication of any warnings or errors during the folder upload process. After this commit: If a user attempts to upload a folder instead of a file using the /file command, it results in a error message in toaster notification. task-3690847 closes odoo/odoo#159755 X-original-commit: 0b27ac02e499bf15d9f011beda17ab202c1f7a42 Signed-off-by: Damien Abeloos (abd) --- addons/web_editor/i18n/web_editor.pot | 6 ++++++ .../upload_progress_toast/upload_service.js | 17 ++++++++++++++++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/addons/web_editor/i18n/web_editor.pot b/addons/web_editor/i18n/web_editor.pot index c9e6e8210c0..bd342dbd46d 100644 --- a/addons/web_editor/i18n/web_editor.pot +++ b/addons/web_editor/i18n/web_editor.pot @@ -871,6 +871,12 @@ msgstr "" msgid "Could not install module %s" msgstr "" +#. module: web_editor +#. odoo-javascript +#: code:addons/web_editor/static/src/components/upload_progress_toast/upload_service.js:0 +#, python-format +msgid "Could not load the file \"%s\"." + #. module: web_editor #: model_terms:ir.ui.view,arch_db:web_editor.snippet_options_background_options msgid "Cover" diff --git a/addons/web_editor/static/src/components/upload_progress_toast/upload_service.js b/addons/web_editor/static/src/components/upload_progress_toast/upload_service.js index 4baa4824ee9..a81d3db3eac 100644 --- a/addons/web_editor/static/src/components/upload_progress_toast/upload_service.js +++ b/addons/web_editor/static/src/components/upload_progress_toast/upload_service.js @@ -2,9 +2,11 @@ import { registry } from '@web/core/registry'; import { UploadProgressToast } from './upload_progress_toast'; +import { _t } from "@web/core/l10n/translation"; import { checkFileSize } from "@web/core/utils/files"; import { humanNumber } from "@web/core/utils/numbers"; import { getDataURLFromFile } from "@web/core/utils/urls"; +import { sprintf } from "@web/core/utils/strings"; import { reactive } from "@odoo/owl"; export const AUTOCLOSE_DELAY = 3000; @@ -94,7 +96,20 @@ export const uploadService = { // limited by bandwidth. for (const sortedFile of sortedFiles) { const file = progressToast.files[sortedFile.progressToastId]; - const dataURL = await getDataURLFromFile(sortedFile); + let dataURL; + try { + dataURL = await getDataURLFromFile(sortedFile); + } catch { + deleteFile(file.id); + env.services.notification.add( + sprintf( + _t('Could not load the file "%s".'), + sortedFile.name + ), + { type: 'danger' } + ); + continue + } try { const xhr = new XMLHttpRequest(); xhr.upload.addEventListener('progress', ev => {