@@ -70,9 +70,14 @@ export class TorrentResource implements IRestResource {
70
70
this . client = client ;
71
71
}
72
72
73
+ headers ( ) : HeadersInit | undefined {
74
+ return this . client . authToken ? { "Authorization" : `Bearer ${ this . client . authToken } ` } : undefined ;
75
+ }
76
+
73
77
async getTorrentInfo ( infoHash : string ) : Promise < TorrentResponse > {
74
78
return await fetchGet < GetTorrentResponse > (
75
- `${ this . client . apiBaseUrl } /torrent/${ infoHash } `
79
+ `${ this . client . apiBaseUrl } /torrent/${ infoHash } ` ,
80
+ this . headers ( )
76
81
)
77
82
. then ( ( res ) => {
78
83
return Promise . resolve ( res . data ) ;
@@ -84,7 +89,8 @@ export class TorrentResource implements IRestResource {
84
89
85
90
async getTorrents ( params : GetTorrentsParams ) : Promise < GetTorrentsResponseData > {
86
91
return await fetchGet < GetTorrentsResponse > (
87
- `${ 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 : "" } `
92
+ `${ 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 : "" } ` ,
93
+ this . headers ( )
88
94
)
89
95
. then ( ( res ) => {
90
96
return Promise . resolve ( res . data ) ;
@@ -98,7 +104,7 @@ export class TorrentResource implements IRestResource {
98
104
return await fetchDelete < any , DeleteTorrentResponse > (
99
105
`${ this . client . apiBaseUrl } /torrent/${ infoHash } ` ,
100
106
{ } ,
101
- { "Authorization" : `Bearer ${ this . client . authToken } ` }
107
+ this . headers ( )
102
108
)
103
109
. then ( ( res ) => {
104
110
return Promise . resolve ( res . data ) ;
@@ -112,7 +118,7 @@ export class TorrentResource implements IRestResource {
112
118
return await fetchPut < UpdateTorrentParams , UpdateTorrentResponse > (
113
119
`${ this . client . apiBaseUrl } /torrent/${ infoHash } ` ,
114
120
params ,
115
- { "Authorization" : `Bearer ${ this . client . authToken } ` , "Content-Type" : "application/json" }
121
+ this . headers ( )
116
122
)
117
123
. then ( ( res ) => {
118
124
return Promise . resolve ( res . data ) ;
@@ -134,7 +140,7 @@ export class TorrentResource implements IRestResource {
134
140
return await fetchPost < NewTorrentResponse > (
135
141
`${ this . client . apiBaseUrl } /torrent/upload` ,
136
142
formData ,
137
- { "Authorization" : `Bearer ${ this . client . authToken } ` }
143
+ this . headers ( )
138
144
)
139
145
. then ( ( res ) => {
140
146
return Promise . resolve ( res . data ) ;
@@ -146,7 +152,8 @@ export class TorrentResource implements IRestResource {
146
152
147
153
async downloadTorrent ( infoHash : string ) : Promise < Blob > {
148
154
return await fetchGetBlob (
149
- `${ this . client . apiBaseUrl } /torrent/download/${ infoHash } `
155
+ `${ this . client . apiBaseUrl } /torrent/download/${ infoHash } ` ,
156
+ this . headers ( )
150
157
)
151
158
. then ( ( blob ) => {
152
159
return Promise . resolve ( blob ) ;
@@ -157,11 +164,9 @@ export class TorrentResource implements IRestResource {
157
164
}
158
165
159
166
async proxiedImage ( url : string ) : Promise < Blob > {
160
- const headers = this . client . authToken ? { "Authorization" : `Bearer ${ this . client . authToken } ` } : undefined ;
161
-
162
167
return await fetchGetBlob (
163
168
`${ this . client . apiBaseUrl } /proxy/image/${ encodeURIComponent ( url ) } ` ,
164
- headers
169
+ this . headers ( )
165
170
)
166
171
. then ( ( blob ) => {
167
172
return Promise . resolve ( blob ) ;
0 commit comments