jormungandr-bite/src/server/api/endpoints.ts

121 lines
2.7 KiB
TypeScript
Raw Normal View History

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