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
use std::path::PathBuf;
use serde::Deserialize;
use serde::Serialize;
#[derive(Clone, Debug, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct Torrent {
pub id: u16,
pub error: u8,
pub error_string: String,
pub eta: i64, pub is_finished: bool,
pub left_until_done: u64, pub name: String,
pub peers_getting_from_us: u16,
pub peers_sending_to_us: u16,
pub rate_download: u32,
pub rate_upload: u32,
pub size_when_done: u64,
pub status: u8,
pub upload_ratio: f32
}
#[serde_with::skip_serializing_none]
#[derive(Debug, Serialize)]
pub struct AddTorrent<'a> {
pub filename: Option<&'a str>,
pub metainfo: Option<&'a str>
}
#[derive(Debug, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct AddedTorrent {
pub id: u16,
pub name: String,
pub hash_string: String
}
#[derive(Debug, Deserialize, Serialize)]
#[serde(rename_all = "kebab-case")]
pub enum AddTorrentResponse {
TorrentAdded(AddedTorrent),
TorrentDuplicate(AddedTorrent)
}
#[derive(Debug, Serialize)]
#[serde(rename_all = "kebab-case")]
pub struct GetTorrentFilesRequest {
fields: &'static [&'static str],
ids: u16
}
impl GetTorrentFilesRequest {
#[inline]
pub fn new(id: u16) -> Self {
Self{
fields: &["files"],
ids: id
}
}
}
#[derive(Clone, Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct TorrentFile {
pub name: PathBuf,
pub bytes_completed: u64,
pub length: u64
}
impl TorrentFile {
#[inline]
pub fn take_name(self) -> PathBuf {
self.name
}
}
#[derive(Debug, Deserialize)]
pub struct TorrentFiles {
pub files: Vec<TorrentFile>
}
#[derive(Debug, Deserialize)]
pub struct GetTorrentFilesResponse {
pub torrents: Vec<TorrentFiles>
}