1
- import { Torrent , TorrentCompact } from "torrust-index-types-lib" ;
1
+ import { Torrent , TorrentTag , TorrentCompact } from "torrust-index-types-lib" ;
2
2
import { Rest } from "../rest" ;
3
3
import { IRestResource } from "../restResource" ;
4
4
import { fetchDelete , fetchGet , fetchGetBlob , fetchPost , fetchPut } from "../../../utils/fetch" ;
@@ -38,6 +38,7 @@ type UploadTorrentParams = {
38
38
title : string
39
39
category : string
40
40
description : string
41
+ tags : Array < number >
41
42
file : any
42
43
}
43
44
@@ -49,6 +50,10 @@ type UploadTorrentResponseData = {
49
50
torrent_id : number
50
51
}
51
52
53
+ type GetTagsResponse = {
54
+ data : Array < TorrentTag >
55
+ }
56
+
52
57
export class TorrentResource implements IRestResource {
53
58
client : Rest ;
54
59
@@ -114,6 +119,7 @@ export class TorrentResource implements IRestResource {
114
119
formData . append ( "title" , params . title ) ;
115
120
formData . append ( "description" , params . description ) ;
116
121
formData . append ( "category" , params . category ) ;
122
+ formData . append ( "tags" , JSON . stringify ( params . tags ) ) ;
117
123
formData . append ( "torrent" , params . file ) ;
118
124
119
125
return await fetchPost < UploadTorrentResponse > (
@@ -155,4 +161,16 @@ export class TorrentResource implements IRestResource {
155
161
return Promise . reject ( err ) ;
156
162
} ) ;
157
163
}
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
+ }
158
176
}
0 commit comments