mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-12-02 09:22:15 +00:00
chore: move transit backend to proper DI
Includes the quirk-repair pass (upstream timeout + size cap, LRU cache, NaN-duration guard) that maps landed as a sibling fix commit.
This commit is contained in:
@@ -2,7 +2,7 @@ import { Controller, Get, HttpException, Query, Req, UseGuards } from '@nestjs/c
|
||||
import type { Request } from 'express';
|
||||
import { JwtAuthGuard } from '../auth/jwt-auth.guard';
|
||||
import { RateLimitService } from '../auth/rate-limit.service';
|
||||
import * as transit from '../../services/transitService';
|
||||
import { TransitService } from './transit.service';
|
||||
|
||||
const RL_WINDOW = 15 * 60 * 1000;
|
||||
|
||||
@@ -15,7 +15,10 @@ const RL_WINDOW = 15 * 60 * 1000;
|
||||
@Controller('api/transit')
|
||||
@UseGuards(JwtAuthGuard)
|
||||
export class TransitController {
|
||||
constructor(private readonly rl: RateLimitService) {}
|
||||
constructor(
|
||||
private readonly rl: RateLimitService,
|
||||
private readonly transit: TransitService,
|
||||
) {}
|
||||
|
||||
private limit(bucket: string, req: Request, max: number): void {
|
||||
if (!this.rl.check(bucket, req.ip || 'unknown', max, RL_WINDOW, Date.now())) {
|
||||
@@ -38,7 +41,7 @@ export class TransitController {
|
||||
) {
|
||||
this.limit('transit_geocode', req, 300);
|
||||
try {
|
||||
return await transit.geocode(q || '', lang, near);
|
||||
return await this.transit.geocode(q || '', lang, near);
|
||||
} catch (err) { this.rethrow(err); }
|
||||
}
|
||||
|
||||
@@ -54,7 +57,7 @@ export class TransitController {
|
||||
) {
|
||||
this.limit('transit_plan', req, 60);
|
||||
try {
|
||||
return await transit.plan({
|
||||
return await this.transit.plan({
|
||||
from: from || '',
|
||||
to: to || '',
|
||||
time,
|
||||
|
||||
Reference in New Issue
Block a user