#![warn(missing_docs)]
use thiserror::Error;
pub mod lemmy;
pub mod piefed;
#[derive(Debug, Clone)]
pub struct ServerPost {
pub community: String,
pub title: String,
pub url: Option<String>,
pub body: Option<String>,
pub language: Option<String>,
pub alt_text: Option<String>,
pub nsfw: Option<bool>,
pub nsfl: Option<bool>,
pub ai_generated: Option<bool>,
pub custom_thumbnail: Option<String>,
}
#[derive(Debug, Clone)]
pub struct ServerCredentials {
pub domain: String,
pub username: String,
pub password: String,
pub fediverse_service_kind: FediverseServiceKind,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum FediverseServiceKind {
Lemmy,
PieFed,
}
#[derive(Debug, Error)]
pub enum Error {
#[error("An error occurred while posting to Lemmy: {0}")]
Lemmy(#[from] lemmy::LemmyError),
#[error("An error occurred while posting to PieFed: {0}")]
PieFed(#[from] piefed::PieFedError),
}
pub async fn post_to_server(
credentials: &ServerCredentials,
post: ServerPost,
) -> Result<(), Error> {
match credentials.fediverse_service_kind {
FediverseServiceKind::Lemmy => lemmy::post_to_lemmy(credentials, post).await?,
FediverseServiceKind::PieFed => piefed::post_to_piefed(credentials, post).await?,
}
Ok(())
}