fedarovich / qbittorrent-net-client

qBittorrent client library for .Net
MIT License
36 stars 14 forks source link

Wrong internal validation for hashes parameter. #21

Open thytrherfvsefasfd443sf opened 1 year ago

thytrherfvsefasfd443sf commented 1 year ago

I guess it may also be due to a recent API change on the QB side, but this library currently wrongly throws an exception if multiple hashes are passed as specified by the QB API.

https://github.com/qbittorrent/qBittorrent/wiki/WebUI-API-(qBittorrent-4.1)#resume-torrents

Parameter | Type | Description -- | -- | -- hashes | string | The hashes of the torrents you want to resume. hashes can contain multiple hashes separated by \|, to resume multiple torrents, or set to all, to resume all torrents.
    public Task ResumeAsync(
        string hash,
        CancellationToken token = default)
    {
        ValidateHash(hash); <---------
        return PostAsync(p => p.Resume(new[] {hash}), token);
    }
thytrherfvsefasfd443sf commented 1 year ago

Delete torrent has the same problem, and probably there are more. This is a serious problem that needs to be fixed soon. A quick solution would be just removing the validation. It seems to me that it is very unlikely that the user of this library would pass a malformed hash value, and even if he does, he would realise it when the API fails.

fedarovich commented 1 year ago

For DeleteAsync, there is actually an overload that accepts an IEnumerable of hashes. However, you are right that the similar overloads are missing for PauseAsync and ResumeAsync. I can add them when I have some time.

Alternatively, you can create a pull request for these methods and corresponding unit tests. They should look like:

public Task ResumeAsync(
    IEnumerable<string> hashes,
    CancellationToken token = default)
{
    ValidateHashes(ref hashes);
    return PostAsync(p => p.Resume(hashes), token);
}

The methods should also be added to the IQBittorrentClient2 interface.