refactoring

Resolve #7779
This commit is contained in:
syuilo 2021-11-12 02:02:25 +09:00
parent 037837b551
commit 0e4a111f81
1714 changed files with 20803 additions and 11751 deletions

View file

@ -0,0 +1,124 @@
import { fileURLToPath } from 'url';
import { dirname } from 'path';
import { Context } from 'cafy';
import * as path from 'path';
import * as glob from 'glob';
import { SimpleSchema } from '@/misc/simple-schema';
//const _filename = fileURLToPath(import.meta.url);
const _filename = __filename;
const _dirname = dirname(_filename);
export type Param = {
validator: Context<any>;
transform?: any;
default?: any;
deprecated?: boolean;
ref?: string;
};
export interface IEndpointMeta {
stability?: string; //'deprecated' | 'experimental' | 'stable';
tags?: string[];
params?: {
[key: string]: Param;
};
errors?: {
[key: string]: {
message: string;
code: string;
id: string;
};
};
res?: SimpleSchema;
/**
*
* false
*/
requireCredential?: boolean;
/**
* 使
*/
requireAdmin?: boolean;
/**
* 使
*/
requireModerator?: boolean;
/**
*
*
* withCredential false
*/
limit?: {
/**
*
*/
key?: string;
/**
* (ms)
* max
*/
duration?: number;
/**
* durationで指定した期間内にいくつまでリクエストできるのか
* duration
*/
max?: number;
/**
* (ms)
*/
minInterval?: number;
};
/**
*
* false
*/
requireFile?: boolean;
/**
*
* false
*/
secure?: boolean;
/**
*
*
*/
kind?: string;
}
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 => {
const ep = require(`./endpoints/${f}`);
return {
name: f.replace('.js', ''),
exec: ep.default,
meta: ep.meta || {}
};
});
export default endpoints;