summaryrefslogtreecommitdiff
path: root/src/server/api/define.ts
diff options
context:
space:
mode:
authorsyuilo <Syuilotan@yahoo.co.jp>2019-04-23 22:35:26 +0900
committerGitHub <noreply@github.com>2019-04-23 22:35:26 +0900
commit0463c6bb0f8fd32740ceb61ccce04c662272a618 (patch)
treea28cbdf6c9cdc14648b8c0e46248665a3ad7e5af /src/server/api/define.ts
parentFix #4768 (diff)
downloadsharkey-0463c6bb0f8fd32740ceb61ccce04c662272a618.tar.gz
sharkey-0463c6bb0f8fd32740ceb61ccce04c662272a618.tar.bz2
sharkey-0463c6bb0f8fd32740ceb61ccce04c662272a618.zip
Refactor API (#4770)
* wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * Update description.ts * wip
Diffstat (limited to 'src/server/api/define.ts')
-rw-r--r--src/server/api/define.ts7
1 files changed, 6 insertions, 1 deletions
diff --git a/src/server/api/define.ts b/src/server/api/define.ts
index 990cbf2a86..1e2600add0 100644
--- a/src/server/api/define.ts
+++ b/src/server/api/define.ts
@@ -3,6 +3,7 @@ import { ILocalUser } from '../../models/entities/user';
import { IEndpointMeta } from './endpoints';
import { ApiError } from './error';
import { App } from '../../models/entities/app';
+import { SchemaType } from '../../misc/schema';
type Params<T extends IEndpointMeta> = {
[P in keyof T['params']]: NonNullable<T['params']>[P]['transform'] extends Function
@@ -12,7 +13,11 @@ type Params<T extends IEndpointMeta> = {
export type Response = Record<string, any> | void;
-export default function <T extends IEndpointMeta>(meta: T, cb: (params: Params<T>, user: ILocalUser, app: App, file?: any, cleanup?: Function) => Promise<Response>): (params: any, user: ILocalUser, app: App, file?: any) => Promise<any> {
+type executor<T extends IEndpointMeta> =
+ (params: Params<T>, user: ILocalUser, app: App, file?: any, cleanup?: Function) => Promise<T['res'] extends undefined ? Response : SchemaType<NonNullable<T['res']>>>;
+
+export default function <T extends IEndpointMeta>(meta: T, cb: executor<T>)
+ : (params: any, user: ILocalUser, app: App, file?: any) => Promise<any> {
return (params: any, user: ILocalUser, app: App, file?: any) => {
function cleanup() {
fs.unlink(file.path, () => {});