summaryrefslogtreecommitdiff
path: root/packages/backend/src/server/api/ApiCallService.ts
diff options
context:
space:
mode:
authoranatawa12 <anatawa12@icloud.com>2025-05-11 15:37:46 +0900
committerGitHub <noreply@github.com>2025-05-11 15:37:46 +0900
commitcbc53de8237fdfeee7c81effa819030962fa4b51 (patch)
treec172a78596383ae9cd18315c8a52e2cd1ecba290 /packages/backend/src/server/api/ApiCallService.ts
parentenhance(backend): increase MAX_ROOM_MEMBERS to 50 (diff)
downloadmisskey-cbc53de8237fdfeee7c81effa819030962fa4b51.tar.gz
misskey-cbc53de8237fdfeee7c81effa819030962fa4b51.tar.bz2
misskey-cbc53de8237fdfeee7c81effa819030962fa4b51.zip
fix: RateLimiterService (#13997)
* fix rate limit check never ends * fix: long term / short term limitがないときでもそれぞれ用のnew Limiterとlimiter.getが呼ばれる問題 * refactor: wrap ratelimiter with promise * refactor: reimplement max/min with async * refactor: reimplement limit with async * refactor: do not check long term limit inside min * refactor: check if there is rate limit inside min/max function * refactor: remove unnecessary return in min/max function * refactor: remove unnecessary max/min function * refactor: return rate limit instead of throwing an object * fix: レートリミットのfactorが二回適用されて二乗の効果がある問題を修正 * fix lint error --------- Co-authored-by: Kisaragi <48310258+KisaragiEffective@users.noreply.github.com> Co-authored-by: syuilo <4439005+syuilo@users.noreply.github.com> Co-authored-by: Sayamame-beans <61457993+Sayamame-beans@users.noreply.github.com>
Diffstat (limited to 'packages/backend/src/server/api/ApiCallService.ts')
-rw-r--r--packages/backend/src/server/api/ApiCallService.ts22
1 files changed, 9 insertions, 13 deletions
diff --git a/packages/backend/src/server/api/ApiCallService.ts b/packages/backend/src/server/api/ApiCallService.ts
index a42fdaf730..7a4af407a3 100644
--- a/packages/backend/src/server/api/ApiCallService.ts
+++ b/packages/backend/src/server/api/ApiCallService.ts
@@ -326,19 +326,15 @@ export class ApiCallService implements OnApplicationShutdown {
if (factor > 0) {
// Rate limit
- await this.rateLimiterService.limit(limit as IEndpointMeta['limit'] & { key: NonNullable<string> }, limitActor, factor).catch(err => {
- if ('info' in err) {
- // errはLimiter.LimiterInfoであることが期待される
- throw new ApiError({
- message: 'Rate limit exceeded. Please try again later.',
- code: 'RATE_LIMIT_EXCEEDED',
- id: 'd5826d14-3982-4d2e-8011-b9e9f02499ef',
- httpStatusCode: 429,
- }, err.info);
- } else {
- throw new TypeError('information must be a rate-limiter information.');
- }
- });
+ const rateLimit = await this.rateLimiterService.limit(limit as IEndpointMeta['limit'] & { key: NonNullable<string> }, limitActor, factor);
+ if (rateLimit != null) {
+ throw new ApiError({
+ message: 'Rate limit exceeded. Please try again later.',
+ code: 'RATE_LIMIT_EXCEEDED',
+ id: 'd5826d14-3982-4d2e-8011-b9e9f02499ef',
+ httpStatusCode: 429,
+ }, rateLimit.info);
+ }
}
}