Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
) => (
req: FastifyRequest,
reply: FastifyReply,
done: (err: Error | null, body?: any) => void,
) => {
if (
(req.req as any)[kMultipart] &&
typeof processFileUploads === 'function'
) {
processFileUploads(req.req, reply.res, uploadsConfig)
.then((body: GraphQLOperation | GraphQLOperation[]) => {
req.body = body;
done(null);
})
.catch((error: any) => {
if (error.status && error.expose) reply.status(error.status);
throw formatApolloErrors([error], {
formatter: server.requestOptions.formatError,
debug: server.requestOptions.debug,
});
});
} else {
done(null);
}
};
return async (request: hapi.Request, _h?: hapi.ResponseToolkit) => {
if (
typeof processFileUploads === 'function' &&
request.mime === 'multipart/form-data'
) {
Object.defineProperty(request, 'payload', {
value: await processFileUploads(
request.raw.req,
request.raw.res,
uploadsConfig,
),
writable: false,
});
}
};
}
) => async (ctx: Koa.Context, next: Function) => {
if (typeis(ctx.req, ['multipart/form-data'])) {
try {
ctx.request.body = await processFileUploads(
ctx.req,
ctx.res,
uploadsConfig,
);
return next();
} catch (error) {
if (error.status && error.expose) ctx.status = error.status;
throw formatApolloErrors([error], {
formatter: server.requestOptions.formatError,
debug: server.requestOptions.debug,
});
}
} else {
return next();
}