Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function wsConnection(ws) {
console.log('Connection: ', ws.upgradeReq.url);
var url = ws.upgradeReq.url;
var base = url.split('?')[0];
var parts = base.split('/');
console.log(parts);
// strip off websockets/ from the path
parts.shift();
ws.docId = Base62.decode(parts[1]);
if (parts[2] !== 'edit' && parts[2] !== 'view') {
return;
}
// Helper Functions
ws.sendJSON = function(json) {
this.send(JSON.stringify(json), function(err) {
if (err) {
console.error('WS ERROR', err);
}
});
};
ws.error = function(msg) {
ws.sendJSON({
type: 'error',
reason: msg
if (!aScript) {
aNext();
return;
}
// HTTP/1.1 Caching
aRes.set('Cache-Control', 'public, max-age=' + maxAge +
', no-cache, no-transform, must-revalidate');
script = modelParser.parseScript(aScript);
meta = script.meta; // NOTE: Watchpoint
if (/\.json$/.test(aReq.params.scriptname)) {
// Create a based representation of the hex sha512sum
eTag = '"' + Base62.encode(parseInt('0x' + aScript.hash, 16)) + ' .meta.json"';
// If already client-side... HTTP/1.1 Caching
if (aReq.get('if-none-match') === eTag) {
aRes.status(304).send(); // Not Modified
return;
}
// Okay to send .meta.json...
aRes.set('Content-Type', 'application/json; charset=UTF-8');
// HTTP/1.0 Caching
aRes.set('Expires', moment(moment() + maxAge * 1000).utc()
.format('ddd, DD MMM YYYY HH:mm:ss') + ' GMT');
// HTTP/1.1 Caching
aRes.set('Etag', eTag);
function generateToken()
{
return base62.encode(new Buffer(uuid.v4(null, [])).readUInt32LE(0));
} // end generateToken
function getOrCreateMessageId(message) {
if (message in messages) {
return messages[message].id;
}
const id = base62ascii.encode(nextMessageId++); // [0-9a-zA-Z]
messages[message] = {id, message};
return id;
}
export function getDjangoBase62() {
// This is the alphabet used by Django.
base62.setCharacterSet(
'0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz',
);
return base62;
}
test.serial('shorten url and retrieve its decoded value', async t => {
const res = await urlService.shortenURL(testURL)
t.is(res.url, testURL)
t.is(res.base62, Base62.encode(res.numerical_id))
const receivedURL = await urlService.getURL(res.base62)
t.is(receivedURL.url, testURL)
t.is(receivedURL.numerical_id, res.numerical_id)
})
export async function shortenURL(url) {
if (!isURL(url)) {
throw new Error('Invalid URL provided')
}
if (url.indexOf('//nazr.in') > -1) {
throw new Error('URLs contain nazr.in can not to be shortened')
}
const shortLink = new ShortLink()
await shortLink.save()
shortLink.url = url
shortLink.base62 = base64Encode(shortLink.numerical_id)
await shortLink.save()
return shortLink
}
function _generateAnonymousClassName(state) {
var mungeNamespace = state.mungeNamespace || '';
return '____Class' + mungeNamespace + base62.encode(_anonClassUUIDCounter++);
}
function _getMungedName(identName, state) {
var mungeNamespace = state.mungeNamespace;
var shouldMinify = state.g.opts.minify;
if (shouldMinify) {
if (!_mungedSymbolMaps[mungeNamespace]) {
_mungedSymbolMaps[mungeNamespace] = {
symbolMap: {},
identUUIDCounter: 0
};
}
var symbolMap = _mungedSymbolMaps[mungeNamespace].symbolMap;
if (!symbolMap[identName]) {
symbolMap[identName] =
base62.encode(_mungedSymbolMaps[mungeNamespace].identUUIDCounter++);
}
identName = symbolMap[identName];
}
return '$' + mungeNamespace + identName;
}
function _generateAnonymousClassName(state) {
var mungeNamespace = state.mungeNamespace || '';
return '____Class' + mungeNamespace + base62.encode(_anonClassUUIDCounter++);
}