Server/project/src/routers/ImageRouter.ts
Refringe 50c7a26a58
ESLint Pass
This is the first pass of ESLint on the codebase.

ESLint formatting is less strict when it comes to line-length and line-breaks then dprint/biome, so if you see formatting that you don't like... fix it! It shouldn't require a configuration change.

- This should merge clean into master (when the time comes).
- This will not merge clean into `3.9.0-DEV`, but the conflicts aren't that bad.
2024-05-07 23:57:08 -04:00

39 lines
1.1 KiB
TypeScript

import { IncomingMessage, ServerResponse } from "node:http";
import { inject, injectable } from "tsyringe";
import { ImageRouteService } from "@spt-aki/services/mod/image/ImageRouteService";
import { HttpFileUtil } from "@spt-aki/utils/HttpFileUtil";
import { VFS } from "@spt-aki/utils/VFS";
@injectable()
export class ImageRouter
{
constructor(
@inject("VFS") protected vfs: VFS,
@inject("ImageRouteService") protected imageRouteService: ImageRouteService,
@inject("HttpFileUtil") protected httpFileUtil: HttpFileUtil,
)
{}
public addRoute(key: string, valueToAdd: string): void
{
this.imageRouteService.addRoute(key, valueToAdd);
}
public sendImage(sessionID: string, req: IncomingMessage, resp: ServerResponse, body: any): void
{
// remove file extension
const url = this.vfs.stripExtension(req.url);
// send image
if (this.imageRouteService.existsByKey(url))
{
this.httpFileUtil.sendFile(resp, this.imageRouteService.getByKey(url));
}
}
public getImage(): string
{
return "IMAGE";
}
}