mod file;
pub use self::file::FileStore;
use crate::error::{Error, Result};
use atrium_api::agent::atp_agent::AtpSession;
use serde::{Deserialize, Serialize};
use std::future::Future;
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Config {
pub endpoint: String,
pub session: Option<AtpSession>,
pub labelers_header: Option<Vec<String>>,
pub proxy_header: Option<String>,
}
impl Config {
pub async fn load(loader: &impl Loader) -> Result<Self> {
loader.load().await.map_err(Error::ConfigLoad)
}
pub async fn save(&self, saver: &impl Saver) -> Result<()> {
saver.save(self).await.map_err(Error::ConfigSave)
}
}
impl Default for Config {
fn default() -> Self {
Self {
endpoint: String::from("https://bsky.social"),
session: None,
labelers_header: None,
proxy_header: None,
}
}
}
pub trait Loader {
fn load(
&self,
) -> impl Future<
Output = core::result::Result<Config, Box<dyn std::error::Error + Send + Sync + 'static>>,
> + Send;
}
pub trait Saver {
fn save(
&self,
config: &Config,
) -> impl Future<
Output = core::result::Result<(), Box<dyn std::error::Error + Send + Sync + 'static>>,
> + Send;
}