refactor: reimplement limit with async

This commit is contained in:
anatawa12 2024-06-14 17:34:01 +09:00
parent 1d6d90d62d
commit b3561ce425
No known key found for this signature in database
GPG Key ID: 9CA909848B8E4EA6
1 changed files with 5 additions and 5 deletions

View File

@ -43,9 +43,9 @@ export class RateLimiterService {
}
@bindThis
public limit(limitation: IEndpointMeta['limit'] & { key: NonNullable<string> }, actor: string, factor = 1) {
public async limit(limitation: IEndpointMeta['limit'] & { key: NonNullable<string> }, actor: string, factor = 1) {
if (this.disabled) {
return Promise.resolve();
return;
}
// Short-term limit
@ -97,11 +97,11 @@ export class RateLimiterService {
typeof limitation.max === 'number';
if (hasShortTermLimit) {
return min();
await min();
} else if (hasLongTermLimit) {
return max();
await max();
} else {
return Promise.resolve();
return;
}
}
}