feature: allow multi-torrent priority change

This commit is contained in:
Jesse Chan
2020-10-04 20:59:30 +08:00
parent 4bd090d0bb
commit 5e1c09153c
9 changed files with 89 additions and 61 deletions
+31
View File
@@ -9,6 +9,7 @@ import type {
CheckTorrentsOptions,
DeleteTorrentsOptions,
MoveTorrentsOptions,
SetTorrentsPriorityOptions,
StartTorrentsOptions,
StopTorrentsOptions,
} from '@shared/types/Action';
@@ -257,6 +258,36 @@ class ClientGatewayService extends BaseService<ClientGatewayServiceEvents> {
}, this.processClientRequestError);
}
/**
* Sets priority of torrents
*
* @param {SetTorrentsPriorityOptions} options - An object of options...
* @return {Promise} - Resolves with RPC call response or rejects with error.
*/
async setTorrentsPriority({hashes, priority}: SetTorrentsPriorityOptions) {
if (this.services == null || this.services.clientRequestManager == null) {
return Promise.reject();
}
const methodCalls = hashes.reduce((accumulator: MultiMethodCalls, hash) => {
accumulator.push({
methodName: 'd.priority.set',
params: [hash, `${priority}`],
});
accumulator.push({
methodName: 'd.update_priorities',
params: [hash],
});
return accumulator;
}, []);
return this.services.clientRequestManager
.methodCall('system.multicall', [methodCalls])
.then(this.processClientRequestSuccess, this.processClientRequestError);
}
/**
* Starts torrents
*