From 97d13433856ea0d410e9e16b05fd1b0c6fa01ae6 Mon Sep 17 00:00:00 2001 From: Chomp Date: Thu, 9 Jan 2025 11:42:17 +0000 Subject: [PATCH] Rewrote image route generation system --- project/src/utils/DatabaseImporter.ts | 29 +++++++++++++++++---------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/project/src/utils/DatabaseImporter.ts b/project/src/utils/DatabaseImporter.ts index 3dc3e11f..649993a6 100644 --- a/project/src/utils/DatabaseImporter.ts +++ b/project/src/utils/DatabaseImporter.ts @@ -1,3 +1,4 @@ +import path from "node:path"; import { ProgramStatics } from "@spt/ProgramStatics"; import { OnLoad } from "@spt/di/OnLoad"; import { ConfigTypes } from "@spt/models/enums/ConfigTypes"; @@ -71,17 +72,7 @@ export class DatabaseImporter implements OnLoad { await this.hydrateDatabase(this.filepath); const imageFilePath = `${this.filepath}images/`; - const directories = await this.fileSystem.getDirectories(imageFilePath); - await this.loadImagesAsync(imageFilePath, directories, [ - "/files/achievement/", - "/files/CONTENT/banners/", - "/files/handbook/", - "/files/Hideout/", - "/files/launcher/", - "/files/prestige/", - "/files/quest/icon/", - "/files/trader/avatar/", - ]); + await this.createRouteMappingAsync(imageFilePath, "files"); } /** @@ -139,6 +130,7 @@ export class DatabaseImporter implements OnLoad { } /** + * @deprecated * Find and map files with image router inside a designated path * @param filepath Path to find files in */ @@ -166,6 +158,21 @@ export class DatabaseImporter implements OnLoad { this.imageRouter.addRoute("/favicon.ico", `${filepath}icon.ico`); } + /** + * Add routes into imageRouter + * @param directory Directory with files to add to router + * @param newBasePath new starting path + */ + public async createRouteMappingAsync(directory: string, newBasePath: string): Promise { + const directoryContent = await this.fileSystem.getFiles(directory, true); + + for (const fileNameWithPath of directoryContent) { + const bsgPath = `/${newBasePath}/${FileSystem.stripExtension(fileNameWithPath)}`; + const sptPath = `${directory}${fileNameWithPath}`; + this.imageRouter.addRoute(bsgPath, sptPath); + } + } + /** * Check for a path override in the http json config file * @param imagePath Key