Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export const migrateFromPouchDbAllDbsToLocalStorage = async () => {
if (localStorage.getItem(KEY) !== null) {
return;
}
try {
// @ts-ignore
const dbNames: string[] = await PouchDB.allDbs();
const tabIds = dbNames.map((dbName) => dbName.substring(4)); // strip "tab/"
localStorage.setItem(KEY, JSON.stringify(tabIds));
console.info(`Migrated ${tabIds.length} tab(s) to local storage: ${tabIds.join(', ')}.`);
try {
// @ts-ignore
await PouchDB.resetAllDbs();
} catch (error) {
console.error('Error destroying PouchDB.allDbs:');
console.error(error);
}
} catch (error) {
if (error.name !== 'indexed_db_went_bad') {
console.warn('Error loading previously used tabs.');
console.error(error);
console.error('Could not fetch PouchDB\'s allDbs while trying to migrate to local storage.');
}
initDbs: function () {
return (
PouchDB.allDbs()
.then(function (dbNames) {
return dbNames.map(this.initDb.bind(this));
}.bind(this))
);
},