From 2328ddf9a37f561a58a1ac1b32551c57722b951c Mon Sep 17 00:00:00 2001 From: syuilo Date: Fri, 21 Jan 2022 17:15:14 +0900 Subject: [PATCH] refactor --- packages/backend/src/server/api/call.ts | 2 +- packages/backend/src/server/api/limiter.ts | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/backend/src/server/api/call.ts b/packages/backend/src/server/api/call.ts index 36aadb532..399ee65bd 100644 --- a/packages/backend/src/server/api/call.ts +++ b/packages/backend/src/server/api/call.ts @@ -1,5 +1,5 @@ import { performance } from 'perf_hooks'; -import limiter from './limiter'; +import { limiter } from './limiter'; import { User } from '@/models/entities/user'; import endpoints from './endpoints'; import { ApiError } from './error'; diff --git a/packages/backend/src/server/api/limiter.ts b/packages/backend/src/server/api/limiter.ts index 5f617771e..4721f6263 100644 --- a/packages/backend/src/server/api/limiter.ts +++ b/packages/backend/src/server/api/limiter.ts @@ -7,8 +7,8 @@ import Logger from '@/services/logger'; const logger = new Logger('limiter'); -export default (endpoint: IEndpoint, user: User) => new Promise((ok, reject) => { - const limitation = endpoint.meta.limit!; +export const limiter = (endpoint: IEndpoint & { meta: { limit: NonNullable } }, user: User) => new Promise((ok, reject) => { + const limitation = endpoint.meta.limit; const key = Object.prototype.hasOwnProperty.call(limitation, 'key') ? limitation.key @@ -30,7 +30,7 @@ export default (endpoint: IEndpoint, user: User) => new Promise((ok, rejec } // Short-term limit - function min() { + function min(): void { const minIntervalLimiter = new Limiter({ id: `${user.id}:${key}:min`, duration: limitation.minInterval, @@ -58,7 +58,7 @@ export default (endpoint: IEndpoint, user: User) => new Promise((ok, rejec } // Long term limit - function max() { + function max(): void { const limiter = new Limiter({ id: `${user.id}:${key}`, duration: limitation.duration,