From 77681ee80f9d301eeef9e0d687c99045c550fe61 Mon Sep 17 00:00:00 2001 From: AlmostEasyGoing Date: Tue, 17 Feb 2026 02:09:55 +0100 Subject: [PATCH 1/4] Added file/directory exclusion settings for indexer --- src/configuration.ts | 11 +++++++++++ src/modules/games/files.service.ts | 27 ++++++++++++++++++++++++++- 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/src/configuration.ts b/src/configuration.ts index 66a02bb1..7e480748 100644 --- a/src/configuration.ts +++ b/src/configuration.ts @@ -194,6 +194,15 @@ function parseKibibytesToBytes( return bytes; } +function parseRegExp( + environmentVariable: string, + defaultValue?: RegExp +): RegExp | undefined { + return environmentVariable + ? RegExp(environmentVariable) + : defaultValue +} + function safeHash(value: string | undefined): string | null { if (!value) { return null; @@ -325,6 +334,8 @@ const configuration = { resolveEnv("GAMES_SEARCH_RECURSIVE"), true, ), + SEARCH_EXCLUDE_FILE_REGEX: parseRegExp(resolveEnv("GAMES_SEARCH_EXCLUDE_FILE_REGEX")), + SEARCH_EXCLUDE_DIR_REGEX: parseRegExp(resolveEnv("GAMES_SEARCH_EXCLUDE_DIR_REGEX")), INDEX_CONCURRENCY: parseNumber(resolveEnv("GAMES_INDEX_CONCURRENCY"), 1), DEFAULT_ARCHIVE_PASSWORD: resolveEnv("GAMES_DEFAULT_ARCHIVE_PASSWORD") || "Anything", diff --git a/src/modules/games/files.service.ts b/src/modules/games/files.service.ts index 102a1eec..1b84dc90 100644 --- a/src/modules/games/files.service.ts +++ b/src/modules/games/files.service.ts @@ -724,6 +724,30 @@ export class FilesService implements OnApplicationBootstrap { return checkedGames; } + private shouldIncludeFile(filename: string): boolean { + const shouldExclude = configuration.GAMES.SEARCH_EXCLUDE_FILE_REGEX?.test(filename); + if (shouldExclude) { + this.logger.debug({ + message: `Indexer ignoring filename due to exclusion settings.`, + reason: "Excluded by configuration.", + filename, + }); + } + return this.isValidFilePath(filename) && !shouldExclude; + } + + private shouldIncludeDirectory(dirname: string): boolean { + const shouldExclude = configuration.GAMES.SEARCH_EXCLUDE_DIR_REGEX?.test(dirname); + if (shouldExclude) { + this.logger.debug({ + message: `Indexer ignoring dirname due to exclusion settings.`, + reason: "Excluded by configuration.", + dirname, + }); + } + return !shouldExclude; + } + /** * This method retrieves an array of objects representing game files in the * file system. @@ -737,7 +761,8 @@ export class FilesService implements OnApplicationBootstrap { const stream = readdirp(configuration.VOLUMES.FILES, { type: "files", depth: configuration.GAMES.SEARCH_RECURSIVE ? undefined : 0, - fileFilter: (entry) => this.isValidFilePath(entry.basename), + fileFilter: (entry) => this.shouldIncludeFile(entry.basename), + directoryFilter: (entry) => this.shouldIncludeDirectory(entry.basename), alwaysStat: true, // ensure size is available for integrity checks }); From d3cfc2d394887455a0be042a13437a412a272789 Mon Sep 17 00:00:00 2001 From: AlmostEasyGoing Date: Tue, 17 Feb 2026 02:11:28 +0100 Subject: [PATCH 2/4] Linting changes --- src/configuration.ts | 14 ++++++++------ src/modules/games/files.service.ts | 6 ++++-- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/configuration.ts b/src/configuration.ts index 7e480748..8dc9803e 100644 --- a/src/configuration.ts +++ b/src/configuration.ts @@ -196,11 +196,9 @@ function parseKibibytesToBytes( function parseRegExp( environmentVariable: string, - defaultValue?: RegExp + defaultValue?: RegExp, ): RegExp | undefined { - return environmentVariable - ? RegExp(environmentVariable) - : defaultValue + return environmentVariable ? RegExp(environmentVariable) : defaultValue; } function safeHash(value: string | undefined): string | null { @@ -334,8 +332,12 @@ const configuration = { resolveEnv("GAMES_SEARCH_RECURSIVE"), true, ), - SEARCH_EXCLUDE_FILE_REGEX: parseRegExp(resolveEnv("GAMES_SEARCH_EXCLUDE_FILE_REGEX")), - SEARCH_EXCLUDE_DIR_REGEX: parseRegExp(resolveEnv("GAMES_SEARCH_EXCLUDE_DIR_REGEX")), + SEARCH_EXCLUDE_FILE_REGEX: parseRegExp( + resolveEnv("GAMES_SEARCH_EXCLUDE_FILE_REGEX"), + ), + SEARCH_EXCLUDE_DIR_REGEX: parseRegExp( + resolveEnv("GAMES_SEARCH_EXCLUDE_DIR_REGEX"), + ), INDEX_CONCURRENCY: parseNumber(resolveEnv("GAMES_INDEX_CONCURRENCY"), 1), DEFAULT_ARCHIVE_PASSWORD: resolveEnv("GAMES_DEFAULT_ARCHIVE_PASSWORD") || "Anything", diff --git a/src/modules/games/files.service.ts b/src/modules/games/files.service.ts index 1b84dc90..8cd85789 100644 --- a/src/modules/games/files.service.ts +++ b/src/modules/games/files.service.ts @@ -725,7 +725,8 @@ export class FilesService implements OnApplicationBootstrap { } private shouldIncludeFile(filename: string): boolean { - const shouldExclude = configuration.GAMES.SEARCH_EXCLUDE_FILE_REGEX?.test(filename); + const shouldExclude = + configuration.GAMES.SEARCH_EXCLUDE_FILE_REGEX?.test(filename); if (shouldExclude) { this.logger.debug({ message: `Indexer ignoring filename due to exclusion settings.`, @@ -737,7 +738,8 @@ export class FilesService implements OnApplicationBootstrap { } private shouldIncludeDirectory(dirname: string): boolean { - const shouldExclude = configuration.GAMES.SEARCH_EXCLUDE_DIR_REGEX?.test(dirname); + const shouldExclude = + configuration.GAMES.SEARCH_EXCLUDE_DIR_REGEX?.test(dirname); if (shouldExclude) { this.logger.debug({ message: `Indexer ignoring dirname due to exclusion settings.`, From cc80316338eab6237a3f9b281524bb498eb90db8 Mon Sep 17 00:00:00 2001 From: AlmostEasyGoing Date: Tue, 17 Feb 2026 02:53:44 +0100 Subject: [PATCH 3/4] Small optimization --- src/modules/games/files.service.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/modules/games/files.service.ts b/src/modules/games/files.service.ts index 8cd85789..fd95e9ce 100644 --- a/src/modules/games/files.service.ts +++ b/src/modules/games/files.service.ts @@ -734,7 +734,7 @@ export class FilesService implements OnApplicationBootstrap { filename, }); } - return this.isValidFilePath(filename) && !shouldExclude; + return !shouldExclude && this.isValidFilePath(filename); } private shouldIncludeDirectory(dirname: string): boolean { From d5d168975568bf0a93d42959ea774844e5e367e2 Mon Sep 17 00:00:00 2001 From: AlmostEasyGoing Date: Tue, 17 Feb 2026 03:00:36 +0100 Subject: [PATCH 4/4] Added descriptor comments. --- src/modules/games/files.service.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/modules/games/files.service.ts b/src/modules/games/files.service.ts index fd95e9ce..b13c5ef7 100644 --- a/src/modules/games/files.service.ts +++ b/src/modules/games/files.service.ts @@ -724,6 +724,7 @@ export class FilesService implements OnApplicationBootstrap { return checkedGames; } + /** Checks whether a given filename should be included by the indexer. */ private shouldIncludeFile(filename: string): boolean { const shouldExclude = configuration.GAMES.SEARCH_EXCLUDE_FILE_REGEX?.test(filename); @@ -737,6 +738,7 @@ export class FilesService implements OnApplicationBootstrap { return !shouldExclude && this.isValidFilePath(filename); } + /** Checks whether a given dirname should be included by the indexer. */ private shouldIncludeDirectory(dirname: string): boolean { const shouldExclude = configuration.GAMES.SEARCH_EXCLUDE_DIR_REGEX?.test(dirname);