Skip to content

Commit

Permalink
[FIX] web_editor: show toaster notification error on uploading folder
Browse files Browse the repository at this point in the history
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 #159755

X-original-commit: 0b27ac0
Signed-off-by: Damien Abeloos (abd) <abd@odoo.com>
  • Loading branch information
visp-odoo committed Mar 29, 2024
1 parent 6c80d93 commit 591658e
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
6 changes: 6 additions & 0 deletions addons/web_editor/i18n/web_editor.pot
Expand Up @@ -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"
Expand Down
Expand Up @@ -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;
Expand Down Expand Up @@ -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 => {
Expand Down

0 comments on commit 591658e

Please sign in to comment.