1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
//! API context: `torrent`.
//!
//! This API context is responsible for handling all torrent related requests.
//!
//! # Endpoints
//!
//! - [Upload new torrent](#upload-new-torrent)
//! - [Download a torrent](#download-a-torrent)
//! - [Get torrent info](#get-torrent-info)
//! - [List torrent infos](#list-torrent-infos)
//! - [Update torrent info](#update-torrent-info)
//! - [Delete a torrent](#delete-a-torrent)
//!
//! # Upload new torrent
//!
//! `POST /v1/torrent/upload`
//!
//! It uploads a new torrent to the index.
//!
//! **Example request**
//!
//! ```bash
//! curl \
//! --header "Content-Type: multipart/form-data" \
//! --header "Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyIjp7InVzZXJfaWQiOjEsInVzZXJuYW1lIjoiaW5kZXhhZG1pbiIsImFkbWluaXN0cmF0b3IiOnRydWV9LCJleHAiOjE2ODYyMTU3ODh9.4k8ty27DiWwOk4WVcYEhIrAndhpXMRWnLZ3i_HlJnvI" \
//! --request POST \
//! --form "title=MandelbrotSet" \
//! --form "description=MandelbrotSet image" \
//! --form "category=software" \
//! --form "torrent=@docs/media/mandelbrot_2048x2048_infohash_v1.png.torrent;type=application/x-bittorrent" \
//! "http://127.0.0.1:3001/v1/torrent/upload"
//! ```
//!
//! **Example response** `200`
//!
//! ```json
//! {
//! "data": {
//! "torrent_id": 2,
//! "info_hash": "5452869BE36F9F3350CCEE6B4544E7E76CAAADAB"
//! }
//! }
//! ```
//!
//! **NOTICE**: Info-hashes will be lowercase hex-encoded strings in the future
//! and the [internal database ID could be removed from the response](https://github.com/torrust/torrust-index-backend/discussions/149).
//!
//! **Resource**
//!
//! Refer to the [`TorrustBackend`](crate::models::response::NewTorrentResponse)
//! struct for more information about the response attributes.
//!
//! # Download a torrent
//!
//! `GET /v1/torrent/download/{info_hash}`
//!
//! It downloads a new torrent file from the the index.
//!
//! **Example request**
//!
//! ```bash
//! curl \
//! --header "Content-Type: application/x-bittorrent" \
//! --header "Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyIjp7InVzZXJfaWQiOjEsInVzZXJuYW1lIjoiaW5kZXhhZG1pbiIsImFkbWluaXN0cmF0b3IiOnRydWV9LCJleHAiOjE2ODYyMTU3ODh9.4k8ty27DiWwOk4WVcYEhIrAndhpXMRWnLZ3i_HlJnvI" \
//! --output mandelbrot_2048x2048_infohash_v1.png.torrent \
//! "http://127.0.0.1:3001/v1/torrent/download/5452869BE36F9F3350CCEE6B4544E7E76CAAADAB"
//! ```
//!
//! **Example response** `200`
//!
//! The response is a torrent file `mandelbrot_2048x2048_infohash_v1.png.torrent`.
//!
//! ```text
//! $ imdl torrent show mandelbrot_2048x2048_infohash_v1.png.torrent
//! Name mandelbrot_2048x2048.png
//! Info Hash 1a326de411f96bc15622c62358130f0824f561e1
//! Torrent Size 492 bytes
//! Content Size 168.17 KiB
//! Private no
//! Tracker udp://localhost:6969/eklijkg8901K2Ol6O6CttT1xlUzO4bFD
//! Announce List Tier 1: udp://localhost:6969/eklijkg8901K2Ol6O6CttT1xlUzO4bFD
//! Tier 2: udp://localhost:6969
//! Piece Size 16 KiB
//! Piece Count 11
//! File Count 1
//! Files mandelbrot_2048x2048.png
//! ```
//!
//! # Get torrent info
//!
//! `GET /v1/torrents/{info_hash}`
//!
//! It returns the torrent info.
//!
//! **Path parameters**
//!
//! Name | Type | Description | Required | Example
//! ---|---|---|---|---
//! `info_hash` | `InfoHash` | The info-hash | Yes | `5452869BE36F9F3350CCEE6B4544E7E76CAAADAB`
//!
//! **Example request**
//!
//! ```bash
//! curl \
//! --header "Content-Type: application/json" \
//! --header "Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyIjp7InVzZXJfaWQiOjEsInVzZXJuYW1lIjoiaW5kZXhhZG1pbiIsImFkbWluaXN0cmF0b3IiOnRydWV9LCJleHAiOjE2ODYyMTU3ODh9.4k8ty27DiWwOk4WVcYEhIrAndhpXMRWnLZ3i_HlJnvI" \
//! --request GET \
//! "http://127.0.0.1:3001/v1/torrent/5452869BE36F9F3350CCEE6B4544E7E76CAAADAB"
//! ```
//!
//! **Example response** `200`
//!
//! ```json
//! {
//! "data": {
//! "torrent_id": 2,
//! "uploader": "indexadmin",
//! "info_hash": "5452869BE36F9F3350CCEE6B4544E7E76CAAADAB",
//! "title": "MandelbrotSet",
//! "description": "MandelbrotSet image",
//! "category": {
//! "category_id": 5,
//! "name": "software",
//! "num_torrents": 1
//! },
//! "upload_date": "2023-05-25 11:33:02",
//! "file_size": 172204,
//! "seeders": 0,
//! "leechers": 0,
//! "files": [
//! {
//! "path": [
//! "mandelbrot_2048x2048.png"
//! ],
//! "length": 172204,
//! "md5sum": null
//! }
//! ],
//! "trackers": [
//! "udp://localhost:6969/eklijkg8901K2Ol6O6CttT1xlUzO4bFD",
//! "udp://localhost:6969"
//! ],
//! "magnet_link": "magnet:?xt=urn:btih:5452869BE36F9F3350CCEE6B4544E7E76CAAADAB&dn=MandelbrotSet&tr=udp%3A%2F%2Flocalhost%3A6969%2Feklijkg8901K2Ol6O6CttT1xlUzO4bFD&tr=udp%3A%2F%2Flocalhost%3A6969"
//! }
//! }
//! ```
//!
//! **Resource**
//!
//! Refer to the [`TorrentResponse`](crate::models::response::TorrentResponse)
//! struct for more information about the response attributes.
//!
//! # List torrent infos
//!
//! `GET /v1/torrents`
//!
//! It returns the torrent info for multiple torrents
//!
//! **Get parameters**
//!
//! Name | Type | Description | Required | Example
//! ---|---|---|---|---
//! `search` | `Option<String>` | A text to search | No | `MandelbrotSet`
//! `categories` | `Option<String>` | A coma-separated category list | No | `music,other,movie,software`
//!
//! **Pagination GET parameters**
//!
//! Name | Type | Description | Required | Example
//! ---|---|---|---|---
//! `page_size` | `Option<u8>` | Number of torrents per page | No | `10`
//! `page` | `Option<u32>` | Page offset, starting at `0` | No | `music,other,movie,software`
//!
//! Pagination default values can be configured in the server configuration file.
//!
//! ```toml
//! [api]
//! default_torrent_page_size = 10
//! max_torrent_page_size = 30
//! ```
//!
//! **Sorting GET parameters**
//!
//! Name | Type | Description | Required | Example
//! ---|---|---|---|---
//! `sort` | `Option<Sorting>` | [Sorting](crate::databases::database::Sorting) options | No | `size_DESC`
//!
//! **Example request**
//!
//! ```bash
//! curl \
//! --header "Content-Type: application/json" \
//! --header "Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyIjp7InVzZXJfaWQiOjEsInVzZXJuYW1lIjoiaW5kZXhhZG1pbiIsImFkbWluaXN0cmF0b3IiOnRydWV9LCJleHAiOjE2ODYyMTU3ODh9.4k8ty27DiWwOk4WVcYEhIrAndhpXMRWnLZ3i_HlJnvI" \
//! --request GET \
//! "http://127.0.0.1:3001/v1/torrents"
//! ```
//!
//! **Example response** `200`
//!
//! ```json
//! {
//! "data": {
//! "total": 1,
//! "results": [
//! {
//! "torrent_id": 2,
//! "uploader": "indexadmin",
//! "info_hash": "5452869BE36F9F3350CCEE6B4544E7E76CAAADAB",
//! "title": "MandelbrotSet",
//! "description": "MandelbrotSet image",
//! "category_id": 5,
//! "date_uploaded": "2023-05-25 11:33:02",
//! "file_size": 172204,
//! "seeders": 0,
//! "leechers": 0
//! }
//! ]
//! }
//! }
//! ```
//!
//! **Resource**
//!
//! Refer to the [`TorrentsResponse`](crate::models::response::TorrentsResponse)
//! struct for more information about the response attributes.
//!
//! # Update torrent info
//!
//! `POST /v1/torrents/{info_hash}`
//!
//! It updates the torrent info.
//!
//! **Path parameters**
//!
//! Name | Type | Description | Required | Example
//! ---|---|---|---|---
//! `info_hash` | `InfoHash` | The info-hash | Yes | `5452869BE36F9F3350CCEE6B4544E7E76CAAADAB`
//!
//! **Post parameters**
//!
//! Name | Type | Description | Required | Example
//! ---|---|---|---|---
//! `title` | `Option<String>` | The torrent title | No | `MandelbrotSet`
//! `description` | `Option<String>` | The torrent description | No | `MandelbrotSet image`
//! `category` | `Option<CategoryId>` | The torrent category ID | No | `1`
//! `tags` | `Option<Vec<TagId>>` | The tag Id list | No | `[1,2,3]`
//!
//!
//! Refer to the [`UpdateTorrentInfoForm`](crate::web::api::v1::contexts::torrent::forms::UpdateTorrentInfoForm)
//! struct for more information about the request attributes.
//!
//! **Example request**
//!
//! ```bash
//! curl \
//! --header "Content-Type: application/json" \
//! --header "Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyIjp7InVzZXJfaWQiOjEsInVzZXJuYW1lIjoiaW5kZXhhZG1pbiIsImFkbWluaXN0cmF0b3IiOnRydWV9LCJleHAiOjE2ODYyMTU3ODh9.4k8ty27DiWwOk4WVcYEhIrAndhpXMRWnLZ3i_HlJnvI" \
//! --request PUT \
//! --data '{"title":"MandelbrotSet", "description":"MandelbrotSet image"}' \
//! "http://127.0.0.1:3001/v1/torrent/5452869BE36F9F3350CCEE6B4544E7E76CAAADAB"
//! ```
//!
//! **Example response** `200`
//!
//! ```json
//! {
//! "data": {
//! "torrent_id": 2,
//! "uploader": "indexadmin",
//! "info_hash": "5452869BE36F9F3350CCEE6B4544E7E76CAAADAB",
//! "title": "MandelbrotSet",
//! "description": "MandelbrotSet image",
//! "category": {
//! "category_id": 5,
//! "name": "software",
//! "num_torrents": 1
//! },
//! "upload_date": "2023-05-25 11:33:02",
//! "file_size": 172204,
//! "seeders": 0,
//! "leechers": 0,
//! "files": [],
//! "trackers": [],
//! "magnet_link": ""
//! }
//! }
//! ```
//!
//! **NOTICE**: the response is not the same as the `GET /v1/torrents/{info_hash}`.
//! It does not contain the `files`, `trackers` and `magnet_link` attributes.
//!
//! **Resource**
//!
//! Refer to the [`TorrentResponse`](crate::models::response::TorrentResponse)
//! struct for more information about the response attributes.
//!
//! # Delete a torrent
//!
//! `DELETE /v1/torrents/{info_hash}`
//!
//! It deletes a torrent.
//!
//! **Path parameters**
//!
//! Name | Type | Description | Required | Example
//! ---|---|---|---|---
//! `info_hash` | `InfoHash` | The info-hash | Yes | `5452869BE36F9F3350CCEE6B4544E7E76CAAADAB`
//!
//! **Example request**
//!
//! ```bash
//! curl \
//! --header "Content-Type: application/json" \
//! --header "Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyIjp7InVzZXJfaWQiOjEsInVzZXJuYW1lIjoiaW5kZXhhZG1pbiIsImFkbWluaXN0cmF0b3IiOnRydWV9LCJleHAiOjE2ODYyMTU3ODh9.4k8ty27DiWwOk4WVcYEhIrAndhpXMRWnLZ3i_HlJnvI" \
//! --request DELETE \
//! "http://127.0.0.1:3001/v1/torrent/5452869BE36F9F3350CCEE6B4544E7E76CAAADAB"
//! ```
//!
//! **Example response** `200`
//!
//! ```json
//! {
//! "data": {
//! "torrent_id": 2,
//! "info_hash": "5452869BE36F9F3350CCEE6B4544E7E76CAAADAB",
//! }
//! }
//! ```
//!
//! **Resource**
//!
//! Refer to the [`DeletedTorrentResponse`](crate::models::response::DeletedTorrentResponse)
//! struct for more information about the response attributes.