Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
core.on('boot', function (changes, next) {
var entities={}, textRanges={}, texts={}, threadRanges={}, threads={}, sid, key, o;
sid = changes.session;
if(!sid) {
console.error('boot@persistence: Session ID is missing.');
}
/* 1. Retrieve all the data from localStorage */
for(key in localStorage) {
if(key.indexOf(sid) !== 0) continue;
try {
o = JSON.parse(lzString.decompressFromUTF16(localStorage[key]));
} catch(e) {
console.error('Could not parse localStorage item ' + key);
continue;
}
key = key.split(':');
switch(key[1]) {
case 'e':
entities[o.id? o.id: o.room + '_' + o.user] = o;
break;
case 'T':
(textRanges[key[2]] = textRanges[key[2]] || []).push(o);
o.items = [];
break;
case 't':
(texts[key[2]] = texts[key[2]] || []).push(o);
break;
db.get(id).then(function(facilitiesDoc) {
console.log("Get:", id);
var facilitiesLZ = facilitiesDoc.facilities[0]; // Why an array? WHO KNOWS
var facilities = JSON.parse(LZString.decompressFromUTF16(facilitiesLZ));
p.fulfill(facilities);
}).catch(function (err) {
console.log("Failed to Get:", err);
while (l--) {
_keys[l] = ls.key(l);
_config[_keys[l]] = _config[_keys[l]] || {};
// _compressAll is given and value is not
// compressed then compress the value
if (_compressAll && !_config[_keys[l]].c) {
_config[_keys[l]].c = true;
ls.setItem(_keys[l], lzstring.compressToUTF16( ls.getItem(_keys[l]) ));
}
// if the value is compressed and
// compressAll is not given then decompress
// current value.
else if (!_compressAll && _config[_keys[l]].c) {
delete _config[_keys[l]].c;
ls.setItem(_keys[l], lzstring.decompressFromUTF16( ls.getItem(_keys[l]) ));
}
if (_config[_keys[l]].ttl) {
_setTimeout(_keys[l], _config[_keys[l]].ttl - Date.now());
}
}
// Exclude locally-config from _keys array
if (_keys.indexOf('locally-config') > -1) {
_keys.splice(_keys.indexOf('locally-config'), 1);
}
}
// custom options
options = options || {};
_compressAll = options.compress;
// load current localStorage state
_config = ls.getItem('locally-config');
// start anew if no config
if (!_config) {
_config = {};
// reads localstorage and updates config
_rebuildConfig();
}
else {
var deconfig = lzstring.decompressFromUTF16(_config);
try {
_config = JSON.parse(deconfig || _config);
} catch (e) {
if (!!deconfig) {
try {
_config = JSON.parse(_config);
} catch (e) {
throw new Error('Locally: config is corrupted');
}
} else throw new Error('Locally: config is corrupted');
}
// reads localstorage and updates config
_rebuildConfig();
}
req.body.compressed.split(',').forEach(function (key) {
req.body[key] = LZString.decompressFromUTF16(req.body[key]);
});
}
export function parseDocument(serializedDocument, format, compression) {
if (format == 'markdown' && compression == 'lz-string-valid-utf16') {
return marked(LZString.decompressFromUTF16(serializedDocument));
}
else {
throw new Error('Invalid document');
}
}
function readData (key) {
let data = localStorage.getItem(key)
if (data) {
if (!data.startsWith('{')) {
data = LZString.decompressFromUTF16(data)
}
return JSON.parse(data)
}
}
export function get(key: string): ?string {
const compressed = localStorage.getItem(makeKey(key));
return decompressFromUTF16(compressed);
}
private decompress(data: string | null): T | null {
if (data === null) {
return null;
}
return JSON.parse(decompressFromUTF16(data));
}
}