use std::collections::HashMap;
use std::path::PathBuf;
pub struct UploadRequest {
pub(crate) comment: Option<String>,
pub(crate) tags: Vec<String>,
pub(crate) text: Option<String>,
pub(crate) ignore_warnings: bool,
pub(crate) file: PathBuf,
pub(crate) chunk_size: usize,
}
impl UploadRequest {
pub fn from_path(path: PathBuf) -> Self {
Self {
comment: None,
tags: vec![],
text: None,
ignore_warnings: false,
file: path,
chunk_size: 5_000_000,
}
}
pub fn comment(mut self, comment: String) -> Self {
self.comment = Some(comment);
self
}
pub fn tags(mut self, tags: Vec<String>) -> Self {
self.tags.extend(tags);
self
}
pub fn text(mut self, text: String) -> Self {
self.text = Some(text);
self
}
pub fn ignore_warnings(mut self, val: bool) -> Self {
self.ignore_warnings = val;
self
}
pub fn chunk_size(mut self, val: usize) -> Self {
self.chunk_size = val;
self
}
pub(crate) fn params(&self) -> HashMap<&'static str, String> {
let mut params = HashMap::new();
if let Some(comment) = &self.comment {
params.insert("comment", comment.to_string());
}
if !self.tags.is_empty() {
params.insert("tags", self.tags.join("|"));
}
if let Some(text) = &self.text {
params.insert("text", text.to_string());
}
params
}
}