Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const host = process.env.CODESANDBOX_HOST;
const MAX_CACHE_SIZE = 1024 * 1024 * 7;
let APICacheUsed = false;
try {
localforage.config({
name: 'CodeSandboxApp',
storeName: 'sandboxes', // Should be alphanumeric, with underscores.
description:
'Cached transpilations of the sandboxes, for faster initialization time.',
});
// Prewarm store
localforage.keys();
} catch (e) {
console.warn('Problems initializing IndexedDB store.');
console.warn(e);
}
function shouldSaveOnlineCache(firstRun: boolean, changes: number) {
if (!firstRun || changes > 0) {
return false;
}
if (!(window as any).__SANDBOX_DATA__) {
return true;
}
return false;
}
export function uncacheDataset(dataset) {
localforage.keys().then((keys) => {
let matchingKeys = [];
for (let i = 0; i < keys.length; i++) {
let key = keys[i];
// this covers both `${key}` and `${key}/genes` case
if (key.startsWith(dataset.path)) {
matchingKeys.push(key);
}
}
return localforage.removeItems(matchingKeys);
});
}
const isProduction = process.env.NODE_ENV === 'production'
/**
* This is required as Webpack seems to do some static analysis
* and breaking the module.
* @see https://github.com/localForage/localForage-startsWith/issues/5
*/
extendPrototype(localforage)
localforage.config({
name: 'happy-plants',
driver: [localforage.INDEXEDDB, localforage.LOCALSTORAGE]
})
// Temporary fix to clean up DB.
localforage.keys()
.then(keys => {
if (keys.includes('undefined')) {
localforage.removeItem('undefined')
}
})
/**
* Vue configuration.
*/
Vue.config.productionTip = isProduction
Vue.config.devtools = true
Vue.config.errorHandler = errorHandler
VueTouch.registerCustomEvent('doubletap', {
type: 'tap',
taps: 2
exists(key, cb) {
localforage.keys().then((keys) => {
if (_.includes(keys, key)) {
return cb(true);
}
return cb(false);
})
.catch((err) => {
console.log(err);
cb(false);
});
},
const updateDocumentsList = () =>
localforage.keys().then((keys) => {
documentIDs = keys
.map((key) => key.match(/document:([a-zA-Z0-9\-_]+):state/))
.filter((key) => key)
.map((key) => key[1]);
render();
});
async list(uri: string): Promise {
let keys = await localforage.keys();
var fsKeys = keys.filter(x => x.startsWith("fs_file[")).map(x => "/" + x.substr(8, x.length - 9));
return FsUri.getChildUris(fsKeys, new FsUri(uri)).map(childUri => new FsItem(childUri));
}
}
export const getAllEntries = (loadEach = true) => {
if (loadEach === false) {
return localforage.keys()
}
return localforage.keys()
.then(keys => Promise.all(keys.map(k => localforage.getItem(k))))
}
.then(() => localForage.keys())
.then(keys => Promise.all(keys.map(key => {