From 4f1d48394846f1f7bc12e4930914116b49fe0a69 Mon Sep 17 00:00:00 2001 From: Raghu Saxena Date: Tue, 16 Jul 2024 18:50:50 +0800 Subject: [PATCH 1/5] Add SKIP_RESUME to config w/ default --- build/src/utils/config.js | 1 + build/src/utils/configV2.js | 24 +++++++++++++++++++----- src/utils/config.ts | 5 +++++ src/utils/configV2.ts | 31 +++++++++++++++++++++++++------ 4 files changed, 50 insertions(+), 11 deletions(-) diff --git a/build/src/utils/config.js b/build/src/utils/config.js index 5c0c5e0..0dec8e5 100644 --- a/build/src/utils/config.js +++ b/build/src/utils/config.js @@ -4,6 +4,7 @@ export const defaultSettings = { PAUSE_RATIO: 1, PAUSE_SKIP_TAGS: ["tracker.linux.org", "some_other_tag"], PAUSE_SKIP_CATEGORIES: ["permaseeding", "some_other_category"], + SKIP_RESUME: false, CONCURRENT_RACES: 1, COUNT_STALLED_DOWNLOADS: false, QBITTORRENT_SETTINGS: { diff --git a/build/src/utils/configV2.js b/build/src/utils/configV2.js index 9944a63..e1f176e 100644 --- a/build/src/utils/configV2.js +++ b/build/src/utils/configV2.js @@ -32,7 +32,7 @@ export const makeConfigIfNotExist = () => { const configDir = getConfigDir(); const logger = getLoggerV3(); // Now check config - const configFilePath = path.join(configDir, 'config.json'); + const configFilePath = getConfigPath(); // Check if config exists try { const stats = fs.statSync(configFilePath); @@ -59,11 +59,25 @@ export const makeConfigIfNotExist = () => { * It's assumed makeConfigIfNotExist() has already been called. */ export const loadConfig = () => { + const logger = getLoggerV3(); const configPath = getConfigPath(); const configData = fs.readFileSync(configPath); - return JSON.parse(configData.toString()); + const parsedConfig = JSON.parse(configData.toString()); + // Check if any keys are missing + const allKeysFromDefault = Object.keys(defaultSettings); + let overwriteConfig = false; + for (const key of allKeysFromDefault) { + if ((key in parsedConfig) === false) { + const defaultValue = defaultSettings[key]; + logger.warn(`Missing key ${key} from current config! Will update with default value (${defaultValue})`); + parsedConfig[key] = defaultValue; + overwriteConfig = true; + } + } + if (overwriteConfig === true) { + logger.info(`Overwriting config for missing keys...`); + fs.writeFileSync(configPath, JSON.stringify(parsedConfig, null, 2)); + } + return parsedConfig; }; -// TODO: Future improvement: -// If an older config, missing keys, then modify it to add the new stuff -// //# sourceMappingURL=configV2.js.map \ No newline at end of file diff --git a/src/utils/config.ts b/src/utils/config.ts index 2f1e66b..f4fe825 100644 --- a/src/utils/config.ts +++ b/src/utils/config.ts @@ -95,6 +95,10 @@ export type Settings = { * Set of category changes to perform on torrent completion */ CATEGORY_FINISH_CHANGE: Record; + /** + * Whether we should skip resuming paused torrents at the end of a race + */ + SKIP_RESUME: boolean; } /** @@ -117,6 +121,7 @@ export const defaultSettings: Settings = { PAUSE_RATIO: 1, PAUSE_SKIP_TAGS: ["tracker.linux.org", "some_other_tag"], PAUSE_SKIP_CATEGORIES: ["permaseeding", "some_other_category"], + SKIP_RESUME: false, CONCURRENT_RACES: 1, COUNT_STALLED_DOWNLOADS: false, QBITTORRENT_SETTINGS: { diff --git a/src/utils/configV2.ts b/src/utils/configV2.ts index 9057f99..f72701e 100644 --- a/src/utils/configV2.ts +++ b/src/utils/configV2.ts @@ -39,7 +39,7 @@ export const makeConfigIfNotExist = () => { const logger = getLoggerV3(); // Now check config - const configFilePath = path.join(configDir, 'config.json'); + const configFilePath = getConfigPath(); // Check if config exists try { @@ -69,11 +69,30 @@ export const makeConfigIfNotExist = () => { * It's assumed makeConfigIfNotExist() has already been called. */ export const loadConfig = (): Settings => { + const logger = getLoggerV3(); const configPath = getConfigPath(); const configData = fs.readFileSync(configPath); - return JSON.parse(configData.toString()); -} -// TODO: Future improvement: -// If an older config, missing keys, then modify it to add the new stuff -// \ No newline at end of file + const parsedConfig = JSON.parse(configData.toString()); + + // Check if any keys are missing + const allKeysFromDefault = Object.keys(defaultSettings); + + let overwriteConfig = false; + + for (const key of allKeysFromDefault){ + if ((key in parsedConfig) === false){ + const defaultValue = defaultSettings[key as keyof Settings]; + logger.warn(`Missing key ${key} from current config! Will update with default value (${defaultValue})`); + parsedConfig[key] = defaultValue; + overwriteConfig = true; + } + } + + if (overwriteConfig === true){ + logger.info(`Overwriting config for missing keys...`); + fs.writeFileSync(configPath, JSON.stringify(parsedConfig, null, 2)); + } + + return parsedConfig +} From a3b3fe37cf82119b5e1765691815c04e2e95c176 Mon Sep 17 00:00:00 2001 From: Raghu Saxena Date: Tue, 16 Jul 2024 18:55:25 +0800 Subject: [PATCH 2/5] Done resume if SKIP_RESUME is true --- build/src/racing/completed.js | 4 ++++ src/racing/completed.ts | 5 +++++ 2 files changed, 9 insertions(+) diff --git a/build/src/racing/completed.js b/build/src/racing/completed.js index 7930a7c..646ba2e 100644 --- a/build/src/racing/completed.js +++ b/build/src/racing/completed.js @@ -67,6 +67,10 @@ export const postRaceResumeV2 = async (api, settings, infohash) => { logger.debug(`Nothing to resume (no paused torrents)`); return; } + if (settings.SKIP_RESUME === true) { + logger.debug(`Skip resume is true, not resuming anything...`); + return; + } // Try and resume try { await api.resumeTorrents(pausedTorrents); diff --git a/src/racing/completed.ts b/src/racing/completed.ts index e71b0a9..09db001 100644 --- a/src/racing/completed.ts +++ b/src/racing/completed.ts @@ -78,6 +78,11 @@ export const postRaceResumeV2 = async (api: QbittorrentApi, settings: Settings, return; } + if (settings.SKIP_RESUME === true){ + logger.debug(`Skip resume is true, not resuming anything...`); + return; + } + // Try and resume try { await api.resumeTorrents(pausedTorrents); From 3a8480c4da765e08c83ed6968401a83c5ec26fd0 Mon Sep 17 00:00:00 2001 From: Raghu Saxena Date: Tue, 16 Jul 2024 18:56:07 +0800 Subject: [PATCH 3/5] Bump to alpha 15 --- package-lock.json | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index f6f5f2b..735239a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "qbit-race", - "version": "2.0.0-alpha.14", + "version": "2.0.0-alpha.15", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "qbit-race", - "version": "2.0.0-alpha.14", + "version": "2.0.0-alpha.15", "license": "ISC", "dependencies": { "@ckcr4lyf/bencode-esm": "^0.0.2", diff --git a/package.json b/package.json index 7cad99c..146f5fa 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "qbit-race", - "version": "2.0.0-alpha.14", + "version": "2.0.0-alpha.15", "description": "Qbit utilities for racing", "main": "./bin/index.js", "type": "module", From e5df6f9d164e6ead89fbf43d1649c5ebc3910cfd Mon Sep 17 00:00:00 2001 From: Raghu Saxena Date: Tue, 16 Jul 2024 19:01:27 +0800 Subject: [PATCH 4/5] Fix npmignore --- .npmignore | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.npmignore b/.npmignore index fcf9936..da33f90 100644 --- a/.npmignore +++ b/.npmignore @@ -1,7 +1,7 @@ __mocks__/ __tests__/ .github/ -src/ +/src/ tests/ .gitignore .npmignore diff --git a/package.json b/package.json index 146f5fa..171c546 100644 --- a/package.json +++ b/package.json @@ -47,6 +47,6 @@ }, "preferGlobal": true, "bin": { - "qbit-race": "./bin/index.mjs" + "qbit-race": "bin/index.mjs" } } From 0ad3386ef09f88d63b0e217e9fe74d383ea669f2 Mon Sep 17 00:00:00 2001 From: Raghu Saxena Date: Tue, 16 Jul 2024 19:01:42 +0800 Subject: [PATCH 5/5] Use shrinkwrap --- package-lock.json => npm-shrinkwrap.json | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename package-lock.json => npm-shrinkwrap.json (100%) diff --git a/package-lock.json b/npm-shrinkwrap.json similarity index 100% rename from package-lock.json rename to npm-shrinkwrap.json