Update ApiCallService.ts

This commit is contained in:
syuilo 2024-09-21 20:36:04 +09:00
parent 23cd0c76d1
commit 6b2076c090
1 changed files with 6 additions and 6 deletions

View File

@ -13,8 +13,7 @@ import { getIpHash } from '@/misc/get-ip-hash.js';
import type { MiLocalUser, MiUser } from '@/models/User.js'; import type { MiLocalUser, MiUser } from '@/models/User.js';
import type { MiAccessToken } from '@/models/AccessToken.js'; import type { MiAccessToken } from '@/models/AccessToken.js';
import type Logger from '@/logger.js'; import type Logger from '@/logger.js';
import type { UserIpsRepository } from '@/models/_.js'; import type { MiMeta, UserIpsRepository } from '@/models/_.js';
import { MetaService } from '@/core/MetaService.js';
import { createTemp } from '@/misc/create-temp.js'; import { createTemp } from '@/misc/create-temp.js';
import { bindThis } from '@/decorators.js'; import { bindThis } from '@/decorators.js';
import { RoleService } from '@/core/RoleService.js'; import { RoleService } from '@/core/RoleService.js';
@ -40,13 +39,15 @@ export class ApiCallService implements OnApplicationShutdown {
private userIpHistoriesClearIntervalId: NodeJS.Timeout; private userIpHistoriesClearIntervalId: NodeJS.Timeout;
constructor( constructor(
@Inject(DI.meta)
private meta: MiMeta,
@Inject(DI.config) @Inject(DI.config)
private config: Config, private config: Config,
@Inject(DI.userIpsRepository) @Inject(DI.userIpsRepository)
private userIpsRepository: UserIpsRepository, private userIpsRepository: UserIpsRepository,
private metaService: MetaService,
private authenticateService: AuthenticateService, private authenticateService: AuthenticateService,
private rateLimiterService: RateLimiterService, private rateLimiterService: RateLimiterService,
private roleService: RoleService, private roleService: RoleService,
@ -265,9 +266,8 @@ export class ApiCallService implements OnApplicationShutdown {
} }
@bindThis @bindThis
private async logIp(request: FastifyRequest, user: MiLocalUser) { private logIp(request: FastifyRequest, user: MiLocalUser) {
const meta = await this.metaService.fetch(); if (!this.meta.enableIpLogging) return;
if (!meta.enableIpLogging) return;
const ip = request.ip; const ip = request.ip;
const ips = this.userIpHistories.get(user.id); const ips = this.userIpHistories.get(user.id);
if (ips == null || !ips.has(ip)) { if (ips == null || !ips.has(ip)) {