Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,13 @@ 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;
Expand Down Expand Up @@ -325,6 +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"),
),
INDEX_CONCURRENCY: parseNumber(resolveEnv("GAMES_INDEX_CONCURRENCY"), 1),
DEFAULT_ARCHIVE_PASSWORD:
resolveEnv("GAMES_DEFAULT_ARCHIVE_PASSWORD") || "Anything",
Expand Down
31 changes: 30 additions & 1 deletion src/modules/games/files.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -724,6 +724,34 @@ 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);
if (shouldExclude) {
this.logger.debug({
message: `Indexer ignoring filename due to exclusion settings.`,
reason: "Excluded by configuration.",
filename,
});
}
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);
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.
Expand All @@ -737,7 +765,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
});

Expand Down