paricafe/src/server/api/endpoints.ts

108 lines
2.6 KiB
TypeScript
Raw Normal View History

2018-11-01 13:32:24 -05:00
import { Context } from 'cafy';
2018-07-15 13:43:36 -05:00
import * as path from 'path';
import * as glob from 'glob';
2018-07-15 13:25:35 -05:00
2018-07-15 13:43:36 -05:00
export interface IEndpointMeta {
2018-11-01 13:32:24 -05:00
stability?: string; //'deprecated' | 'experimental' | 'stable';
2018-10-21 15:16:27 -05:00
2018-11-01 13:32:24 -05:00
desc?: { [key: string]: string };
2018-07-15 13:53:03 -05:00
2018-11-01 13:32:24 -05:00
params?: {
[key: string]: {
validator: Context<any>;
transform?: any;
default?: any;
desc?: { [key: string]: string };
ref?: string;
};
};
2018-07-15 13:53:03 -05:00
res?: any;
2018-07-15 13:25:35 -05:00
/**
*
* false
*/
requireCredential?: boolean;
2018-08-13 11:05:58 -05:00
/**
* 使
*/
requireAdmin?: boolean;
2018-11-14 13:15:42 -06:00
/**
* 使
*/
requireModerator?: boolean;
2018-07-15 13:25:35 -05:00
/**
*
*
* withCredential false
*/
limit?: {
/**
*
*/
key?: string;
/**
* (ms)
* max
*/
duration?: number;
/**
* durationで指定した期間内にいくつまでリクエストできるのか
* duration
*/
max?: number;
/**
* (ms)
*/
minInterval?: number;
};
/**
*
* false
*/
2018-07-24 17:18:50 -05:00
requireFile?: boolean;
2018-07-15 13:25:35 -05:00
/**
*
* false
*/
secure?: boolean;
/**
*
*
*/
kind?: string;
}
2018-07-15 13:43:36 -05:00
export interface IEndpoint {
name: string;
exec: any;
meta: IEndpointMeta;
}
const files = glob.sync('**/*.js', {
cwd: path.resolve(__dirname + '/endpoints/')
});
const endpoints: IEndpoint[] = files.map(f => {
2018-09-01 09:12:51 -05:00
const ep = require(`./endpoints/${f}`);
2018-07-15 13:43:36 -05:00
return {
name: f.replace('.js', ''),
exec: ep.default,
meta: ep.meta || {}
};
});
export default endpoints;