use crate::signing::Disposition;
use doido_core::Result;
use std::sync::Arc;
use std::time::Duration;
#[derive(Debug, Clone)]
pub struct UrlOptions {
pub expires_in: Duration,
pub disposition: Disposition,
pub filename: Option<String>,
pub content_type: Option<String>,
}
impl Default for UrlOptions {
fn default() -> Self {
Self {
expires_in: Duration::from_secs(300),
disposition: Disposition::Inline,
filename: None,
content_type: None,
}
}
}
#[async_trait::async_trait]
pub trait Service: Send + Sync {
fn name(&self) -> &str;
fn public(&self) -> bool {
false
}
async fn upload(&self, key: &str, data: Vec<u8>, content_type: Option<&str>) -> Result<()>;
async fn download(&self, key: &str) -> Result<Vec<u8>>;
async fn delete(&self, key: &str) -> Result<()>;
async fn exists(&self, key: &str) -> Result<bool>;
async fn size(&self, key: &str) -> Result<u64>;
async fn url(&self, key: &str, opts: &UrlOptions) -> Result<Option<String>> {
let _ = (key, opts);
Ok(None)
}
async fn presigned_put(&self, key: &str, opts: &UrlOptions) -> Result<Option<String>> {
let _ = (key, opts);
Ok(None)
}
}
#[async_trait::async_trait]
impl Service for Arc<dyn Service> {
fn name(&self) -> &str {
(**self).name()
}
fn public(&self) -> bool {
(**self).public()
}
async fn upload(&self, key: &str, data: Vec<u8>, content_type: Option<&str>) -> Result<()> {
(**self).upload(key, data, content_type).await
}
async fn download(&self, key: &str) -> Result<Vec<u8>> {
(**self).download(key).await
}
async fn delete(&self, key: &str) -> Result<()> {
(**self).delete(key).await
}
async fn exists(&self, key: &str) -> Result<bool> {
(**self).exists(key).await
}
async fn size(&self, key: &str) -> Result<u64> {
(**self).size(key).await
}
async fn url(&self, key: &str, opts: &UrlOptions) -> Result<Option<String>> {
(**self).url(key, opts).await
}
async fn presigned_put(&self, key: &str, opts: &UrlOptions) -> Result<Option<String>> {
(**self).presigned_put(key, opts).await
}
}