use mime::Mime;
use std::{
error::Error,
fmt::Debug,
future::Future,
io::Result,
path::{Path, PathBuf},
time::{Duration, SystemTime},
};
use url::Url;
#[cfg(feature = "local")]
pub mod local;
pub mod memory;
#[cfg(feature = "s3")]
pub mod s3;
#[cfg(feature = "local")]
pub use local::LocalAdapter;
pub use memory::MemoryAdapter;
#[cfg(feature = "s3")]
pub use s3::S3Adapter;
use crate::{contents::Contents, Visibility};
pub trait AdapterInit: Adapter + Sized + 'static {
type Config: Clone + Send + Sized;
type Error: Debug + Error + Send + Sized;
fn new(
config: Self::Config,
) -> impl Future<Output = std::result::Result<Self, Self::Error>> + Send;
}
pub trait Adapter: Debug + Send + Sync {
fn file_exists(&self, path: &Path) -> impl Future<Output = Result<bool>> + Send;
fn directory_exists(&self, path: &Path) -> impl Future<Output = Result<bool>> + Send;
fn write(&mut self, path: &Path, content: &[u8]) -> impl Future<Output = Result<()>> + Send;
fn read(&self, path: &Path) -> impl Future<Output = Result<Contents>> + Send;
fn delete(&mut self, path: &Path) -> impl Future<Output = Result<()>> + Send;
fn delete_directory(&mut self, path: &Path) -> impl Future<Output = Result<()>> + Send;
fn create_directory(&mut self, path: &Path) -> impl Future<Output = Result<()>> + Send;
fn set_visibility(
&mut self,
path: &Path,
visibility: Visibility,
) -> impl Future<Output = Result<()>> + Send;
fn visibility(&self, path: &Path) -> impl Future<Output = Result<Visibility>> + Send;
fn mime_type(&self, path: &Path) -> impl Future<Output = Result<Mime>> + Send;
fn last_modified(&self, path: &Path) -> impl Future<Output = Result<SystemTime>> + Send;
fn file_size(&self, path: &Path) -> impl Future<Output = Result<u64>> + Send;
fn list_contents(
&self,
path: &Path,
deep: bool,
) -> impl Future<Output = Result<Vec<PathBuf>>> + Send;
fn r#move(
&mut self,
source: &Path,
destination: &Path,
) -> impl Future<Output = Result<()>> + Send;
fn copy(
&mut self,
source: &Path,
destination: &Path,
) -> impl Future<Output = Result<()>> + Send;
fn checksum(&self, path: &Path) -> impl Future<Output = Result<String>> + Send;
}
pub trait PublicUrlGenerator {
type Error;
fn public_url(
&self,
path: &Path,
) -> impl Future<Output = std::result::Result<String, Self::Error>> + Send;
}
pub trait TemporaryUrlGenerator {
fn temporary_url(
&self,
path: &Path,
expires_in: Duration,
) -> impl Future<Output = Result<Url>> + Send;
}