Server/project/src/routers/ImageRouter.ts

33 lines
1.1 KiB
TypeScript
Raw Normal View History

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