handle files wanted/unwanted/priorities for torrent-add & torrent-get

This commit is contained in:
Raphaël BILAND 2021-08-03 12:44:18 +08:00
parent cf1bdb95d2
commit 21f0b62bac
3 changed files with 32 additions and 10 deletions

View File

@ -10,7 +10,6 @@ pub struct BasicAuth {
} }
pub use self::request::ArgumentFields; pub use self::request::ArgumentFields;
pub use self::request::File;
pub use self::request::Id; pub use self::request::Id;
pub(crate) use self::request::RpcRequest; pub(crate) use self::request::RpcRequest;
pub use self::request::TorrentAction; pub use self::request::TorrentAction;

View File

@ -146,16 +146,22 @@ pub struct TorrentAddArgs {
pub peer_limit: Option<i64>, pub peer_limit: Option<i64>,
#[serde(skip_serializing_if = "Option::is_none", rename = "bandwidthPriority")] #[serde(skip_serializing_if = "Option::is_none", rename = "bandwidthPriority")]
pub bandwidth_priority: Option<i64>, pub bandwidth_priority: Option<i64>,
/// list of indices of files to be downloaded
/// to ignore some files, put their indices in files_unwanted, otherwise they will still be downloaded
#[serde(skip_serializing_if = "Option::is_none", rename = "files-wanted")] #[serde(skip_serializing_if = "Option::is_none", rename = "files-wanted")]
pub files_wanted: Option<Vec<File>>, pub files_wanted: Option<Vec<i32>>,
/// list of indices of files not to download
#[serde(skip_serializing_if = "Option::is_none", rename = "files-unwanted")] #[serde(skip_serializing_if = "Option::is_none", rename = "files-unwanted")]
pub files_unwanted: Option<Vec<File>>, pub files_unwanted: Option<Vec<i32>>,
/// list of indices of files to be downloaded with high priority
#[serde(skip_serializing_if = "Option::is_none", rename = "priority-high")] #[serde(skip_serializing_if = "Option::is_none", rename = "priority-high")]
pub priority_high: Option<Vec<File>>, pub priority_high: Option<Vec<i32>>,
/// list of indices of files to be downloaded with low priority
#[serde(skip_serializing_if = "Option::is_none", rename = "priority-low")] #[serde(skip_serializing_if = "Option::is_none", rename = "priority-low")]
pub priority_low: Option<Vec<File>>, pub priority_low: Option<Vec<i32>>,
/// list of indices of files to be downloaded with normal priority
#[serde(skip_serializing_if = "Option::is_none", rename = "priority-normal")] #[serde(skip_serializing_if = "Option::is_none", rename = "priority-normal")]
pub priority_normal: Option<Vec<File>>, pub priority_normal: Option<Vec<i32>>,
} }
impl Default for TorrentAddArgs { impl Default for TorrentAddArgs {
@ -177,10 +183,6 @@ impl Default for TorrentAddArgs {
} }
} }
#[derive(Serialize, Debug, RustcEncodable, Clone)]
pub struct File {
//todo
}
#[derive(Clone, IntoEnumIterator)] #[derive(Clone, IntoEnumIterator)]
pub enum TorrentGetField { pub enum TorrentGetField {
Id, Id,
@ -213,6 +215,9 @@ pub enum TorrentGetField {
Uploadedever, Uploadedever,
Uploadratio, Uploadratio,
Webseedssendingtous, Webseedssendingtous,
Wanted,
Priorities,
Filestats
} }
impl TorrentGetField { impl TorrentGetField {
@ -254,6 +259,9 @@ impl TorrentGetField {
TorrentGetField::Uploadedever => "uploadedEver", TorrentGetField::Uploadedever => "uploadedEver",
TorrentGetField::Uploadratio => "uploadRatio", TorrentGetField::Uploadratio => "uploadRatio",
TorrentGetField::Webseedssendingtous => "webseedsSendingToUs", TorrentGetField::Webseedssendingtous => "webseedsSendingToUs",
TorrentGetField::Wanted => "wanted",
TorrentGetField::Priorities => "priorities",
TorrentGetField::Filestats => "fileStats",
}.to_string() }.to_string()
} }
} }

View File

@ -76,6 +76,12 @@ pub struct Torrent {
#[serde(rename = "uploadedEver")] #[serde(rename = "uploadedEver")]
pub uploaded_ever: Option<i64>, pub uploaded_ever: Option<i64>,
pub files: Option<Vec<File>>, pub files: Option<Vec<File>>,
/// for each file in files, whether or not they will be downloaded (0 or 1)
pub wanted: Option<Vec<i8>>,
/// for each file in files, their download priority (low:-1,normal:0,high:1)
pub priorities: Option<Vec<i8>>,
#[serde(rename = "fileStats")]
pub file_stats: Option<Vec<FileStat>>,
} }
#[derive(Deserialize, Debug, RustcEncodable)] #[derive(Deserialize, Debug, RustcEncodable)]
@ -98,6 +104,15 @@ pub struct File {
pub name: String, pub name: String,
} }
#[derive(Deserialize, Debug, RustcEncodable, Clone)]
pub struct FileStat {
#[serde(rename = "bytesCompleted")]
pub bytes_completed: i64,
pub wanted: bool,
/// low: -1, normal: 0, high: 1
pub priority: i8,
}
#[derive(Deserialize, Debug, RustcEncodable)] #[derive(Deserialize, Debug, RustcEncodable)]
pub struct Nothing {} pub struct Nothing {}
impl RpcResponseArgument for Nothing {} impl RpcResponseArgument for Nothing {}