From cb5282192920360b08dcd7ead2cd606b56268ad3 Mon Sep 17 00:00:00 2001 From: zakary <123845855+zakkarry@users.noreply.github.com> Date: Mon, 23 Oct 2023 17:31:00 -0500 Subject: [PATCH] fix(logging/config): validates config file action methods (#517) will not silently proceed to save if erroneous values are set for action in the config file. - Fixes #478 --- src/action.ts | 10 ++++++++++ src/startup.ts | 2 ++ 2 files changed, 12 insertions(+) diff --git a/src/action.ts b/src/action.ts index c77f964ac..974b10e73 100644 --- a/src/action.ts +++ b/src/action.ts @@ -23,6 +23,16 @@ import { getRuntimeConfig } from "./runtimeConfig.js"; import { Searchee } from "./searchee.js"; import { saveTorrentFile } from "./torrent.js"; import { getTag } from "./utils.js"; +import { CrossSeedError } from "./errors.js"; + +export async function validateAction(): Promise { + const { action } = getRuntimeConfig(); + if (action !== Action.INJECT && action !== Action.SAVE) { + throw new CrossSeedError( + `Action method "${action}" is invalid. Allowed choices are "save" and "inject".` + ); + } +} export async function performAction( newMeta: Metafile, diff --git a/src/startup.ts b/src/startup.ts index 76cfb40fd..d6d8614a1 100644 --- a/src/startup.ts +++ b/src/startup.ts @@ -5,6 +5,7 @@ import { logger } from "./logger.js"; import { getRuntimeConfig } from "./runtimeConfig.js"; import { validateTorrentDir } from "./torrent.js"; import { validateTorznabUrls } from "./torznab.js"; +import { validateAction } from "./action.js"; function validateOptions() { const { @@ -43,6 +44,7 @@ export async function doStartupValidation(): Promise { const downloadClient = getClient(); await Promise.all( [ + validateAction(), validateTorznabUrls(), downloadClient?.validateConfig(), validateTorrentDir(),