refactor: reimplement limit with async
This commit is contained in:
parent
1d6d90d62d
commit
b3561ce425
|
@ -43,9 +43,9 @@ export class RateLimiterService {
|
||||||
}
|
}
|
||||||
|
|
||||||
@bindThis
|
@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) {
|
if (this.disabled) {
|
||||||
return Promise.resolve();
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Short-term limit
|
// Short-term limit
|
||||||
|
@ -97,11 +97,11 @@ export class RateLimiterService {
|
||||||
typeof limitation.max === 'number';
|
typeof limitation.max === 'number';
|
||||||
|
|
||||||
if (hasShortTermLimit) {
|
if (hasShortTermLimit) {
|
||||||
return min();
|
await min();
|
||||||
} else if (hasLongTermLimit) {
|
} else if (hasLongTermLimit) {
|
||||||
return max();
|
await max();
|
||||||
} else {
|
} else {
|
||||||
return Promise.resolve();
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue