summaryrefslogtreecommitdiff
path: root/src/server/api/endpoints.ts
diff options
context:
space:
mode:
authorsyuilo <syuilotan@yahoo.co.jp>2018-07-16 03:43:36 +0900
committersyuilo <syuilotan@yahoo.co.jp>2018-07-16 03:43:36 +0900
commit1744316656f742dddc6f314aa8bc3289714f1311 (patch)
treefa5c69840097adc70a0f2e3278c52dfacf5efbf1 /src/server/api/endpoints.ts
parent良い感じに (diff)
downloadsharkey-1744316656f742dddc6f314aa8bc3289714f1311.tar.gz
sharkey-1744316656f742dddc6f314aa8bc3289714f1311.tar.bz2
sharkey-1744316656f742dddc6f314aa8bc3289714f1311.zip
良い感じに
Diffstat (limited to 'src/server/api/endpoints.ts')
-rw-r--r--src/server/api/endpoints.ts80
1 files changed, 80 insertions, 0 deletions
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;