Skip to content

Commit

Permalink
fix(logging/config): validates config file action methods (cross-seed…
Browse files Browse the repository at this point in the history
…#517)

will not silently proceed to save if erroneous values are set for action
in the config file.

- Fixes cross-seed#478
  • Loading branch information
zakkarry authored Oct 23, 2023
1 parent ae824fc commit cb52821
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<void> {
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,
Expand Down
2 changes: 2 additions & 0 deletions src/startup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -43,6 +44,7 @@ export async function doStartupValidation(): Promise<void> {
const downloadClient = getClient();
await Promise.all<void>(
[
validateAction(),
validateTorznabUrls(),
downloadClient?.validateConfig(),
validateTorrentDir(),
Expand Down

0 comments on commit cb52821

Please sign in to comment.