blob: bb4e972b8e4af258d01bb4885942b64035db825e (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
|
import { fileURLToPath } from 'url';
import { dirname } from 'path';
import { Context } from 'cafy';
import * as path from 'path';
import * as glob from 'glob';
import { Schema } from '@/misc/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 {
readonly stability?: 'deprecated' | 'experimental' | 'stable';
readonly tags?: ReadonlyArray<string>;
readonly params?: {
readonly [key: string]: Param;
};
readonly errors?: {
readonly [key: string]: {
readonly message: string;
readonly code: string;
readonly id: string;
};
};
readonly res?: Schema;
/**
* このエンドポイントにリクエストするのにユーザー情報が必須か否か
* 省略した場合は false として解釈されます。
*/
readonly requireCredential?: boolean;
/**
* 管理者のみ使えるエンドポイントか否か
*/
readonly requireAdmin?: boolean;
/**
* 管理者またはモデレーターのみ使えるエンドポイントか否か
*/
readonly requireModerator?: boolean;
/**
* エンドポイントのリミテーションに関するやつ
* 省略した場合はリミテーションは無いものとして解釈されます。
* また、withCredential が false の場合はリミテーションを行うことはできません。
*/
readonly limit?: {
/**
* 複数のエンドポイントでリミットを共有したい場合に指定するキー
*/
readonly key?: string;
/**
* リミットを適用する期間(ms)
* このプロパティを設定する場合、max プロパティも設定する必要があります。
*/
readonly duration?: number;
/**
* durationで指定した期間内にいくつまでリクエストできるのか
* このプロパティを設定する場合、duration プロパティも設定する必要があります。
*/
readonly max?: number;
/**
* 最低でもどれくらいの間隔を開けてリクエストしなければならないか(ms)
*/
readonly minInterval?: number;
};
/**
* ファイルの添付を必要とするか否か
* 省略した場合は false として解釈されます。
*/
readonly requireFile?: boolean;
/**
* サードパーティアプリからはリクエストすることができないか否か
* 省略した場合は false として解釈されます。
*/
readonly secure?: boolean;
/**
* エンドポイントの種類
* パーミッションの実現に利用されます。
*/
readonly 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;
|