async_aria2/
json.rs

1use serde::{Deserialize, Serialize};
2
3#[derive(Serialize)]
4pub struct Request {
5    pub jsonrpc: String,
6    pub id: String,
7    pub method: String,
8    pub params: Params,
9}
10
11#[derive(Serialize)]
12#[serde(untagged)]
13pub enum Params {
14    V(Vec<String>),
15    SV(String, Vec<String>),
16    SSV(String, String, Vec<String>),
17    SOptions(String, Options),
18    SUU(String, usize, usize),
19}
20
21#[derive(Serialize)]
22pub struct Options {
23    #[serde(rename = "max-overall-download-limit")]
24    pub max_overall_download_limit: String,
25    #[serde(rename = "max-overall-upload-limit")]
26    pub max_overall_upload_limit: String,
27    pub dir: String,
28}
29
30#[derive(Deserialize)]
31pub struct Response {
32    pub jsonrpc: String,
33    pub id: String,
34    pub result: JsonResult,
35}
36
37#[derive(Deserialize)]
38#[serde(untagged)]
39pub enum JsonResult {
40    S(String),
41    Status(Status),
42    StatusList(Vec<Status>),
43    Statistics(Statistics),
44}
45
46#[derive(Deserialize, Debug)]
47pub struct Status {
48    pub bitfield: String,
49    pub bittorrent: Option<Bittorrent>,
50    #[serde(rename = "completedLength")]
51    pub completed_length: String,
52    pub connections: String,
53    pub dir: String,
54    #[serde(rename = "downloadSpeed")]
55    pub download_speed: String,
56    pub files: Vec<File>,
57    pub gid: String,
58    #[serde(rename = "infoHash")]
59    pub info_hash: Option<String>,
60    #[serde(rename = "numPieces")]
61    pub num_pieces: String,
62    #[serde(rename = "numSeeders")]
63    pub num_seeders: Option<String>,
64    #[serde(rename = "pieceLength")]
65    pub piece_length: String,
66    pub seeder: Option<String>,
67    pub status: String,
68    #[serde(rename = "totalLength")]
69    pub total_length: String,
70    #[serde(rename = "uploadLength")]
71    pub upload_length: String,
72    #[serde(rename = "uploadSpeed")]
73    pub upload_speed: String,
74}
75
76#[derive(Deserialize, Debug)]
77pub struct Bittorrent {
78    #[serde(rename = "announceList")]
79    pub announce_list: Vec<Vec<String>>,
80    pub comment: String,
81    #[serde(rename = "creationDate")]
82    pub creation_date: u32,
83    pub info: Info,
84    pub mode: String,
85}
86
87#[derive(Deserialize, Debug)]
88pub struct Info {
89    pub name: String,
90}
91
92#[derive(Deserialize, Debug)]
93pub struct File {
94    #[serde(rename = "completedLength")]
95    pub completed_length: String,
96    pub index: String,
97    pub length: String,
98    pub path: String,
99    pub selected: String,
100    pub uris: Vec<Uri>,
101}
102
103#[derive(Deserialize, Debug)]
104pub struct Uri {
105    pub status: String,
106    pub uri: String,
107}
108
109#[derive(Deserialize, Debug)]
110pub struct Statistics {
111    #[serde(rename = "downloadSpeed")]
112    pub download_speed: String,
113    #[serde(rename = "numActive")]
114    pub num_active: String,
115    #[serde(rename = "numStopped")]
116    pub num_stopped: String,
117    #[serde(rename = "numStoppedTotal")]
118    pub num_stopped_total: String,
119    #[serde(rename = "numWaiting")]
120    pub num_waiting: String,
121    #[serde(rename = "uploadSpeed")]
122    pub upload_speed: String,
123}