@@ -26,8 +26,13 @@ type GetTorrentsResponseData = {
2626}
2727
2828type DeleteTorrentResponse = {
29+ data : DeleteTorrentResponseData
30+ }
31+
32+ type DeleteTorrentResponseData = {
2933 data : {
3034 torrent_id : number
35+ info_hash : string
3136 }
3237}
3338
@@ -49,12 +54,13 @@ type UploadTorrentParams = {
4954 file : any
5055}
5156
52- type UploadTorrentResponse = {
53- data : UploadTorrentResponseData
57+ type NewTorrentResponse = {
58+ data : NewTorrentResponseData
5459}
5560
56- type UploadTorrentResponseData = {
61+ type NewTorrentResponseData = {
5762 torrent_id : number
63+ info_hash : string
5864}
5965
6066export class TorrentResource implements IRestResource {
@@ -64,7 +70,7 @@ export class TorrentResource implements IRestResource {
6470 this . client = client ;
6571 }
6672
67- async getTorrent ( infoHash : string ) : Promise < TorrentResponse > {
73+ async getTorrentInfo ( infoHash : string ) : Promise < TorrentResponse > {
6874 return await fetchGet < GetTorrentResponse > (
6975 `${ this . client . apiBaseUrl } /torrent/${ infoHash } `
7076 )
@@ -88,14 +94,14 @@ export class TorrentResource implements IRestResource {
8894 } ) ;
8995 }
9096
91- async deleteTorrent ( infoHash : string ) : Promise < boolean > {
97+ async deleteTorrent ( infoHash : string ) : Promise < DeleteTorrentResponseData > {
9298 return await fetchDelete < any , DeleteTorrentResponse > (
9399 `${ this . client . apiBaseUrl } /torrent/${ infoHash } ` ,
94100 { } ,
95101 { "Authorization" : `Bearer ${ this . client . authToken } ` }
96102 )
97- . then ( ( _res ) => {
98- return Promise . resolve ( true ) ;
103+ . then ( ( res ) => {
104+ return Promise . resolve ( res . data ) ;
99105 } )
100106 . catch ( ( err ) => {
101107 return Promise . reject ( err . response ?. data ?. error ?? err ) ;
@@ -116,7 +122,7 @@ export class TorrentResource implements IRestResource {
116122 } ) ;
117123 }
118124
119- async uploadTorrent ( params : UploadTorrentParams ) : Promise < number > {
125+ async uploadTorrent ( params : UploadTorrentParams ) : Promise < NewTorrentResponseData > {
120126 const formData = new FormData ( ) ;
121127
122128 formData . append ( "title" , params . title ) ;
@@ -125,20 +131,20 @@ export class TorrentResource implements IRestResource {
125131 formData . append ( "tags" , JSON . stringify ( params . tags ) ) ;
126132 formData . append ( "torrent" , params . file ) ;
127133
128- return await fetchPost < UploadTorrentResponse > (
134+ return await fetchPost < NewTorrentResponse > (
129135 `${ this . client . apiBaseUrl } /torrent/upload` ,
130136 formData ,
131137 { "Authorization" : `Bearer ${ this . client . authToken } ` }
132138 )
133139 . then ( ( res ) => {
134- return Promise . resolve ( res . data . torrent_id ) ;
140+ return Promise . resolve ( res . data ) ;
135141 } )
136142 . catch ( ( err ) => {
137143 return Promise . reject ( err . response ?. data ?. error ?? err ) ;
138144 } ) ;
139145 }
140146
141- async downloadTorrent ( infoHash : number ) : Promise < Blob > {
147+ async downloadTorrent ( infoHash : string ) : Promise < Blob > {
142148 return await fetchGetBlob (
143149 `${ this . client . apiBaseUrl } /torrent/download/${ infoHash } `
144150 )
0 commit comments