418d9f2a8f
- Ability to use @spt-aki path alias on the whole project. - Swapped all imports from relative paths, for imports using the path alias. Reviewed-on: https://dev.sp-tarkov.com/SPT-AKI/Server/pulls/157 Co-authored-by: TheSparta <thesparta@noreply.dev.sp-tarkov.com> Co-committed-by: TheSparta <thesparta@noreply.dev.sp-tarkov.com>
28 lines
815 B
TypeScript
28 lines
815 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, file: any): void
|
|
{
|
|
const pathSlic = file.split("/");
|
|
const type = this.httpServerHelper.getMimeText(pathSlic[pathSlic.length - 1].split(".").at(-1)) || this.httpServerHelper.getMimeText("txt");
|
|
const fileStream = fs.createReadStream(file);
|
|
|
|
fileStream.on("open", function ()
|
|
{
|
|
resp.setHeader("Content-Type", type);
|
|
fileStream.pipe(resp);
|
|
});
|
|
}
|
|
} |