0
0
mirror of https://github.com/sp-tarkov/server.git synced 2025-02-13 09:50:43 -05:00
server/project/src/utils/HttpFileUtil.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

27 lines
820 B
TypeScript

import fs from "node:fs";
import { ServerResponse } from "node:http";
import { inject, injectable } from "tsyringe";
import { HttpServerHelper } from "@spt-aki/helpers/HttpServerHelper";
@injectable()
export class HttpFileUtil
{
constructor(@inject("HttpServerHelper") protected httpServerHelper: HttpServerHelper)
{
}
public sendFile(resp: ServerResponse, filePath: string): void
{
const pathSlic = filePath.split("/");
const type = this.httpServerHelper.getMimeText(pathSlic[pathSlic.length - 1].split(".").at(-1))
|| this.httpServerHelper.getMimeText("txt");
const fileStream = fs.createReadStream(filePath);
fileStream.on("open", () =>
{
resp.setHeader("Content-Type", type);
fileStream.pipe(resp);
});
}
}