This commit is contained in:
Alex Yatskov 2017-09-13 15:41:06 -07:00
parent 79b99131f6
commit 219eeb6e81

View File

@ -20,7 +20,6 @@
class Database { class Database {
constructor() { constructor() {
this.db = null; this.db = null;
this.version = 2;
this.tagCache = {}; this.tagCache = {};
} }
@ -177,7 +176,7 @@ class Database {
const indexDataLoaded = async summary => { const indexDataLoaded = async summary => {
const count = await this.db.dictionaries.where('title').equals(summary.title).count(); const count = await this.db.dictionaries.where('title').equals(summary.title).count();
if (count > 0) { if (count > 0) {
throw `dictionary "${title}" is already imported`; throw `dictionary "${summary.title}" is already imported`;
} }
await this.db.dictionaries.add(summary); await this.db.dictionaries.add(summary);
@ -299,9 +298,9 @@ class Database {
kanjiFreqDataLoaded, kanjiFreqDataLoaded,
tagDataLoaded tagDataLoaded
) { ) {
const files = (await JSZip.loadAsync(archive)).files; const zip = await JSZip.loadAsync(archive);
const indexFile = files['index.json']; const indexFile = zip.files['index.json'];
if (!indexFile) { if (!indexFile) {
throw 'no dictionary index found in archive'; throw 'no dictionary index found in archive';
} }
@ -324,7 +323,7 @@ class Database {
const countBanks = namer => { const countBanks = namer => {
let count = 0; let count = 0;
while (files[namer(count)]) { while (zip.files[namer(count)]) {
++count; ++count;
} }
@ -358,7 +357,7 @@ class Database {
const loadBank = async (namer, count, callback) => { const loadBank = async (namer, count, callback) => {
if (callback) { if (callback) {
for (let i = 0; i < count; ++i) { for (let i = 0; i < count; ++i) {
const bankFile = files[namer(i)]; const bankFile = zip.files[namer(i)];
const bank = JSON.parse(await bankFile.async('string')); const bank = JSON.parse(await bankFile.async('string'));
await callback(index.title, bank, bankTotalCount, bankLoadedCount++); await callback(index.title, bank, bankTotalCount, bankLoadedCount++);
} }