From db1b53a71876060b788c09e59fd8a6b28176ac52 Mon Sep 17 00:00:00 2001 From: Jesse Chan Date: Wed, 23 Dec 2020 20:25:05 +0800 Subject: [PATCH] server: rTorrent: implement "isSequential" support Requires rTorrent to have "d.down.sequential(.set)" commands --- .../services/rTorrent/clientGatewayService.ts | 24 +++++++++++++++---- .../methodCallConfigs/torrentList.ts | 4 ++++ 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/server/services/rTorrent/clientGatewayService.ts b/server/services/rTorrent/clientGatewayService.ts index 2ccb8e58..5655f908 100644 --- a/server/services/rTorrent/clientGatewayService.ts +++ b/server/services/rTorrent/clientGatewayService.ts @@ -15,6 +15,7 @@ import type { MoveTorrentsOptions, SetTorrentContentsPropertiesOptions, SetTorrentsPriorityOptions, + SetTorrentsSequentialOptions, SetTorrentsTrackersOptions, StartTorrentsOptions, StopTorrentsOptions, @@ -97,6 +98,7 @@ class RTorrentClientGatewayService extends ClientGatewayService { tags, isBasePath, isCompleted, + isSequential, start, }: Required): Promise { await fs.promises.mkdir(destination, {recursive: true}); @@ -149,6 +151,10 @@ class RTorrentClientGatewayService extends ClientGatewayService { additionalCalls.push(`d.custom.set=addtime,${Math.round(Date.now() / 1000)}`); + if (isSequential) { + additionalCalls.push(`d.down.sequential.set=1`); + } + return { methodName: start ? 'load.start' : 'load.normal', params: ['', torrentPath].concat(additionalCalls), @@ -435,9 +441,20 @@ class RTorrentClientGatewayService extends ClientGatewayService { ); } - async setTorrentsSequential(): Promise { - // TODO: not implemented - throw new Error(); + async setTorrentsSequential({hashes, isSequential}: SetTorrentsSequentialOptions): Promise { + const methodCalls: MultiMethodCalls = hashes.map((hash) => ({ + methodName: 'd.down.sequential.set', + params: [hash, isSequential ? '1' : '0'], + })); + + return ( + this.clientRequestManager + .methodCall('system.multicall', [methodCalls]) + .then(this.processClientRequestSuccess, this.processClientRequestError) + .then(() => { + // returns nothing. + }) || Promise.reject() + ); } async setTorrentsTags({hashes, tags}: SetTorrentsTagsOptions): Promise { @@ -608,7 +625,6 @@ class RTorrentClientGatewayService extends ClientGatewayService { processedResponses.map(async (response) => { const torrentProperties: TorrentProperties = { ...response, - isSequential: false, // TODO: not implemented status: getTorrentStatusFromProperties(response), percentComplete: getTorrentPercentCompleteFromProperties(response), eta: getTorrentETAFromProperties(response), diff --git a/server/services/rTorrent/constants/methodCallConfigs/torrentList.ts b/server/services/rTorrent/constants/methodCallConfigs/torrentList.ts index 13693f45..e298c020 100644 --- a/server/services/rTorrent/constants/methodCallConfigs/torrentList.ts +++ b/server/services/rTorrent/constants/methodCallConfigs/torrentList.ts @@ -30,6 +30,10 @@ const torrentListMethodCallConfigs = { methodCall: 'd.is_private=', transformValue: booleanTransformer, }, + isSequential: { + methodCall: 'd.down.sequential=', + transformValue: booleanTransformer, + }, isOpen: { methodCall: 'd.is_open=', transformValue: booleanTransformer,