diff options
author | Birudo un <cokoryuu@gmail.com> | 2024-03-18 20:29:53 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-03-18 12:29:53 +0000 |
commit | c26680fd7399e8e1fb5e3c10a3f72f592d59e370 (patch) | |
tree | f088a7b06c3ef0440b8aea0d0dff772435a48601 /ext/js | |
parent | 7ee76d708934adeef06479f7757beb22c6c01d14 (diff) |
feat: support skipping already import dictionaries (#769)
Diffstat (limited to 'ext/js')
-rw-r--r-- | ext/js/dictionary/dictionary-importer.js | 5 | ||||
-rw-r--r-- | ext/js/pages/settings/dictionary-import-controller.js | 13 |
2 files changed, 14 insertions, 4 deletions
diff --git a/ext/js/dictionary/dictionary-importer.js b/ext/js/dictionary/dictionary-importer.js index 16998a8f..310b2ec1 100644 --- a/ext/js/dictionary/dictionary-importer.js +++ b/ext/js/dictionary/dictionary-importer.js @@ -106,7 +106,10 @@ export class DictionaryImporter { // Verify database is not already imported if (await dictionaryDatabase.dictionaryExists(dictionaryTitle)) { - throw new Error('Dictionary is already imported'); + return { + errors: [new Error(`Dictionary ${dictionaryTitle} is already imported, skipped it.`)], + result: null + }; } // Load schemas diff --git a/ext/js/pages/settings/dictionary-import-controller.js b/ext/js/pages/settings/dictionary-import-controller.js index 64d94a52..f63eb49e 100644 --- a/ext/js/pages/settings/dictionary-import-controller.js +++ b/ext/js/pages/settings/dictionary-import-controller.js @@ -149,6 +149,8 @@ export class DictionaryImportController { const prevention = this._preventPageExit(); + /** @type {Error[]} */ + let errors = []; try { this._setModifying(true); this._hideErrors(); @@ -196,12 +198,12 @@ export class DictionaryImportController { count: 0 }); if (statusFooter !== null) { statusFooter.setTaskActive(progressSelector, true); } - - await this._importDictionary(files[i], importDetails, onProgress); + errors = [...errors, ...(await this._importDictionary(files[i], importDetails, onProgress) ?? [])]; } } catch (error) { - this._showErrors([toError(error)]); + errors.push(toError(error)); } finally { + this._showErrors(errors); prevention.end(); for (const progress of progressContainers) { progress.hidden = true; } if (statusFooter !== null) { statusFooter.setTaskActive(progressSelector, false); } @@ -231,10 +233,15 @@ export class DictionaryImportController { * @param {File} file * @param {import('dictionary-importer').ImportDetails} importDetails * @param {import('dictionary-worker').ImportProgressCallback} onProgress + * @returns {Promise<Error[] | undefined>} */ async _importDictionary(file, importDetails, onProgress) { const archiveContent = await this._readFile(file); const {result, errors} = await new DictionaryWorker().importDictionary(archiveContent, importDetails, onProgress); + if (!result) { + return errors; + } + void this._settingsController.application.api.triggerDatabaseUpdated('dictionary', 'import'); const errors2 = await this._addDictionarySettings(result.sequenced, result.title); |