From 1744316656f742dddc6f314aa8bc3289714f1311 Mon Sep 17 00:00:00 2001 From: syuilo Date: Mon, 16 Jul 2018 03:43:36 +0900 Subject: 良い感じに MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/server/api/endpoints.ts | 80 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 src/server/api/endpoints.ts (limited to 'src/server/api/endpoints.ts') diff --git a/src/server/api/endpoints.ts b/src/server/api/endpoints.ts new file mode 100644 index 0000000000..cc9b90d6fc --- /dev/null +++ b/src/server/api/endpoints.ts @@ -0,0 +1,80 @@ +import * as path from 'path'; +import * as glob from 'glob'; + +export interface IEndpointMeta { + /** + * このエンドポイントにリクエストするのにユーザー情報が必須か否か + * 省略した場合は false として解釈されます。 + */ + requireCredential?: boolean; + + /** + * エンドポイントのリミテーションに関するやつ + * 省略した場合はリミテーションは無いものとして解釈されます。 + * また、withCredential が false の場合はリミテーションを行うことはできません。 + */ + limit?: { + + /** + * 複数のエンドポイントでリミットを共有したい場合に指定するキー + */ + key?: string; + + /** + * リミットを適用する期間(ms) + * このプロパティを設定する場合、max プロパティも設定する必要があります。 + */ + duration?: number; + + /** + * durationで指定した期間内にいくつまでリクエストできるのか + * このプロパティを設定する場合、duration プロパティも設定する必要があります。 + */ + max?: number; + + /** + * 最低でもどれくらいの間隔を開けてリクエストしなければならないか(ms) + */ + minInterval?: number; + }; + + /** + * ファイルの添付を必要とするか否か + * 省略した場合は false として解釈されます。 + */ + withFile?: 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; -- cgit v1.2.3-freya