server: qBittorrent: set tags after removing all existing tags

APIs of qBittorrent (removeTags, addTags) are incremental. However,
currently it is being used to "set" tags. As a result, tags are never
removed.

This change removes all existing tags before adding new set of tags
in order to simulate the idempotent set function.
This commit is contained in:
Lucas Winther
2020-11-20 17:01:39 +01:00
committed by Jesse Chan
parent f1b6d31a1e
commit a5de58593b
2 changed files with 19 additions and 3 deletions
@@ -179,9 +179,11 @@ class QBittorrentClientGatewayService extends ClientGatewayService {
}
async setTorrentsTags({hashes, tags}: SetTorrentsTagsOptions): Promise<void> {
return this.clientRequestManager
.torrentsAddTags(hashes, tags)
.then(this.processClientRequestSuccess, this.processClientRequestError);
return this.clientRequestManager.torrentsRemoveTags(hashes).then(() => {
this.clientRequestManager
.torrentsAddTags(hashes, tags)
.then(this.processClientRequestSuccess, this.processClientRequestError);
});
}
async setTorrentsTrackers({hashes, trackers}: SetTorrentsTrackersOptions): Promise<void> {
@@ -253,6 +253,20 @@ class ClientRequestManager {
});
}
async torrentsRemoveTags(hashes: Array<string>, tags?: Array<string>): Promise<void> {
return axios
.get(`${this.apiBase}/torrents/removeTags`, {
params: {
hashes: hashes.join('|'),
tags: tags?.join(','),
},
headers: {Cookie: await this.authCookie},
})
.then(() => {
// returns nothing
});
}
async torrentsAddTrackers(hash: string, urls: Array<string>): Promise<void> {
return axios
.get(`${this.apiBase}/torrents/addTrackers?hash=${hash}&urls=${urls.join('|')}`, {