Michael-128 / qBitControl

qBittorrent remote client for iOS devices.
https://x.com/qbitcontrol
GNU General Public License v3.0
196 stars 9 forks source link

[BUG] Categories do not load when a category has `download_path` set to No #16

Closed narenh closed 3 months ago

narenh commented 4 months ago

Describe the bug If any one of your categories has "Use another path for incomplete torrents" set to No (as opposed to Default or Yes), no categories will load in the app.

To Reproduce Steps to reproduce the behavior:

  1. Edit your categories in Qbittorrent to make one with "use another path" set to No
  2. Add a torrent with the app
  3. See that no categories appear

Expected behavior Categories should appear

Screenshots If applicable, add screenshots to help explain your problem.

Smartphone (please complete the following information):

Additional context In func requestCategoriesJSON(), JSONDecoder expects [String: [String: String]]. However, download_path is returned as a Boolean false if "use another path" is set to No. If "use another path" is set to Yes, then download_path is a string containing the alternate download path.

This seems like poor API design on Qbittorrent's part, so I imagine a solution will have to work around this.

narenh commented 4 months ago
struct Category: Decodable {
    let name: String
    let savePath: String
}

could be a fix. I don't think qBitControl needs access to download_path since that's all handled by Qbittorrent so defining this type and then ignoring the download_path key when decoding should fix the issue. The other nice thing is using a struct like this should remove the need for categoriesArr and categoriesPaths which seems kinda messy.

Michael-128 commented 3 months ago

Thank you for fixing the bugs and simplifying the code! It seems that the "Use another path for incomplete torrents" option is not available in the WebUI, so I never noticed, as I use a headless version of qBittorrent on my server.

Regarding the optimization you mentioned in #17, creating a CategoryManager is indeed a good idea. However, there is another method that could be effective. In the WebUI, all changes are fetched from /api/v2/sync/maindata, which prevents the same data from being fetched repeatedly. When I created this app, I wasn't aware of this method. I plan to implement it in the future, but it will be tricky and require a lot of changes.