Prevent duplicate import

This commit is contained in:
Alex Yatskov 2016-11-07 22:12:18 -08:00
parent 407da51918
commit 638fe54c2a

View File

@ -161,20 +161,22 @@ class Database {
} }
const indexLoaded = (title, version, entities, hasTerms, hasKanji) => { const indexLoaded = (title, version, entities, hasTerms, hasKanji) => {
return this.db.dictionaries.where('title').equals(title).count().then(count => {
if (count > 0) {
return Promise.reject(`dictionary "${title}" is already imported`);
}
return this.db.dictionaries.add({title, version, hasTerms, hasKanji}).then(() => { return this.db.dictionaries.add({title, version, hasTerms, hasKanji}).then(() => {
this.entities = entities || {}; this.entities = entities || {};
const rows = []; const rows = [];
for (const name in entities || {}) { for (const name in entities || {}) {
rows.push({ rows.push({name, value: entities[name], dictionary: title});
name,
value: entities[name],
dictionary: title
});
} }
return this.db.entities.bulkAdd(rows); return this.db.entities.bulkAdd(rows);
}); });
});
}; };
const termsLoaded = (title, entries, total, current) => { const termsLoaded = (title, entries, total, current) => {