use crate::backend::StorageBackend;
#[derive(Debug, Clone)]
pub struct BackendConfig {
pub backend_type: String,
pub endpoint: String,
pub region: String,
pub access_key: String,
pub secret_key: String,
pub use_tls: bool,
pub root_path: String,
pub is_default: bool,
}
impl Default for BackendConfig {
fn default() -> Self {
Self {
backend_type: "local".into(),
endpoint: "uploads".into(),
region: String::new(),
access_key: String::new(),
secret_key: String::new(),
use_tls: false,
root_path: "uploads".into(),
is_default: true,
}
}
}
#[derive(Debug, Clone, serde::Deserialize)]
pub struct FsPluginConfig {
#[serde(default = "default_backend_type")]
pub default_backend_type: String,
#[serde(default = "default_root_dir")]
pub local_root_dir: String,
#[serde(default = "default_max_size")]
pub max_file_size_bytes: u64,
#[serde(default = "default_presign_ttl")]
pub presign_url_ttl_secs: u64,
}
fn default_backend_type() -> String { "local".into() }
fn default_root_dir() -> String { "uploads".into() }
fn default_max_size() -> u64 { 52_428_800 }
fn default_presign_ttl() -> u64 { 3600 }
impl Default for FsPluginConfig {
fn default() -> Self {
Self {
default_backend_type: default_backend_type(),
local_root_dir: default_root_dir(),
max_file_size_bytes: default_max_size(),
presign_url_ttl_secs: default_presign_ttl(),
}
}
}
#[derive(Debug, Clone)]
pub struct BackendEntry {
pub backend_type: &'static str,
pub constructor_fn: fn() -> Box<dyn StorageBackend>,
pub config_fn: fn() -> BackendConfig,
}
#[linkme::distributed_slice]
pub static STORAGE_BACKENDS: [BackendEntry] = [..];