aria2_ws/
response.rs

1use chrono::{DateTime, Utc};
2use serde::{Deserialize, Serialize};
3use serde_with::{serde_as, DisplayFromStr, TimestampSeconds};
4
5#[derive(Serialize, Deserialize, Debug, Clone)]
6#[serde(rename_all = "camelCase")]
7pub struct Version {
8    pub enabled_features: Vec<String>,
9
10    pub version: String,
11}
12
13/// Full status of a task.
14///
15/// <https://aria2.github.io/manual/en/html/aria2c.html#aria2.tellStatus>
16#[serde_as]
17#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
18#[serde(rename_all = "camelCase")]
19pub struct Status {
20    /// GID of the download.
21    pub gid: String,
22
23    pub status: TaskStatus,
24
25    #[serde_as(as = "DisplayFromStr")]
26    pub total_length: u64,
27
28    #[serde_as(as = "DisplayFromStr")]
29    pub completed_length: u64,
30
31    #[serde_as(as = "DisplayFromStr")]
32    pub upload_length: u64,
33
34    /// Hexadecimal representation of the download progress.
35    ///
36    /// The highest bit corresponds to the piece at index 0.
37    ///
38    /// Any set bits indicate loaded pieces, while
39    /// unset bits indicate not yet loaded and/or missing pieces.
40    ///
41    /// Any overflow bits at the end are set to zero.
42    ///
43    /// When the download was not started yet,
44    /// this key will not be included in the response.
45    pub bitfield: Option<String>,
46
47    #[serde_as(as = "DisplayFromStr")]
48    pub download_speed: u64,
49
50    #[serde_as(as = "DisplayFromStr")]
51    pub upload_speed: u64,
52
53    /// InfoHash. BitTorrent only
54    pub info_hash: Option<String>,
55
56    #[serde_as(as = "Option<DisplayFromStr>")]
57    pub num_seeders: Option<u64>,
58
59    /// true if the local endpoint is a seeder. Otherwise false. BitTorrent only.
60    #[serde_as(as = "Option<DisplayFromStr>")]
61    pub seeder: Option<bool>,
62
63    #[serde_as(as = "DisplayFromStr")]
64    pub piece_length: u64,
65
66    #[serde_as(as = "DisplayFromStr")]
67    pub num_pieces: u64,
68
69    #[serde_as(as = "DisplayFromStr")]
70    pub connections: u64,
71
72    pub error_code: Option<String>,
73
74    pub error_message: Option<String>,
75    /// List of GIDs which are generated as the result of this download.
76    ///
77    /// For example, when aria2 downloads a Metalink file,
78    /// it generates downloads described in the Metalink (see the --follow-metalink option).
79    ///
80    /// This value is useful to track auto-generated downloads.
81    ///
82    /// If there are no such downloads, this key will not be included in the response.
83    pub followed_by: Option<Vec<String>>,
84
85    /// The reverse link for followedBy.
86    ///
87    /// A download included in followedBy has this object's GID in its following value.
88    pub following: Option<String>,
89
90    /// GID of a parent download.
91    ///
92    /// Some downloads are a part of another download.
93    ///
94    /// For example, if a file in a Metalink has BitTorrent resources,
95    /// the downloads of ".torrent" files are parts of that parent.
96    ///
97    /// If this download has no parent, this key will not be included in the response.
98    pub belongs_to: Option<String>,
99
100    pub dir: String,
101
102    pub files: Vec<File>,
103
104    pub bittorrent: Option<BittorrentStatus>,
105
106    /// The number of verified number of bytes while the files are being hash checked.
107    ///
108    /// This key exists only when this download is being hash checked.
109    #[serde_as(as = "Option<DisplayFromStr>")]
110    pub verified_length: Option<u64>,
111
112    /// `true` if this download is waiting for the hash check in a queue.
113    ///
114    /// This key exists only when this download is in the queue.
115    #[serde_as(as = "Option<DisplayFromStr>")]
116    pub verify_integrity_pending: Option<bool>,
117}
118
119#[serde_as]
120#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
121#[serde(rename_all = "camelCase")]
122pub struct BittorrentStatus {
123    pub announce_list: Vec<Vec<String>>,
124
125    pub comment: Option<String>,
126
127    #[serde_as(as = "Option<TimestampSeconds<i64>>")]
128    pub creation_date: Option<DateTime<Utc>>,
129
130    pub mode: Option<BitTorrentFileMode>,
131}
132
133#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
134#[serde(rename_all = "lowercase")]
135pub enum BitTorrentFileMode {
136    Single,
137    Multi,
138}
139
140#[serde_as]
141#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
142#[serde(rename_all = "camelCase")]
143pub struct File {
144    #[serde_as(as = "DisplayFromStr")]
145    pub index: u64,
146
147    pub path: String,
148
149    #[serde_as(as = "DisplayFromStr")]
150    pub length: u64,
151
152    #[serde_as(as = "DisplayFromStr")]
153    pub completed_length: u64,
154
155    #[serde_as(as = "DisplayFromStr")]
156    pub selected: bool,
157
158    pub uris: Vec<Uri>,
159}
160
161#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
162#[serde(rename_all = "camelCase")]
163pub struct Uri {
164    pub status: UriStatus,
165
166    pub uri: String,
167}
168
169#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
170#[serde(rename_all = "lowercase")]
171pub enum UriStatus {
172    Used,
173    Waiting,
174}
175
176/// Task status returned by `aria2.tellStatus`.
177///
178/// `Active` for currently downloading/seeding downloads.
179///
180/// `Waiting` for downloads in the queue; download is not started.
181///
182/// `Paused` for paused downloads.
183///
184/// `Error` for downloads that were stopped because of error.
185///
186/// `Complete` for stopped and completed downloads.
187///
188/// `Removed` for the downloads removed by user.
189///
190/// <https://aria2.github.io/manual/en/html/aria2c.html#aria2.tellStatus>
191#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
192#[serde(rename_all = "lowercase")]
193pub enum TaskStatus {
194    Active,
195    Waiting,
196    Paused,
197    Error,
198    Complete,
199    Removed,
200}
201
202#[serde_as]
203#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
204#[serde(rename_all = "camelCase")]
205pub struct Peer {
206    #[serde_as(as = "DisplayFromStr")]
207    pub am_choking: bool,
208
209    pub bitfield: String,
210
211    #[serde_as(as = "DisplayFromStr")]
212    pub download_speed: u64,
213
214    pub ip: String,
215
216    #[serde_as(as = "DisplayFromStr")]
217    pub peer_choking: bool,
218
219    pub peer_id: String,
220
221    #[serde_as(as = "DisplayFromStr")]
222    pub port: u16,
223
224    #[serde_as(as = "DisplayFromStr")]
225    pub seeder: bool,
226
227    #[serde_as(as = "DisplayFromStr")]
228    pub upload_speed: u64,
229}
230
231#[serde_as]
232#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
233#[serde(rename_all = "camelCase")]
234pub struct GlobalStat {
235    #[serde_as(as = "DisplayFromStr")]
236    pub download_speed: u64,
237
238    #[serde_as(as = "DisplayFromStr")]
239    pub upload_speed: u64,
240
241    #[serde_as(as = "DisplayFromStr")]
242    pub num_active: i32,
243
244    #[serde_as(as = "DisplayFromStr")]
245    pub num_waiting: i32,
246
247    #[serde_as(as = "DisplayFromStr")]
248    pub num_stopped: i32,
249
250    #[serde_as(as = "DisplayFromStr")]
251    pub num_stopped_total: i32,
252}
253
254#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
255#[serde(rename_all = "camelCase")]
256pub struct SessionInfo {
257    pub session_id: String,
258}
259
260#[serde_as]
261#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
262#[serde(rename_all = "camelCase")]
263pub struct GetServersResult {
264    #[serde_as(as = "DisplayFromStr")]
265    pub index: i32,
266
267    pub servers: Vec<Server>,
268}
269
270#[serde_as]
271#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
272#[serde(rename_all = "camelCase")]
273pub struct Server {
274    pub uri: String,
275
276    pub current_uri: String,
277
278    #[serde_as(as = "DisplayFromStr")]
279    pub download_speed: u64,
280}