[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) <abd@odoo.com>
This commit is contained in:
visp-odoo
2024-03-29 12:38:06 +00:00
parent 6c80d93f07
commit 591658ea67
2 changed files with 22 additions and 1 deletions
+6
View File
@@ -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"
@@ -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 => {