c3e203922e
This PR is required by SPT-AKI/Modules!104 in order for it to function correctly. ## Overview - Adds the package `buffer-crc32`, it can generate CRC32 hashes from buffers or strings - Splits `HashCacheService` into 2 classes `ModHashCacheService` does exactly the same `HashCacheService` used to do, and added a new `BundleHashCacheService` - `BundleLoader` now generates a CRC32 hash of every bundle file from every loaded mod - Reworked `BundleInfo` to better represent the data expected by the client when requesting `/singleplayer/bundles` - Removes all checks on `BundleLoader` that verified if the request was made to a localhost address, this is now addressed by the client. ## Testing The code has been tested by @Senko-san and me. Co-authored-by: chomp <chomp@noreply.dev.sp-tarkov.com> Reviewed-on: https://dev.sp-tarkov.com/SPT-AKI/Server/pulls/274 Co-authored-by: TheSparta <thesparta@noreply.dev.sp-tarkov.com> Co-committed-by: TheSparta <thesparta@noreply.dev.sp-tarkov.com>
28 lines
823 B
TypeScript
28 lines
823 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);
|
|
});
|
|
}
|
|
}
|