Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function* parser (ctx) {
var body
if (ctx.is('text/*')) {
body = yield text(ctx)
} else if (ctx.is('json')) {
body = yield co.json(ctx)
} else if (ctx.is('xml')) {
body = yield xml(ctx)
} else if (ctx.is('urlencoded')) {
body = yield co.form(ctx)
} else if (ctx.is('multipart')) {
body = yield multipart(ctx)
} else {
// return stream buffer for unsupported content-type
body = yield buffer(ctx)
}
return body
}
function* jsonBody(next) {
if (['POST', 'PUT', 'PATCH'].includes(this.method)) {
try {
this.state.body = yield parse.json(this);
} catch (e) {
// Possibly revisit this choice; if the body wasn't JSON-parsable then
// reject it immediately.
this.throw(400, 'Invalid request body');
}
if (!this.state.body) { this.state.body = {}; }
}
yield next;
}
body = yield new Promise((resolve, reject) => {
parse.json(context).then(resolve).catch(reject);
});
}
app.post('/:user/:repo/objects/verify', checkJWT('verify'), wrap(function* (req, res, next) {
try {
var body = yield parse.json(req);
var oid = body.oid;
var size = body.size;
if (!oid || !size) {
return res.status(422).end();
}
var objectSize = yield STORE.getSize(req.params.user, req.params.repo, oid);
if (size !== objectSize) {
return res.status(422).end();
}
res.status(200).end();
} catch (err) {
next(err);
}
return async (ctx) => {
const body = await json(ctx.request)
const response = await handler(body, ctx.vtex)
ctx.set('Content-Type', 'application/json')
ctx.status = 200
ctx.body = response
}
})
return yield new Promise((resolve, reject) => {
parse.json(koaContext).then(resolve).catch(reject);
});
}
* _parse (request) {
let formBody = {
fields: {},
files: {},
raw: null
}
if (request.is(contentTypes.json)) {
formBody.fields = yield coBody.json(request.request, this.formOptions)
} else if (request.is(contentTypes.form)) {
formBody.fields = yield coBody.form(request.request, this.formOptions)
} else if (request.is(contentTypes.text)) {
formBody.raw = yield coBody.text(request.request, this.formOptions)
} else if (request.is(contentTypes.multipart)) {
formBody = yield this._multipart(request, this.uploadOptions)
}
return formBody
}
async function parseBody(ctx) {
if (enableJson && ((detectJSON && detectJSON(ctx)) || ctx.request.is(jsonTypes))) {
return await parse.json(ctx, jsonOpts);
}
if (enableForm && ctx.request.is(formTypes)) {
return await parse.form(ctx, formOpts);
}
if (enableText && ctx.request.is(textTypes)) {
return await parse.text(ctx, textOpts) || '';
}
return {};
}
};
async function parseBody(ctx) {
if (enableJson && ctx.request.is(jsonTypes)) {
return await parse.json(ctx, jsonOpts);
}
if (enableForm && ctx.request.is(formTypes)) {
return await parse.form(ctx, formOpts);
}
if (enableText && ctx.request.is(textTypes)) {
return await parse.text(ctx, textOpts) || '';
}
return {};
}
};