mirror of
https://github.com/YGGverse/aquatic.git
synced 2026-04-01 02:05:30 +00:00
improve ws protocol struct naming and documentation
This commit is contained in:
parent
b473bb6fba
commit
0789f7ec3b
17 changed files with 193 additions and 137 deletions
32
crates/ws_protocol/src/incoming/scrape.rs
Normal file
32
crates/ws_protocol/src/incoming/scrape.rs
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::common::*;
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
||||
pub struct ScrapeRequest {
|
||||
/// Always "scrape"
|
||||
pub action: ScrapeAction,
|
||||
/// Info hash or info hashes
|
||||
///
|
||||
/// Notes from reference implementation:
|
||||
/// - If omitted, scrape for all torrents, apparently
|
||||
/// - Accepts a single info hash or an array of info hashes
|
||||
#[serde(rename = "info_hash")]
|
||||
pub info_hashes: Option<ScrapeRequestInfoHashes>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
||||
#[serde(untagged)]
|
||||
pub enum ScrapeRequestInfoHashes {
|
||||
Single(InfoHash),
|
||||
Multiple(Vec<InfoHash>),
|
||||
}
|
||||
|
||||
impl ScrapeRequestInfoHashes {
|
||||
pub fn as_vec(self) -> Vec<InfoHash> {
|
||||
match self {
|
||||
Self::Single(info_hash) => vec![info_hash],
|
||||
Self::Multiple(info_hashes) => info_hashes,
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue