Skip to content

Commit

Permalink
Merge pull request #49 from ckcr4lyf/feature/skip-resume
Browse files Browse the repository at this point in the history
Add SKIP_RESUME
  • Loading branch information
ckcr4lyf authored Jul 16, 2024
2 parents 156b68b + 0ad3386 commit f337e03
Show file tree
Hide file tree
Showing 9 changed files with 64 additions and 16 deletions.
2 changes: 1 addition & 1 deletion .npmignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
__mocks__/
__tests__/
.github/
src/
/src/
tests/
.gitignore
.npmignore
Expand Down
4 changes: 4 additions & 0 deletions build/src/racing/completed.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions build/src/utils/config.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 19 additions & 5 deletions build/src/utils/configV2.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package-lock.json → npm-shrinkwrap.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down Expand Up @@ -47,6 +47,6 @@
},
"preferGlobal": true,
"bin": {
"qbit-race": "./bin/index.mjs"
"qbit-race": "bin/index.mjs"
}
}
5 changes: 5 additions & 0 deletions src/racing/completed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
5 changes: 5 additions & 0 deletions src/utils/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,10 @@ export type Settings = {
* Set of category changes to perform on torrent completion
*/
CATEGORY_FINISH_CHANGE: Record<string, string>;
/**
* Whether we should skip resuming paused torrents at the end of a race
*/
SKIP_RESUME: boolean;
}

/**
Expand All @@ -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: {
Expand Down
31 changes: 25 additions & 6 deletions src/utils/configV2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
//
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
}

0 comments on commit f337e03

Please sign in to comment.