mirror of
https://github.com/kikootwo/ReadMeABook.git
synced 2026-06-03 04:40:09 +00:00
Fix qBittorrent category save path not updating when config changes
Previously, when a user changed the download_dir setting after initial setup, the qBittorrent category "readmeabook" would retain the old save path. This could cause torrents to download to the wrong location, depending on qBittorrent's Automatic Torrent Management (ATM) settings. Root cause: - ensureCategory() only created the category if it didn't exist - createCategory API is idempotent but doesn't update existing categories - If download_dir changed from /downloads to /downloads/RMAB, category would still have savePath=/downloads qBittorrent behavior: - If ATM enabled: category savePath overrides per-torrent savepath - If ATM disabled: per-torrent savepath takes precedence Fix: - ensureCategory() now calls both createCategory AND editCategory - createCategory: ensures category exists (idempotent) - editCategory: updates save path to match current download_dir config - This guarantees category path is always synced with database config Benefits: - Users can change download_dir setting and it takes effect immediately - Works regardless of ATM settings in qBittorrent - No manual qBittorrent category management needed Updated documentation/phase3/qbittorrent.md to explain category management and save path synchronization.
This commit is contained in:
@@ -369,7 +369,8 @@ export class QBittorrentService {
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensure category exists in qBittorrent
|
||||
* Ensure category exists in qBittorrent with correct save path
|
||||
* Always updates the category's save path to match current config
|
||||
*/
|
||||
private async ensureCategory(category: string): Promise<void> {
|
||||
if (!this.cookie) {
|
||||
@@ -377,7 +378,7 @@ export class QBittorrentService {
|
||||
}
|
||||
|
||||
try {
|
||||
// Create category (this is idempotent - won't fail if it already exists)
|
||||
// Try to create category first (idempotent - won't fail if exists)
|
||||
await this.client.post(
|
||||
'/torrents/createCategory',
|
||||
new URLSearchParams({
|
||||
@@ -392,11 +393,34 @@ export class QBittorrentService {
|
||||
}
|
||||
);
|
||||
|
||||
console.log(`[qBittorrent] Category "${category}" ensured`);
|
||||
console.log(`[qBittorrent] Category "${category}" created/exists`);
|
||||
} catch (error) {
|
||||
// Ignore errors - category might already exist
|
||||
// Category might already exist - that's OK
|
||||
console.log(`[qBittorrent] Category creation returned:`, error);
|
||||
}
|
||||
|
||||
// Always update the category's save path to ensure it matches current config
|
||||
// This handles cases where download_dir was changed after category was created
|
||||
try {
|
||||
await this.client.post(
|
||||
'/torrents/editCategory',
|
||||
new URLSearchParams({
|
||||
category,
|
||||
savePath: this.defaultSavePath,
|
||||
}),
|
||||
{
|
||||
headers: {
|
||||
Cookie: this.cookie,
|
||||
'Content-Type': 'application/x-www-form-urlencoded',
|
||||
},
|
||||
}
|
||||
);
|
||||
|
||||
console.log(`[qBittorrent] Category "${category}" save path updated to: ${this.defaultSavePath}`);
|
||||
} catch (error) {
|
||||
console.warn(`[qBittorrent] Failed to update category save path:`, error);
|
||||
// Don't throw - torrents can still be added with per-torrent savepath parameter
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user