Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const decompress = string =>
LZString.decompressFromBase64(
string
.replace(/-/g, '+') // Convert '-' to '+'
.replace(/_/g, '/') // Convert '_' to '/'
);
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;
function loadAsync() {
let hash = getCurrentHash();
if (!hash)
return null;
last.hash = hash;
if (hash.startsWith('gist:'))
return loadGistAsync(hash);
if (!hash.startsWith('v2:'))
return legacyLoadFrom(hash);
hash = hash.substring('v2:'.length);
try {
const decompressed = LZString.decompressFromBase64(hash);
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const [, optionsPart, codePart] = /^([^|]*)\|([\s\S]*)$/.exec(decompressed)!;
const optionsPacked = (
optionsPart.split(',').reduce((result, p) => {
const [key, value] = p.split(':', 2);
result[key] = value;
return result;
}, {} as { [key: string]: string|undefined })
);
const language = languageMapReverse[optionsPacked.l ?? 'cs']
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
?? throwError(`Failed to resolve language: ${optionsPacked.l}`);
const target = targetMapReverse[optionsPacked.t ?? 'cs']
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
?? throwError(`Failed to resolve target: ${optionsPacked.t}`);
function icons()
{
var vide=outFile; var data=out;
console.log( "- Trying to acquire application ID from Server (" + lzString.decompressFromBase64( data.url ) + ")..." );
var url="/app/check/?url=" + lzString.decompressFromBase64( data.url );
sendBackendRequest( url, {}, function( response ) {
var array=response.check;
var appId;
// --- Check if url exists on the server
for( var i=0; i < array.length; ++i ) {
if ( array[i].name === "url" ) {
if ( array[i].exists ) appId=array[i].appid;
}
}
if ( appId )
{
console.log( "- Acquired the application ID successfully (" + appId + ")." );
var parameters={};
if ( sources[i].indexOf( "clipper.js") === -1 ) {
jshint.JSHINT( source, { evil : true, esversion: 6, loopfunc : true } );
jshint.JSHINT.errors.forEach( function( error ) {
if ( !error ) return;
var evidence=error.evidence ? " ( '" + error.evidence.substring( 0, 10 ) + " )'" : "";
console.log( sources[i] + ", line " + error.line + " char " + error.character + ": " + error.reason + evidence );
} );
}
var name;
if ( source.indexOf( "function vgMain" ) !== -1 ) name="main.js";
else name=path.basename( sources[i] );
out.sources[name]=lzString.compressToBase64( source );
}
// --- Images
out.images={};
var images=extractTokenList( lines, "images", "," );
for ( var i=0; i < images.length; ++i )
{
var image=base64Image( path.join( dir, images[i] ) );
if ( !image || !image.length ) { console.log( "Error: image file \"" + images[i] + "\" not found." ); return; }
var name=path.basename( images[i] );
out.images[name]=image;
}
// --- ImageDirs
// --- SVGDirs
var svgDirs=extractTokenList( lines, "svgDir", "," );
for ( var i=0; i < svgDirs.length; ++i )
{
var svgPath=path.join( dir, svgDirs[i] );
var files=fs.readdirSync( svgPath );
for ( var p=0; p < files.length; ++p )
{
var svgPath=path.join( dir, svgDirs[i], files[p] );
var svg=fs.readFileSync( svgPath ).toString();
if ( !svg || !svg.length ) { console.log( "Error: SVG file \"" + files[p] + "\" not found." ); return; }
var name=path.basename( files[p] );
out.svg[name]=lzString.compressToBase64( svg );
}
}
// --- Html
out.texts={};
var html=extractTokenList( lines, "html", "," );
for ( var i=0; i < html.length; ++i )
{
var source=fs.readFileSync( path.join( dir, html[i] ) ).toString();
if ( !source || !source.length ) { this.errorLog( "Error: html file \"" + html[i] + "\" not found." ); return; }
var name=path.basename( html[i], '.html' );
out.texts[name]=lzString.compressToBase64( source );
}
export function set(key: string, value: string) {
const compressed = compressToUTF16(value);
try {
localStorage.setItem(makeKey(key), compressed);
} catch (e) {
// TODO: How do we want to handle local storage
// being full? We could clear everything and
// start over - but perhaps that's not right
// to consumers using the embeds.
// eslint-disable-next-line
console.error('Local storage is full!');
}
}
async function getPastEvents() {
if (processing) {
await isDone()
}
processing = true
if (!triedIpfs && config.ipfsEventCache) {
debug('Try IPFS cache...')
let ipfsData
try {
ipfsData = await get(config.ipfsGateway, config.ipfsEventCache)
if (ipfsData.compressed) {
const decompressed = LZString.decompress(ipfsData.compressed)
ipfsData = JSON.parse(decompressed)
}
} catch (e) {
/* Ignore */
}
if (ipfsData && ipfsData.events) {
debug('Got IPFS cache')
// console.log(ipfsData)
events = ipfsData.events
lastLookup = ipfsData.lastLookup
fromBlock = ipfsData.lastLookup
// ({ events, lastLookup } = ipfsData)
} else {
debug('Error getting IPFS cache')
}
triedIpfs = true
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);
...events,
...newEvents.map(e => ({ ...e, block: { id: e.blockNumber } }))
],
e => e.id
)
debug(`Found ${events.length} events, ${newEvents.length} new`)
fromBlock = toBlock + 1
processing = false
while (queue.length) {
queue.pop()()
}
if (typeof window !== 'undefined') {
const compressed = LZString.compress(
JSON.stringify({
lastLookup,
events
})
)
window.localStorage[cacheStr] = compressed
// const hash = await post(config.ipfsRPC, { compressed }, true)
// console.log('IPFS Hash', hash)
}
}