revert un-needed changes to RateLimiterService

This commit is contained in:
Hazelnoot 2024-12-08 07:47:52 -05:00
parent f6b256620b
commit fc5399a67d

View file

@ -10,29 +10,29 @@ 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 { bindThis } from '@/decorators.js'; import { bindThis } from '@/decorators.js';
import type { LimitInfo } from '@/server/api/SkRateLimiterService.js';
import { EnvService } from '@/core/EnvService.js';
import type { IEndpointMeta } from './endpoints.js'; import type { IEndpointMeta } from './endpoints.js';
/** @deprecated Use SkRateLimiterService instead */ /** @deprecated Use SkRateLimiterService instead */
@Injectable() @Injectable()
export class RateLimiterService { export class RateLimiterService {
protected readonly logger: Logger; private logger: Logger;
protected readonly disabled: boolean; private disabled = false;
constructor( constructor(
@Inject(DI.redis) @Inject(DI.redis)
protected readonly redisClient: Redis.Redis, private redisClient: Redis.Redis,
private loggerService: LoggerService, private loggerService: LoggerService,
envService: EnvService,
) { ) {
this.logger = this.loggerService.getLogger('limiter'); this.logger = this.loggerService.getLogger('limiter');
this.disabled = envService.env.NODE_ENV !== 'production';
if (process.env.NODE_ENV !== 'production') {
this.disabled = true;
}
} }
@bindThis @bindThis
public limit(limitation: IEndpointMeta['limit'] & { key: NonNullable<string> }, actor: string, factor = 1): Promise<LimitInfo | void> { public limit(limitation: IEndpointMeta['limit'] & { key: NonNullable<string> }, actor: string, factor = 1) {
return new Promise<void>((ok, reject) => { return new Promise<void>((ok, reject) => {
if (this.disabled) ok(); if (this.disabled) ok();