Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
.then(result => {
// if one is not present then set the current one
if (!result) {
log('no version found, setting');
return set('db-version', currentVersion);
}
// if one is present and it's the same as the current one take no action
if (result === currentVersion) {
log('up to date');
return;
}
// if one is present and it's different then flash the database and refresh the page
if (result !== currentVersion) {
log('version mismatch, reset', result, currentVersion);
clear()
.then(() => set('db-version', currentVersion))
.then(() => location.reload());
}
// unclear what an else branch would mean
log('else branch', result, currentVersion);
return;
});
}
PersistentCache.prototype.clear = function () {
var _this = this;
idb_keyval_1.clear(this.store).catch(function (err) {
console.warn("PersistentCache -> Clear: Store clearing has failed with error: " + err);
_this.memoryCache.clear();
});
};
/**
async function refreshManifests() {
console.log('refreshing manifests...');
const response = await fetch(urls.MANIFESTS, { credentials: 'include' });
if (response.ok) {
const manifests = await response.json();
await idbKeyval.clear();
await Promise.all(manifests.map(manifest => idbKeyval.set(manifest.key_path, manifest)));
console.log('manifests refreshed');
await notifyClients({ type: 'manifests' });
} else {
console.warn('unable to refresh manifests', response);
}
}
async (action: GenericAction) => {
if (isActionOfType(action, 'CLEAR_PRESISTED_STATE_SUCCEEDED')) {
try {
await idb.clear();
return next(clearPersistedStateSucceeded(void 0));
} catch (e) {
console.error(
`Failed to clean persisted state.`,
e,
);
return next(clearPersistedStateFailed({ message: e.message }));
}
} else {
return next(action);
}
};
public clear(): void {
clear(this.store).catch(err => {
console.warn(`PersistentCache -> Clear: Store clearing has failed with error: ${err}`);
this.memoryCache.clear();
});
}
}
set: async newSeed => {
const seed = await get('seed', store);
if (newSeed != seed) {
console.log('clearing cache');
await clear(store);
await set('seed', newSeed, store);
return true;
}
return false;
},
get: async () => await get('seed', store),
async clear() {
if (TdLibController.localStorage) {
localStorage.clear();
} else {
await clear();
}
//const store = localforage.createInstance({ name: 'telegram' });
//store.clear();
}
}
public clear() {
return from(clear(this.store));
}
}
async $clear(callbackId: number) {
const callback = this.bridge.callbackFromId(callbackId);
try {
await idbKeyval.clear();
callback(null);
} catch (err) {
callback(err);
}
}
}
case 'get':
db.get(key, store)
.then((res) => self.postMessage(res))
break
case 'set':
db.set(key, val, store)
.then(() => self.postMessage(true))
.catch(() => self.postMessage(false))
break
case 'del':
db.del(key, store)
.then(() => self.postMessage(true))
.catch(() => self.postMessage(false))
break
case 'clr':
db.clear(store)
.then(() => self.postMessage(true))
.catch(() => self.postMessage(false))
break
case 'keys':
db.keys(store)
.then((res) => self.postMessage(res))
.catch(() => self.postMessage(false))
break
}
})