Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export async function parseFromURL(config: string): Promise {
// get URL and convert to JSON
const data: ReturnType = JSON.parse(
lz.decompressFromEncodedURIComponent(config.trim())
);
const currentSemester = { id: data[2], name: data[3] };
await semester.selectSemester(currentSemester);
return {
name: data[0],
modified: data[1],
currentSemester,
display: Display.decompressJSON(data[4]),
filter: FilterStore.decompressJSON(data[5]),
schedule: ScheduleStore.decompressJSON(data[6]),
palette: Palette.decompressJSON(data[7])
};
}
if (args.length - 1 !== index) {
msgStr += ' ';
}
});
const msgArr = [{
time: now,
type: level,
category: this.category,
message: msgStr
}];
let msgToSet = '';
if (currentHeader) {
let updateHeader = JSON.parse(lzstring.decompressFromEncodedURIComponent(currentHeader));
updateHeader.push(msgArr[0]);
msgToSet = lzstring.compressToEncodedURIComponent(JSON.stringify(updateHeader));
} else {
msgToSet = lzstring.compressToEncodedURIComponent(JSON.stringify(msgArr));
}
// Check if request is end
if (!res.headersSent) {
// Max length limit
if (msgToSet.length > Number(this.options.extension.maxLength) * 1024) {
res.set(resHeaderName, lzstring.compressToEncodedURIComponent(JSON.stringify([{
time: now,
type: 'warn',
category: 'Server Log',
message: `The logs are too much (${parseInt(msgToSet.length / 1024)}KB), cannot view them now.`
}])));
deserializeFromUrl(): Configuration {
const urlParams = Util.parseUrlParameters();
const preset = urlParams["preset"],
config = urlParams["config"];
if (preset && Presets.exists(preset)) return Presets.get(preset);
else if (config) {
console.log(
JSON.parse(LZString.decompressFromEncodedURIComponent(config))
);
return JSON.parse(
LZString.decompressFromEncodedURIComponent(config)
);
} else return Presets.get("Binary Classifier for XOR");
}
/**
deserialize(data: string | GUI) {
if (this.audioPlayer) this.audioPlayer.playing = false;
if (this.loadingState !== 1) {
console.error("can't load while loading");
return;
}
let obj;
if (typeof data === "string") obj = JSON.parse(LZString.decompressFromEncodedURIComponent(data));
else obj = data;
if (obj.conversation && this.conversation !== obj.conversation) {
this.loadConversation(obj.conversation, obj);
} else {
this.applyState(obj);
}
}
@mobx.action
React.useEffect(() => {
const params = {};
document.location.search
.slice(1)
.split('&')
.forEach(p => {
const [k, v] = p.split('=');
params[k] = v;
});
const encodedCode = params.c || window.localStorage.getItem(`code-${name}`);
if (encodedCode) {
const nextCode = LZString.decompressFromEncodedURIComponent(encodedCode);
setCode(nextCode);
}
}, []);
export const getCode = () => {
if (typeof document === 'undefined') return sampleCode
const hash = document.location.hash.slice(1)
if (!hash) return sampleCode
return (
LZString.decompressFromEncodedURIComponent(hash) || decodeURIComponent(hash)
)
}
function parseCondition(conditionJson) {
return JSON.parse(LZString.decompressFromEncodedURIComponent(conditionJson));
}
private _decode(options: string|TOptions): TOptions {
let decompressed = options;
if (typeof options === 'string') {
decompressed = JSON.parse(decompress(options));
}
return {...this.defaults, ...decompressed as TOptions};
}
export const decodeUrl = (url: string) => {
const urlParameters = new URLSearchParams(url);
if (urlParameters.has("saved")) {
const savedParameter = urlParameters.get("saved");
if (isNil(savedParameter)) {
return undefined;
}
const decompressed = lzString.decompressFromEncodedURIComponent(
savedParameter
);
return JSON.parse(decompressed);
}
return undefined;
};