Update how errors are reported when importing a dictionary
This commit is contained in:
parent
0156869a3d
commit
2dad7f888b
@ -332,9 +332,10 @@ class Database {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
async importDictionary(archive, progressCallback, exceptions, details) {
|
async importDictionary(archive, progressCallback, details) {
|
||||||
this.validate();
|
this.validate();
|
||||||
|
|
||||||
|
const errors = [];
|
||||||
const prefixWildcardsSupported = details.prefixWildcardsSupported;
|
const prefixWildcardsSupported = details.prefixWildcardsSupported;
|
||||||
|
|
||||||
const maxTransactionLength = 1000;
|
const maxTransactionLength = 1000;
|
||||||
@ -351,11 +352,7 @@ class Database {
|
|||||||
const objectStore = transaction.objectStore(objectStoreName);
|
const objectStore = transaction.objectStore(objectStoreName);
|
||||||
await Database.bulkAdd(objectStore, items, i, count);
|
await Database.bulkAdd(objectStore, items, i, count);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (exceptions) {
|
errors.push(e);
|
||||||
exceptions.push(e);
|
|
||||||
} else {
|
|
||||||
throw e;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -496,7 +493,7 @@ class Database {
|
|||||||
await bulkAdd('tagMeta', rows, total, current);
|
await bulkAdd('tagMeta', rows, total, current);
|
||||||
};
|
};
|
||||||
|
|
||||||
return await Database.importDictionaryZip(
|
const result = await Database.importDictionaryZip(
|
||||||
archive,
|
archive,
|
||||||
indexDataLoaded,
|
indexDataLoaded,
|
||||||
termDataLoaded,
|
termDataLoaded,
|
||||||
@ -506,6 +503,8 @@ class Database {
|
|||||||
tagDataLoaded,
|
tagDataLoaded,
|
||||||
details
|
details
|
||||||
);
|
);
|
||||||
|
|
||||||
|
return {result, errors};
|
||||||
}
|
}
|
||||||
|
|
||||||
validate() {
|
validate() {
|
||||||
|
@ -577,7 +577,6 @@ async function onDictionaryImport(e) {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const exceptions = [];
|
|
||||||
const files = [...e.target.files];
|
const files = [...e.target.files];
|
||||||
|
|
||||||
const optionsFull = await apiOptionsGetFull();
|
const optionsFull = await apiOptionsGetFull();
|
||||||
@ -593,21 +592,22 @@ async function onDictionaryImport(e) {
|
|||||||
dictImportInfo.textContent = `(${i + 1} of ${ii})`;
|
dictImportInfo.textContent = `(${i + 1} of ${ii})`;
|
||||||
}
|
}
|
||||||
|
|
||||||
const summary = await utilDatabaseImport(files[i], updateProgress, exceptions, importDetails);
|
const {result, errors} = await utilDatabaseImport(files[i], updateProgress, importDetails);
|
||||||
for (const options of toIterable(await getOptionsArray())) {
|
for (const options of toIterable(await getOptionsArray())) {
|
||||||
const dictionaryOptions = SettingsDictionaryListUI.createDictionaryOptions();
|
const dictionaryOptions = SettingsDictionaryListUI.createDictionaryOptions();
|
||||||
dictionaryOptions.enabled = true;
|
dictionaryOptions.enabled = true;
|
||||||
options.dictionaries[summary.title] = dictionaryOptions;
|
options.dictionaries[result.title] = dictionaryOptions;
|
||||||
if (summary.sequenced && options.general.mainDictionary === '') {
|
if (result.sequenced && options.general.mainDictionary === '') {
|
||||||
options.general.mainDictionary = summary.title;
|
options.general.mainDictionary = result.title;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
await settingsSaveOptions();
|
await settingsSaveOptions();
|
||||||
|
|
||||||
if (exceptions.length > 0) {
|
if (errors.length > 0) {
|
||||||
exceptions.push(`Dictionary may not have been imported properly: ${exceptions.length} error${exceptions.length === 1 ? '' : 's'} reported.`);
|
errors.push(...errors);
|
||||||
dictionaryErrorsShow(exceptions);
|
errors.push(`Dictionary may not have been imported properly: ${errors.length} error${errors.length === 1 ? '' : 's'} reported.`);
|
||||||
|
dictionaryErrorsShow(errors);
|
||||||
}
|
}
|
||||||
|
|
||||||
const optionsContext = getOptionsContext();
|
const optionsContext = getOptionsContext();
|
||||||
|
@ -106,13 +106,13 @@ function utilDatabaseDeleteDictionary(dictionaryName, onProgress) {
|
|||||||
return utilBackend().translator.database.deleteDictionary(dictionaryName, onProgress);
|
return utilBackend().translator.database.deleteDictionary(dictionaryName, onProgress);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function utilDatabaseImport(data, progress, exceptions, details) {
|
async function utilDatabaseImport(data, progress, details) {
|
||||||
// Edge cannot read data on the background page due to the File object
|
// Edge cannot read data on the background page due to the File object
|
||||||
// being created from a different window. Read on the same page instead.
|
// being created from a different window. Read on the same page instead.
|
||||||
if (EXTENSION_IS_BROWSER_EDGE) {
|
if (EXTENSION_IS_BROWSER_EDGE) {
|
||||||
data = await utilReadFile(data);
|
data = await utilReadFile(data);
|
||||||
}
|
}
|
||||||
return utilBackend().translator.database.importDictionary(data, progress, exceptions, details);
|
return utilBackend().translator.database.importDictionary(data, progress, details);
|
||||||
}
|
}
|
||||||
|
|
||||||
function utilReadFile(file) {
|
function utilReadFile(file) {
|
||||||
|
Loading…
Reference in New Issue
Block a user