From 3af9fd1ea3a2d2288bf9ae73c24bb92eb8291cdd Mon Sep 17 00:00:00 2001 From: Jaifroid Date: Tue, 10 Oct 2023 08:17:32 +0100 Subject: [PATCH] If import failed, delete file stub(s) --- www/js/app.js | 7 ++++++- www/js/lib/kiwixServe.js | 4 +++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/www/js/app.js b/www/js/app.js index a9c05ad9..af89869b 100644 --- a/www/js/app.js +++ b/www/js/app.js @@ -1353,8 +1353,13 @@ archiveFilesLegacy.addEventListener('change', function (files) { console.error('Unable to import files to OPFS!', err); var message = '

We could not import the selected files to the OPFS!

Reason: ' + err.message + '

'; if (/iOS/.test(params.appType) || /^((?!chrome|android).)*safari/i.test(navigator.userAgent)) message = '

Unfortunately, Safari and iOS browsers do not currently support importing files into the OPFS. Please disable the OPFS and use other file selection options.

Error message: ' + err.message + '

'; - uiUtil.systemAlert(message, 'OPFS import error'); uiUtil.pollOpsPanel(); + uiUtil.systemAlert(message, 'OPFS import error').then(function () { + // Delete each of the files that failed to import + filesArray.forEach(function (file) { + cache.deleteOPFSEntry(file.name); + }); + }); }); }); } diff --git a/www/js/lib/kiwixServe.js b/www/js/lib/kiwixServe.js index ed705b30..77677ee6 100644 --- a/www/js/lib/kiwixServe.js +++ b/www/js/lib/kiwixServe.js @@ -629,7 +629,9 @@ function requestXhttpData (URL, lang, subj, kiwixDate) { percentageComplete = 0; var message = 'Unable to download the archive ' + archiveName + ' to your device: ' + err; if (/iOS/.test(params.appType) || /^((?!chrome|android).)*safari/i.test(navigator.userAgent)) message = '

Unfortunately, Safari and iOS browsers do not currently support downloading files directly into the OPFS. Please select a different download method.

Error message: ' + err.message + '

'; - return uiUtil.systemAlert(message, 'Download failed'); + return uiUtil.systemAlert(message, 'Download failed').then(function () { + return cache.deleteOPFSEntry(archiveName); + }); }); } if (megabytes > 1000) {