Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export function shortUrlAssertValid(url: string) {
const { protocol, hostname, pathname } = parse(url);
if (protocol) {
throw Boom.notAcceptable(`Short url targets cannot have a protocol, found "${protocol}"`);
}
if (hostname) {
throw Boom.notAcceptable(`Short url targets cannot have a hostname, found "${hostname}"`);
}
const pathnameParts = trim(pathname, '/').split('/');
if (pathnameParts.length !== 2) {
throw Boom.notAcceptable(
`Short url target path must be in the format "/app/{{appId}}", found "${pathname}"`
);
}
}
async handler(req, res) {
let allrkeys = Object.keys(quotes.ALL_RKEYS)
let symbols = req.body.symbols as string[]
let types = (req.body.types || allrkeys) as Quotes.AllKeys[]
let invalids = _.difference(types, allrkeys)
if (invalids.length > 0) throw boom.notAcceptable(invalids.toString(), { invalids });
return quotes.getAlls(symbols, types)
}
})
export function getSearchDsl(mappings, schema, options = {}) {
const {
type,
search,
searchFields,
sortField,
sortOrder,
namespace,
} = options;
if (!type) {
throw Boom.notAcceptable('type must be specified');
}
if (sortOrder && !sortField) {
throw Boom.notAcceptable('sortOrder requires a sortField');
}
return {
...getQueryParams(mappings, schema, namespace, type, search, searchFields),
...getSortingParams(mappings, type, sortField, sortOrder),
};
}
function (req, res, next) {
var gitScript = path.join(__dirname, '../bin/git-status');
var directory;
switch (req.params.repo) {
case 'platforms':
case 'resources':
case 'middlewares':
directory = path.join(__dirname, '..', req.params.repo);
break;
case 'app':
directory = path.join(__dirname, '..');
break;
default:
return next(Boom.notAcceptable('invalid_repository'));
}
execFile(gitScript, { cwd: directory }, function (error, stdout) {
if (error) { return next(error); }
if (!stdout) { return next(Boom.badImplementation()); }
try {
var result = JSON.parse(stdout);
res.status(200).json(result);
} catch (e) {
return next(e);
}
});
}
);
function safePath(name, value) {
const restriction = () => `Valid ${name} contains Alpha-Numeric characters, is at least 1 character long but less than 25,
and may contain any special characters including dash (-) or underscore (_)`;
if (!value || validation[name].validate(value).error) {
return boom.notAcceptable(restriction());
}
if (name === 'albumStem') {
return `album_${value}.xml`;
}
return `gallery-${value}`;
}
const updateProcess = (request, reply) => {
if (request.payload.status === 'start') {
return request.server.methods.startProcess(context(request), request.params.name)
} else if (request.payload.status === 'stop') {
return request.server.methods.stopProcess(context(request), request.params.name)
}
if (request.payload.workers) {
return request.server.methods.setNumWorkers(context(request), request.params.name, request.payload.workers)
}
return Promise.reject(Boom.notAcceptable('A status or some workers should be sent'))
}
async handler(request, h) {
const guard = new TransactionGuard(transactionPool)
const result = await guard.validate(request.payload.transactions)
if (result.invalid.length > 0) {
return Boom.notAcceptable(
'Transactions list could not be accepted.',
guard.errors,
)
}
if (result.broadcast.length > 0) {
container.resolvePlugin('p2p').broadcastTransactions(result.broadcast)
}
return { data: result.accept.map(t => t.id) }
},
config: {
function use (redeem, userId, cb) {
if (redeem === null) {
log.error({err: err, redeem: redeem.id}, 'redeem code not found')
return cb(Boom.notAcceptable())
}
if (redeem.achievement === null) {
log.error({err: err, achievement: redeem.achievement}, 'achievement of redeem not found')
return cb(Boom.notAcceptable())
}
if (redeem.available !== undefined && redeem.available <= 0) {
log.info({err: err, user: userId, redeem: redeem.id}, 'redeem code not available anymore')
return cb(Boom.notAcceptable())
}
Achievement.findOne({ id: redeem.achievement }, (err, achievement) => {
if (err) {
log.error({err: err, achievement: achievement.id}, 'achievement of redeem not found')
return cb(Boom.notAcceptable())
}
let now = new Date().getTime()
if (achievement.validity !== undefined
request.log([DEBUG, CONTEXT], `${request.params.name} emitted ${request.payload.event} with args ${JSON.stringify(request.payload.args)}`)
return receiveEvent(request, request.params.name, request.payload.event, request.payload.args)
} else if (request.auth.credentials.scope.indexOf('user') !== -1) {
request.log([DEBUG, CONTEXT], `Sending ${request.payload.event} to ${request.params.name} with args ${JSON.stringify(request.payload.args)}`)
return request.server.methods.sendEvent(
context(request),
request.params.name,
request.payload.event,
request.payload.args,
request.payload.worker
)
}
return Promise.reject(Boom.notAcceptable('An event should be sent by or to a process'))
}