Server/project/src/routers/serializers/BundleSerializer.ts

36 lines
1.1 KiB
TypeScript
Raw Normal View History

import { IncomingMessage, ServerResponse } from "node:http";
2023-03-03 15:23:46 +00:00
import { inject, injectable } from "tsyringe";
import { Serializer } from "@spt-aki/di/Serializer";
import { BundleLoader } from "@spt-aki/loaders/BundleLoader";
import { ILogger } from "@spt-aki/models/spt/utils/ILogger";
import { HttpFileUtil } from "@spt-aki/utils/HttpFileUtil";
2023-03-03 15:23:46 +00:00
@injectable()
export class BundleSerializer extends Serializer
{
constructor(
@inject("WinstonLogger") protected logger: ILogger,
@inject("BundleLoader") protected bundleLoader: BundleLoader,
2023-11-15 20:35:05 -05:00
@inject("HttpFileUtil") protected httpFileUtil: HttpFileUtil,
2023-03-03 15:23:46 +00:00
)
{
super();
}
public override serialize(sessionID: string, req: IncomingMessage, resp: ServerResponse, body: any): void
{
this.logger.info(`[BUNDLE]: ${req.url}`);
const key = req.url.split("/bundle/")[1];
const bundle = this.bundleLoader.getBundle(key);
2023-03-03 15:23:46 +00:00
this.httpFileUtil.sendFile(resp, `${bundle.modpath}/bundles/${bundle.filename}`);
2023-03-03 15:23:46 +00:00
}
public override canHandle(route: string): boolean
{
return route === "BUNDLE";
}
2023-11-15 20:35:05 -05:00
}