enhance(server): productionじゃない限りレートリミットを無効に
This commit is contained in:
parent
86e88647fd
commit
ee6e022b2a
1 changed files with 8 additions and 3 deletions
|
@ -4,12 +4,13 @@ import Redis from 'ioredis';
|
||||||
import { DI } from '@/di-symbols.js';
|
import { DI } from '@/di-symbols.js';
|
||||||
import type Logger from '@/logger.js';
|
import type Logger from '@/logger.js';
|
||||||
import { LoggerService } from '@/core/LoggerService.js';
|
import { LoggerService } from '@/core/LoggerService.js';
|
||||||
import type { IEndpointMeta } from './endpoints.js';
|
|
||||||
import { bindThis } from '@/decorators.js';
|
import { bindThis } from '@/decorators.js';
|
||||||
|
import type { IEndpointMeta } from './endpoints.js';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class RateLimiterService {
|
export class RateLimiterService {
|
||||||
private logger: Logger;
|
private logger: Logger;
|
||||||
|
private disabled = false;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
@Inject(DI.redis)
|
@Inject(DI.redis)
|
||||||
|
@ -18,12 +19,16 @@ export class RateLimiterService {
|
||||||
private loggerService: LoggerService,
|
private loggerService: LoggerService,
|
||||||
) {
|
) {
|
||||||
this.logger = this.loggerService.getLogger('limiter');
|
this.logger = this.loggerService.getLogger('limiter');
|
||||||
|
|
||||||
|
if (process.env.NODE_ENV !== 'production') {
|
||||||
|
this.disabled = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@bindThis
|
@bindThis
|
||||||
public limit(limitation: IEndpointMeta['limit'] & { key: NonNullable<string> }, actor: string) {
|
public limit(limitation: IEndpointMeta['limit'] & { key: NonNullable<string> }, actor: string) {
|
||||||
return new Promise<void>((ok, reject) => {
|
return new Promise<void>((ok, reject) => {
|
||||||
if (process.env.NODE_ENV === 'test') ok();
|
if (this.disabled) ok();
|
||||||
|
|
||||||
// Short-term limit
|
// Short-term limit
|
||||||
const min = (): void => {
|
const min = (): void => {
|
||||||
|
|
Loading…
Reference in a new issue