This commit is contained in:
syuilo
2018-04-13 11:44:39 +09:00
parent 22d2f2051c
commit e2e7babee0
5 changed files with 14 additions and 10 deletions

View File

@ -7,6 +7,8 @@ import { IUser } from '../../models/user';
import { IApp } from '../../models/app';
export default async (endpoint: Endpoint, ctx: Koa.Context) => {
const body = ctx.is('multipart/form-data') ? (ctx.req as any).body : ctx.request.body;
const reply = (x?: any, y?: any) => {
if (x === undefined) {
ctx.status = 204;
@ -25,7 +27,7 @@ export default async (endpoint: Endpoint, ctx: Koa.Context) => {
// Authentication
try {
[user, app] = await authenticate(ctx.request.body['i']);
[user, app] = await authenticate(body['i']);
} catch (e) {
reply(403, 'AUTHENTICATION_FAILED');
return;
@ -35,7 +37,7 @@ export default async (endpoint: Endpoint, ctx: Koa.Context) => {
// API invoking
try {
res = await call(endpoint, user, app, ctx.request.body, ctx.req);
res = await call(endpoint, user, app, body, (ctx.req as any).file);
} catch (e) {
reply(400, e);
return;