summaryrefslogtreecommitdiff
path: root/src/api/api-handler.ts
diff options
context:
space:
mode:
authortamaina <tamaina@hotmail.co.jp>2018-04-11 20:27:09 +0900
committerGitHub <noreply@github.com>2018-04-11 20:27:09 +0900
commitd43fe853c3605696e2e57e240845d0fc9c284f61 (patch)
tree838914e262c0fca5737588a7bba64e2b9f3d8e5f /src/api/api-handler.ts
parentUpdate README.md (diff)
parentwip #1443 (diff)
downloadmisskey-d43fe853c3605696e2e57e240845d0fc9c284f61.tar.gz
misskey-d43fe853c3605696e2e57e240845d0fc9c284f61.tar.bz2
misskey-d43fe853c3605696e2e57e240845d0fc9c284f61.zip
Merge pull request #1 from syuilo/master
追従
Diffstat (limited to 'src/api/api-handler.ts')
-rw-r--r--src/api/api-handler.ts56
1 files changed, 0 insertions, 56 deletions
diff --git a/src/api/api-handler.ts b/src/api/api-handler.ts
deleted file mode 100644
index fb603a0e2a..0000000000
--- a/src/api/api-handler.ts
+++ /dev/null
@@ -1,56 +0,0 @@
-import * as express from 'express';
-
-import { Endpoint } from './endpoints';
-import authenticate from './authenticate';
-import { IAuthContext } from './authenticate';
-import _reply from './reply';
-import limitter from './limitter';
-
-export default async (endpoint: Endpoint, req: express.Request, res: express.Response) => {
- const reply = _reply.bind(null, res);
- let ctx: IAuthContext;
-
- // Authentication
- try {
- ctx = await authenticate(req);
- } catch (e) {
- return reply(403, 'AUTHENTICATION_FAILED');
- }
-
- if (endpoint.secure && !ctx.isSecure) {
- return reply(403, 'ACCESS_DENIED');
- }
-
- if (endpoint.withCredential && ctx.user == null) {
- return reply(401, 'PLZ_SIGNIN');
- }
-
- if (ctx.app && endpoint.kind) {
- if (!ctx.app.permission.some(p => p === endpoint.kind)) {
- return reply(403, 'ACCESS_DENIED');
- }
- }
-
- if (endpoint.withCredential && endpoint.limit) {
- try {
- await limitter(endpoint, ctx); // Rate limit
- } catch (e) {
- // drop request if limit exceeded
- return reply(429);
- }
- }
-
- let exec = require(`${__dirname}/endpoints/${endpoint.name}`);
-
- if (endpoint.withFile) {
- exec = exec.bind(null, req.file);
- }
-
- // API invoking
- try {
- const res = await exec(req.body, ctx.user, ctx.app, ctx.isSecure);
- reply(res);
- } catch (e) {
- reply(400, e);
- }
-};