use bytes::Bytes;
use std::collections::{HashMap, HashSet};
#[derive(Debug, Clone, Default)]
pub struct ListBlobsRequest {
pub include_dirs: bool,
pub extensions: HashSet<String>,
pub excluded: HashSet<String>,
pub prefix: Option<String>,
}
impl ListBlobsRequest {
pub fn exclude<'a, I: Iterator<Item = &'a str>>(mut self, items: I) -> Self {
self.excluded.extend(items.map(String::from));
self
}
pub fn with_prefix<I: Into<String>>(mut self, prefix: Option<I>) -> Self {
self.prefix = prefix.map(Into::into);
self
}
pub fn with_extensions<'a, I: Iterator<Item = &'a str>>(mut self, exts: I) -> Self {
self.extensions
.extend(exts.filter(|x| x.starts_with('.')).map(String::from));
self
}
pub fn with_include_dirs(&mut self, yes: bool) -> &mut Self {
self.include_dirs = yes;
self
}
pub fn is_excluded<I: AsRef<str>>(&self, item: I) -> bool {
self.excluded.contains(item.as_ref())
}
pub fn is_ext_allowed<I: AsRef<str>>(&self, ext: I) -> bool {
if self.extensions.is_empty() {
return true;
}
self.extensions.contains(ext.as_ref())
}
}
#[derive(Debug, Clone, Default)]
pub struct UploadRequest {
pub content_type: Option<String>,
pub metadata: HashMap<String, String>,
pub data: Bytes,
}
impl UploadRequest {
pub fn with_content_type<I: Into<String>>(mut self, content_type: Option<I>) -> Self {
self.content_type = content_type.map(Into::into);
self
}
pub fn with_metadata(mut self, metadata: HashMap<String, String>) -> Self {
self.metadata.extend(metadata);
self
}
pub fn with_data<I: Into<Bytes>>(mut self, container: I) -> Self {
self.data = container.into();
self
}
}