1use std::time::SystemTime;
2
3use serde::{Deserialize, Serialize};
4use smol_str::SmolStr;
5
6#[derive(Serialize, Deserialize, Debug, Clone, Copy, PartialEq, Eq)]
7#[serde(rename_all = "camelCase")]
8pub enum StatusKey {
9 Gid,
10 Status,
11 TotalLength,
12 CompletedLength,
13 UploadLength,
14 Bitfield,
15 DownloadSpeed,
16 UploadSpeed,
17 InfoHash,
18 NumSeeders,
19 Seeder,
20 PieceLength,
21 NumPieces,
22 Connections,
23 ErrorCode,
24 ErrorMessage,
25 FollowedBy,
26 Following,
27 BelongsTo,
28 Dir,
29 Files,
30 Bittorrent,
31 VerifiedLength,
32 VerifyIntegrityPending,
33}
34
35#[serde_with::serde_as]
36#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
37#[serde(rename_all = "camelCase")]
38pub struct Status {
39 pub gid: Option<SmolStr>,
40 pub status: Option<TaskStatus>,
41 #[serde_as(as = "Option<serde_with::DisplayFromStr>")]
42 pub total_length: Option<u64>,
43 #[serde_as(as = "Option<serde_with::DisplayFromStr>")]
44 pub completed_length: Option<u64>,
45 #[serde_as(as = "Option<serde_with::DisplayFromStr>")]
46 pub upload_length: Option<u64>,
47 pub bitfield: Option<String>,
48 #[serde_as(as = "Option<serde_with::DisplayFromStr>")]
49 pub download_speed: Option<u64>,
50 #[serde_as(as = "Option<serde_with::DisplayFromStr>")]
51 pub upload_speed: Option<u64>,
52 pub info_hash: Option<String>,
53 #[serde_as(as = "Option<serde_with::DisplayFromStr>")]
54 pub num_seeders: Option<u64>,
55 #[serde_as(as = "Option<serde_with::DisplayFromStr>")]
56 pub seeder: Option<bool>,
57 #[serde_as(as = "Option<serde_with::DisplayFromStr>")]
58 pub piece_length: Option<u64>,
59 #[serde_as(as = "Option<serde_with::DisplayFromStr>")]
60 pub num_pieces: Option<u64>,
61 #[serde_as(as = "Option<serde_with::DisplayFromStr>")]
62 pub connections: Option<u64>,
63 pub error_code: Option<String>,
64 pub error_message: Option<String>,
65 pub followed_by: Option<Vec<String>>,
66 pub following: Option<String>,
67 pub belongs_to: Option<String>,
68 pub dir: Option<String>,
69 pub files: Option<Vec<File>>,
70 pub bittorrent: Option<BittorrentStatus>,
71}
72
73#[derive(Serialize, Deserialize, Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord)]
74#[serde(rename_all = "camelCase")]
75#[repr(u8)]
76pub enum TaskStatus {
77 Active,
78 Waiting,
79 Paused,
80 Error,
81 Complete,
82 Removed,
83}
84
85#[serde_with::serde_as]
86#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
87#[serde(rename_all = "camelCase")]
88pub struct File {
89 #[serde_as(as = "serde_with::DisplayFromStr")]
90 pub index: u64,
91 pub path: String,
92 #[serde_as(as = "serde_with::DisplayFromStr")]
93 pub length: u64,
94 #[serde_as(as = "serde_with::DisplayFromStr")]
95 pub completed_length: u64,
96 #[serde_as(as = "serde_with::DisplayFromStr")]
97 pub selected: bool,
98 pub uris: Vec<Uri>,
99}
100
101#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
102pub struct Uri {
103 pub uri: String,
104 pub status: UriStatus,
105}
106
107#[derive(Serialize, Deserialize, Debug, Copy, Clone, PartialEq, Eq)]
108#[serde(rename_all = "camelCase")]
109pub enum UriStatus {
110 Used,
111 Waiting,
112}
113
114#[serde_with::serde_as]
115#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
116#[serde(rename_all = "camelCase")]
117pub struct BittorrentStatus {
118 pub announce_list: Vec<Vec<String>>,
119 pub comment: Option<String>,
120 #[serde_as(as = "Option<serde_with::TimestampSeconds<i64>>")]
121 pub creation_date: Option<SystemTime>,
122 pub mode: Option<BitTorrentMode>,
123 pub info: Option<BittorrentInfo>,
124}
125
126#[derive(Serialize, Deserialize, Debug, Copy, Clone, PartialEq, Eq)]
127#[serde(rename_all = "lowercase")]
128pub enum BitTorrentMode {
129 Single,
130 Multi,
131}
132
133#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
134pub struct BittorrentInfo {
135 pub name: String,
136}
137
138#[derive(Serialize, Deserialize, Debug, Clone, Copy, PartialEq, Eq)]
139#[serde(rename_all = "camelCase")]
140pub enum StatKey {
141 DownloadSpeed,
142 UploadSpeed,
143 NumActive,
144 NumWaiting,
145 NumStopped,
146 NumStoppedTotal,
147}
148
149#[serde_with::serde_as]
150#[derive(Serialize, Deserialize, Debug, Clone)]
151#[serde(rename_all = "camelCase")]
152pub struct Stat {
153 #[serde_as(as = "Option<serde_with::DisplayFromStr>")]
154 pub download_speed: Option<u64>,
155 #[serde_as(as = "Option<serde_with::DisplayFromStr>")]
156 pub upload_speed: Option<u64>,
157 #[serde_as(as = "Option<serde_with::DisplayFromStr>")]
158 pub num_active: Option<u32>,
159 #[serde_as(as = "Option<serde_with::DisplayFromStr>")]
160 pub num_waiting: Option<u32>,
161 #[serde_as(as = "Option<serde_with::DisplayFromStr>")]
162 pub num_stopped: Option<u32>,
163 #[serde_as(as = "Option<serde_with::DisplayFromStr>")]
164 pub num_stopped_total: Option<u32>,
165}