Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
init () {
try {
// IOS fixed crash IndexedDB
// DOMException: Connection to Indexed Database server lost. Refresh the page to try again
// Disable IndexedDB for Safari
let driver = []
// eslint-disable-next-line no-useless-escape
if (!!navigator.userAgent.match(/Version\/[\d\.]+.*Safari/)) {
// console.log('Safari: No IndexedDB usage')
driver = [
localForage.WEBSQL,
localForage.LOCALSTORAGE
]
} else {
driver = [
localForage.INDEXEDDB,
localForage.WEBSQL,
localForage.LOCALSTORAGE
]
}
localForage.config({
driver
})
return localForage
} catch (error) {
console.error('localForage.config Error: ', error)
}
}
import localforage from 'localforage';
import _ from 'lodash';
localforage.config({
name: 'somafm',
driver: localforage.LOCALSTORAGE,
size: 4980736 // Default.
});
const storage = {
getItem(key, cb) {
localforage.getItem(key).then((val) =>
cb(val)
)
.catch((err) => {
cb(err);
});
},
setItem(key, value, cb) {
localforage.setItem(key, value).then((val) =>
) {
const dbConfig: LocalForageOptions = {
name: platformService.appName,
version: 3,
size: 4980736, // Size of database, in bytes. WebSQL-only for now.
storeName: `${platformService.appName}_db`,
description: `${platformService.appName}`,
};
this._db = localForage.createInstance(dbConfig);
this._db.setDriver([
localForage.INDEXEDDB,
localForage.WEBSQL,
localForage.LOCALSTORAGE,
]);
this._db.length(); // Init db now
}
import * as localforage from 'localforage';
import BrowserStorage from 'mtproto-storage-browser';
import MTProto from 'telegram-mtproto';
import { appSettings, serverConfig } from './config';
export const storage = localforage.createInstance({
driver: localforage.LOCALSTORAGE,
});
const app = {
debug: true,
storage: new BrowserStorage(storage),
};
const pool = MTProto({
server: serverConfig,
api: appSettings,
app,
});
// TODO: use generic params and options
export const api = (method: string, params?: object, options?: object): Promise =>
pool(method, params, options);
import Axios from 'axios';
import { Modal, notification, message } from 'antd';
import { setupCache, setup } from 'axios-cache-adapter';
import localforage from 'localforage';
const baseURL = 'https://api.github.com';
export const forageStore = localforage.createInstance({
// List of drivers used
driver: [localforage.INDEXEDDB, localforage.LOCALSTORAGE],
// Prefix all storage keys to prevent conflicts
name: 'remu-cache',
});
export const request = setup({
baseURL,
cache: {
maxAge: 60 * 60 * 1000,
exclude: { query: false },
store: forageStore,
invalidate: async (config, request) => {
if (request.clearCacheEntry) {
// @ts-ignore
await config.store.removeItem(config.uuid);
}
},
this.cacheConfig = {
...defaults,
...cacheConfig
}
this.log = this.log.bind( this )
this.clearCachePrefix = this.clearCachePrefix.bind( this )
this.inferPrefixFromUrl = this.inferPrefixFromUrl.bind( this )
this.generateCacheKey = this.generateCacheKey.bind( this )
this.shouldInvalidate = this.shouldInvalidate.bind( this )
this.cacheStore = localforage.createInstance( {
driver: [
localforage.LOCALSTORAGE,
],
// Prefix all storage keys to prevent conflicts
name: storagePrefix
} )
}
constructor() {
/* TODO remove when it is working again
* With the latest version of localforage Firefox can not use indexDB
* "A mutation operation was attempted on a database that did not allow mutations."
* Therefor we have to use localstorage until it is fixed
*/
if (ClientDetector.getClient().name === ClientNames.Firefox) {
localforage.config({
driver: localforage.LOCALSTORAGE
});
}
}
return driverOrder.map(driver => {
switch (driver) {
case 'sqlite':
return CordovaSQLiteDriver._driver;
case 'indexeddb':
return LocalForage.INDEXEDDB;
case 'websql':
return LocalForage.WEBSQL;
case 'localstorage':
return LocalForage.LOCALSTORAGE;
}
});
}
function createDataStorage() {
return localForage.createInstance({
name: 'tabliss',
driver:
process.env.BUILD_TARGET === 'web'
? localForage.LOCALSTORAGE
: syncDriver._driver,
storeName: 'data',
});
}