Server/project/src/callbacks/BundleCallbacks.ts
TheSparta c3e203922e bundle-crc-cache (!274)
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>
2024-03-29 18:43:36 +00:00

36 lines
1.1 KiB
TypeScript

import { inject, injectable } from "tsyringe";
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 { ConfigServer } from "@spt-aki/servers/ConfigServer";
import { HttpResponseUtil } from "@spt-aki/utils/HttpResponseUtil";
@injectable()
export class BundleCallbacks
{
protected httpConfig: IHttpConfig;
constructor(
@inject("HttpResponseUtil") protected httpResponse: HttpResponseUtil,
@inject("BundleLoader") protected bundleLoader: BundleLoader,
@inject("ConfigServer") protected configServer: ConfigServer,
)
{
this.httpConfig = this.configServer.getConfig(ConfigTypes.HTTP);
}
/**
* Handle singleplayer/bundles
*/
public getBundles(url: string, info: any, sessionID: string): string
{
return this.httpResponse.noBody(this.bundleLoader.getBundles());
}
public getBundle(url: string, info: any, sessionID: string): string
{
return "BUNDLE";
}
}