1
1
mirror of https://github.com/kokonect-link/cherrypick synced 2024-11-02 08:05:58 +09:00
cherrypick/src/server/api/endpoints.ts

94 lines
2.2 KiB
TypeScript
Raw Normal View History

2018-07-16 03:43:36 +09:00
import * as path from 'path';
import * as glob from 'glob';
2018-07-16 03:25:35 +09:00
2018-07-16 03:43:36 +09:00
export interface IEndpointMeta {
2018-10-22 05:16:27 +09:00
stability?: 'deprecated' | 'experimental' | 'stable';
2018-07-16 03:53:03 +09:00
desc?: any;
params?: any;
res?: any;
2018-07-16 03:25:35 +09:00
/**
*
* false
*/
requireCredential?: boolean;
2018-08-14 01:05:58 +09:00
/**
* 使
*/
requireAdmin?: boolean;
2018-07-16 03:25:35 +09:00
/**
*
*
* withCredential false
*/
limit?: {
/**
*
*/
key?: string;
/**
* (ms)
* max
*/
duration?: number;
/**
* durationで指定した期間内にいくつまでリクエストできるのか
* duration
*/
max?: number;
/**
* (ms)
*/
minInterval?: number;
};
/**
*
* false
*/
2018-07-25 07:18:50 +09:00
requireFile?: boolean;
2018-07-16 03:25:35 +09:00
/**
*
* false
*/
secure?: boolean;
/**
*
*
*/
kind?: string;
}
2018-07-16 03:43:36 +09: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 23:12:51 +09:00
const ep = require(`./endpoints/${f}`);
2018-07-16 03:43:36 +09:00
return {
name: f.replace('.js', ''),
exec: ep.default,
meta: ep.meta || {}
};
});
export default endpoints;