@@ -57,7 +57,19 @@ import {
5757
5858class RTorrentClientGatewayService extends ClientGatewayService {
5959 clientRequestManager = new ClientRequestManager ( this . user . client as RTorrentConnectionSettings ) ;
60- availableMethodCalls = this . fetchAvailableMethodCalls ( true ) ;
60+ availableMethodCalls = this . fetchAvailableMethodCalls ( ) ;
61+
62+ async getPreferredMethod ( methods : string [ ] ) : Promise < string > {
63+ const { methodList} = await this . availableMethodCalls ;
64+
65+ const matchedMethod = methods . find ( ( method ) => methodList . includes ( method ) ) ;
66+
67+ if ( ! matchedMethod ) {
68+ throw new Error ( `None of the requested methods are available: ${ methods . join ( ', ' ) } ` ) ;
69+ }
70+
71+ return matchedMethod ;
72+ }
6173
6274 async appendTorrentCommentCall ( file : string , additionalCalls : string [ ] ) {
6375 const comment = await getComment ( Buffer . from ( file , 'base64' ) ) ;
@@ -106,11 +118,15 @@ class RTorrentClientGatewayService extends ClientGatewayService {
106118 const result : string [ ] = [ ] ;
107119
108120 if ( this . clientRequestManager . isJSONCapable ) {
121+ const methodName = await this . getPreferredMethod (
122+ start ? [ 'load.start_throw' , 'load.start' ] : [ 'load.throw' , 'load.normal' ] ,
123+ ) ;
124+
109125 await this . clientRequestManager
110126 . methodCall ( 'system.multicall' , [
111127 await Promise . all (
112128 processedFiles . map ( async ( file ) => ( {
113- methodName : start ? 'load.start' : 'load.normal' ,
129+ methodName,
114130 params : [
115131 '' ,
116132 `data:applications/x-bittorrent;base64,${ file } ` ,
@@ -159,13 +175,9 @@ class RTorrentClientGatewayService extends ClientGatewayService {
159175 const result : string [ ] = [ ] ;
160176
161177 if ( urls [ 0 ] ) {
162- const methodName = start ? 'load.start' : 'load.normal' ;
163-
164- // if (this.clientRequestManager.isJSONCapable) {
165- // methodName = start ? 'load.start_throw' : 'load.throw';
166- // } else {
167- // methodName = start ? 'load.start' : 'load.normal';
168- // }
178+ const methodName = await this . getPreferredMethod (
179+ start ? [ 'load.start_throw' , 'load.start' ] : [ 'load.throw' , 'load.normal' ] ,
180+ ) ;
169181
170182 await this . clientRequestManager
171183 . methodCall ( 'system.multicall' , [
@@ -789,6 +801,7 @@ class RTorrentClientGatewayService extends ClientGatewayService {
789801 }
790802
791803 async fetchAvailableMethodCalls ( fallback = false ) : Promise < {
804+ methodList : string [ ] ;
792805 clientSetting : string [ ] ;
793806 torrentContent : string [ ] ;
794807 torrentList : string [ ] ;
@@ -828,6 +841,7 @@ class RTorrentClientGatewayService extends ClientGatewayService {
828841 : ( methodCalls : Array < string > ) => methodCalls ;
829842
830843 return {
844+ methodList,
831845 clientSetting : getAvailableMethodCalls ( getMethodCalls ( clientSettingMethodCallConfigs ) ) ,
832846 torrentContent : getAvailableMethodCalls ( getMethodCalls ( torrentContentMethodCallConfigs ) ) ,
833847 torrentList : getAvailableMethodCalls ( getMethodCalls ( torrentListMethodCallConfigs ) ) ,
0 commit comments