@@ -12,6 +12,7 @@ type GetTorrentsParams = {
12
12
page : number
13
13
sorting : string
14
14
categories ?: Array < string >
15
+ tags ?: Array < string >
15
16
searchQuery ?: string
16
17
}
17
18
@@ -30,6 +31,12 @@ type DeleteTorrentResponse = {
30
31
}
31
32
}
32
33
34
+ type UpdateTorrentParams = {
35
+ title ?: string
36
+ description ?: string
37
+ tags ?: number [ ]
38
+ }
39
+
33
40
type UpdateTorrentResponse = {
34
41
data : Torrent
35
42
}
@@ -50,20 +57,16 @@ type UploadTorrentResponseData = {
50
57
torrent_id : number
51
58
}
52
59
53
- type GetTagsResponse = {
54
- data : Array < TorrentTag >
55
- }
56
-
57
60
export class TorrentResource implements IRestResource {
58
61
client : Rest ;
59
62
60
63
constructor ( client : Rest ) {
61
64
this . client = client ;
62
65
}
63
66
64
- async getTorrent ( torrentId : number ) : Promise < Torrent > {
67
+ async getTorrent ( infoHash : string ) : Promise < Torrent > {
65
68
return await fetchGet < GetTorrentResponse > (
66
- `${ this . client . apiBaseUrl } /torrent/${ torrentId } `
69
+ `${ this . client . apiBaseUrl } /torrent/${ infoHash } `
67
70
)
68
71
. then ( ( res ) => {
69
72
return Promise . resolve ( res . data ) ;
@@ -75,7 +78,7 @@ export class TorrentResource implements IRestResource {
75
78
76
79
async getTorrents ( params : GetTorrentsParams ) : Promise < GetTorrentsResponseData > {
77
80
return await fetchGet < GetTorrentsResponse > (
78
- `${ this . client . apiBaseUrl } /torrents?page_size=${ params . pageSize } &page=${ params . page - 1 } &sort=${ params . sorting } ${ params . categories ? "&categories=" + params . categories . join ( "," ) : "" } ${ params . searchQuery ? "&search=" + params . searchQuery : "" } `
81
+ `${ this . client . apiBaseUrl } /torrents?page_size=${ params . pageSize } &page=${ params . page - 1 } &sort=${ params . sorting } ${ params . categories ? "&categories=" + params . categories . join ( "," ) : "" } ${ params . tags ? "&tags=" + params . tags . join ( "," ) : "" } ${ params . searchQuery ? "&search=" + params . searchQuery : "" } `
79
82
)
80
83
. then ( ( res ) => {
81
84
return Promise . resolve ( res . data ) ;
@@ -85,9 +88,9 @@ export class TorrentResource implements IRestResource {
85
88
} ) ;
86
89
}
87
90
88
- async deleteTorrent ( torrentId : number ) : Promise < boolean > {
91
+ async deleteTorrent ( infoHash : string ) : Promise < boolean > {
89
92
return await fetchDelete < any , DeleteTorrentResponse > (
90
- `${ this . client . apiBaseUrl } /torrent/${ torrentId } ` ,
93
+ `${ this . client . apiBaseUrl } /torrent/${ infoHash } ` ,
91
94
{ } ,
92
95
{ "Authorization" : `Bearer ${ this . client . authToken } ` }
93
96
)
@@ -99,10 +102,10 @@ export class TorrentResource implements IRestResource {
99
102
} ) ;
100
103
}
101
104
102
- async updateTorrent ( torrent : Torrent ) : Promise < Torrent > {
103
- return await fetchPut < Torrent , UpdateTorrentResponse > (
104
- `${ this . client . apiBaseUrl } /torrent/${ torrent . torrent_id } ` ,
105
- torrent ,
105
+ async updateTorrent ( infoHash : string , params : UpdateTorrentParams ) : Promise < Torrent > {
106
+ return await fetchPut < UpdateTorrentParams , UpdateTorrentResponse > (
107
+ `${ this . client . apiBaseUrl } /torrent/${ infoHash } ` ,
108
+ params ,
106
109
{ "Authorization" : `Bearer ${ this . client . authToken } ` , "Content-Type" : "application/json" }
107
110
)
108
111
. then ( ( res ) => {
@@ -135,9 +138,9 @@ export class TorrentResource implements IRestResource {
135
138
} ) ;
136
139
}
137
140
138
- async downloadTorrent ( torrentId : number ) : Promise < Blob > {
141
+ async downloadTorrent ( infoHash : number ) : Promise < Blob > {
139
142
return await fetchGetBlob (
140
- `${ this . client . apiBaseUrl } /torrent/download/${ torrentId } `
143
+ `${ this . client . apiBaseUrl } /torrent/download/${ infoHash } `
141
144
)
142
145
. then ( ( blob ) => {
143
146
return Promise . resolve ( blob ) ;
@@ -161,16 +164,4 @@ export class TorrentResource implements IRestResource {
161
164
return Promise . reject ( err ) ;
162
165
} ) ;
163
166
}
164
-
165
- async getTags ( ) : Promise < Array < TorrentTag > > {
166
- return await fetchGet < GetTagsResponse > (
167
- `${ this . client . apiBaseUrl } /tags`
168
- )
169
- . then ( ( res ) => {
170
- return Promise . resolve ( res . data ) ;
171
- } )
172
- . catch ( ( err ) => {
173
- return Promise . reject ( err ) ;
174
- } ) ;
175
- }
176
167
}
0 commit comments