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

@ -1,4 +1,3 @@
import * as http from 'http';
import * as multer from 'koa-multer';
import endpoints, { Endpoint } from './endpoints';
@ -6,7 +5,7 @@ import limitter from './limitter';
import { IUser } from '../../models/user';
import { IApp } from '../../models/app';
export default (endpoint: string | Endpoint, user: IUser, app: IApp, data: any, req?: http.IncomingMessage) => new Promise<any>(async (ok, rej) => {
export default (endpoint: string | Endpoint, user: IUser, app: IApp, data: any, file?: any) => new Promise<any>(async (ok, rej) => {
const isSecure = user != null && app == null;
const ep = typeof endpoint == 'string' ? endpoints.find(e => e.name == endpoint) : endpoint;
@ -36,8 +35,8 @@ export default (endpoint: string | Endpoint, user: IUser, app: IApp, data: any,
let exec = require(`${__dirname}/endpoints/${ep.name}`);
if (ep.withFile && req) {
exec = exec.bind(null, (req as multer.MulterIncomingMessage).file);
if (ep.withFile && file) {
exec = exec.bind(null, file);
}
let res;