use serde::{Deserialize, Serialize};
pub const MAX_LISTED_SKIPS: usize = 50;
pub const SKIP_REPORT_ENTRY: &str = ".computerd-skipped";
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct UploadQuery {
pub path: String,
#[serde(default)]
pub overwrite: bool,
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct UploadCheck {
pub path: String,
#[serde(default)]
pub overwrite: bool,
pub name: String,
pub folder: bool,
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct DownloadRequest {
pub path: String,
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct Skipped {
pub path: String,
pub reason: String,
}
#[derive(Debug, Clone, Default, PartialEq, Eq, Serialize, Deserialize)]
pub struct SkipList {
pub entries: Vec<Skipped>,
pub omitted: u64,
}
impl SkipList {
pub fn push(&mut self, path: impl Into<String>, reason: impl Into<String>) {
if self.entries.len() < MAX_LISTED_SKIPS {
self.entries.push(Skipped {
path: path.into(),
reason: reason.into(),
});
} else {
self.omitted += 1;
}
}
pub fn merge(&mut self, other: Self) {
self.omitted += other.omitted;
for entry in other.entries {
self.push(entry.path, entry.reason);
}
}
#[must_use]
pub fn is_empty(&self) -> bool {
self.entries.is_empty() && self.omitted == 0
}
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct TransferReply {
pub path: String,
pub files: u64,
pub folders: u64,
pub bytes: u64,
pub skipped: SkipList,
}