Server/project/src/routers/ImageRouter.ts

39 lines
1.1 KiB
TypeScript
Raw Normal View History

import { IncomingMessage, ServerResponse } from "node:http";
2023-03-03 16:23:46 +01:00
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";
2023-03-03 16:23:46 +01:00
@injectable()
export class ImageRouter
{
constructor(
@inject("VFS") protected vfs: VFS,
@inject("ImageRouteService") protected imageRouteService: ImageRouteService,
2023-11-16 02:35:05 +01:00
@inject("HttpFileUtil") protected httpFileUtil: HttpFileUtil,
2023-03-03 16:23:46 +01:00
)
2023-11-16 02:35:05 +01:00
{}
2023-03-03 16:23:46 +01:00
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";
}
2023-11-16 02:35:05 +01:00
}