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
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
}
#[derive(Debug, Serialize)]
pub struct AddTorrent {
pub filename: String
}
#[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: Vec<String>,
ids: u16
}
impl GetTorrentFilesRequest {
pub fn new(id: u16) -> Self {
Self{
fields: vec!["files".to_string()],
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 {
pub fn take_name(self) -> PathBuf {
self.name
}
}
#[derive(Debug, Deserialize)]
pub struct TorrentFileWrapper {
pub files: Vec<TorrentFile>
}
#[derive(Debug, Deserialize)]
pub struct GetTorrentFilesResponse {
pub torrents: Vec<TorrentFileWrapper>
}