2023-03-03 15:23:46 +00:00
|
|
|
import { inject, injectable } from "tsyringe";
|
|
|
|
|
2023-10-19 17:21:17 +00:00
|
|
|
import { BundleLoader } from "@spt-aki/loaders/BundleLoader";
|
|
|
|
import { ConfigTypes } from "@spt-aki/models/enums/ConfigTypes";
|
|
|
|
import { IHttpConfig } from "@spt-aki/models/spt/config/IHttpConfig";
|
|
|
|
import { ILogger } from "@spt-aki/models/spt/utils/ILogger";
|
|
|
|
import { ConfigServer } from "@spt-aki/servers/ConfigServer";
|
|
|
|
import { HttpFileUtil } from "@spt-aki/utils/HttpFileUtil";
|
|
|
|
import { HttpResponseUtil } from "@spt-aki/utils/HttpResponseUtil";
|
2023-03-03 15:23:46 +00:00
|
|
|
|
|
|
|
@injectable()
|
|
|
|
export class BundleCallbacks
|
|
|
|
{
|
|
|
|
protected httpConfig: IHttpConfig;
|
|
|
|
|
|
|
|
constructor(
|
|
|
|
@inject("WinstonLogger") protected logger: ILogger,
|
|
|
|
@inject("HttpResponseUtil") protected httpResponse: HttpResponseUtil,
|
|
|
|
@inject("HttpFileUtil") protected httpFileUtil: HttpFileUtil,
|
|
|
|
@inject("BundleLoader") protected bundleLoader: BundleLoader,
|
|
|
|
@inject("ConfigServer") protected configServer: ConfigServer
|
|
|
|
)
|
|
|
|
{
|
|
|
|
this.httpConfig = this.configServer.getConfig(ConfigTypes.HTTP);
|
|
|
|
}
|
|
|
|
|
|
|
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
|
|
public sendBundle(sessionID: string, req: any, resp: any, body: any): any
|
|
|
|
{
|
|
|
|
this.logger.info(`[BUNDLE]: ${req.url}`);
|
|
|
|
|
|
|
|
const key = req.url.split("/bundle/")[1];
|
|
|
|
const bundle = this.bundleLoader.getBundle(key, true);
|
|
|
|
|
|
|
|
// send bundle
|
|
|
|
this.httpFileUtil.sendFile(resp, bundle.path);
|
|
|
|
}
|
|
|
|
|
2023-07-15 10:56:00 +01:00
|
|
|
/**
|
|
|
|
* Handle singleplayer/bundles
|
|
|
|
*/
|
2023-03-03 15:23:46 +00:00
|
|
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
|
|
public getBundles(url: string, info: any, sessionID: string): string
|
|
|
|
{
|
|
|
|
const local = (this.httpConfig.ip === "127.0.0.1" || this.httpConfig.ip === "localhost");
|
|
|
|
return this.httpResponse.noBody(this.bundleLoader.getBundles(local));
|
|
|
|
}
|
|
|
|
|
|
|
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
|
|
public getBundle(url: string, info: any, sessionID: string): string
|
|
|
|
{
|
|
|
|
return "BUNDLE";
|
|
|
|
}
|
|
|
|
}
|