summaryrefslogtreecommitdiff
path: root/ext
diff options
context:
space:
mode:
authorCashew <52880648+Scrub1492@users.noreply.github.com>2024-01-20 10:43:27 +0700
committerGitHub <noreply@github.com>2024-01-20 03:43:27 +0000
commit0011afe435f565dc5669f030da64e2c6e10ce05e (patch)
treeb7cc9598d6a958cbfdd15fff32294ab85dda550e /ext
parentbe267e1994f8fda2ef68562c5c3a5edc9442a8a8 (diff)
improve dictionary validation (#520)
* improve dictionary validation * fix * improve performance * add undefined check * rename types * rename types * rename
Diffstat (limited to 'ext')
-rw-r--r--ext/js/dictionary/dictionary-importer.js24
1 files changed, 13 insertions, 11 deletions
diff --git a/ext/js/dictionary/dictionary-importer.js b/ext/js/dictionary/dictionary-importer.js
index a9726aaf..067c8a3a 100644
--- a/ext/js/dictionary/dictionary-importer.js
+++ b/ext/js/dictionary/dictionary-importer.js
@@ -115,13 +115,13 @@ export class DictionaryImporter {
// Files
/** @type {import('dictionary-importer').QueryDetails} */
- const queryDetails = new Map([
+ const queryDetails = [
['termFiles', /^term_bank_(\d+)\.json$/],
['termMetaFiles', /^term_meta_bank_(\d+)\.json$/],
['kanjiFiles', /^kanji_bank_(\d+)\.json$/],
['kanjiMetaFiles', /^kanji_meta_bank_(\d+)\.json$/],
['tagFiles', /^tag_bank_(\d+)\.json$/]
- ]);
+ ];
const {termFiles, termMetaFiles, kanjiFiles, kanjiMetaFiles, tagFiles} = Object.fromEntries(this._getArchiveFiles(fileMap, queryDetails));
// Load data
@@ -692,16 +692,18 @@ export class DictionaryImporter {
_getArchiveFiles(fileMap, queryDetails) {
/** @type {import('dictionary-importer').QueryResult} */
const results = new Map();
- for (const [name, value] of fileMap.entries()) {
- for (const [fileType, fileNameFormat] of queryDetails.entries()) {
- let entries = results.get(fileType);
- if (typeof entries === 'undefined') {
- entries = [];
- results.set(fileType, entries);
- }
- if (fileNameFormat.test(name)) {
- entries.push(value);
+ for (const [fileType] of queryDetails) {
+ results.set(fileType, []);
+ }
+
+ for (const [fileName, fileEntry] of fileMap.entries()) {
+ for (const [fileType, fileNameFormat] of queryDetails) {
+ if (!fileNameFormat.test(fileName)) { continue; }
+ const entries = results.get(fileType);
+
+ if (typeof entries !== 'undefined') {
+ entries.push(fileEntry);
break;
}
}