From 95ce885dbc1f8c5c431c7607a054d08da7392867 Mon Sep 17 00:00:00 2001 From: Vika Date: Mon, 7 Mar 2022 11:36:19 +0300 Subject: Port onboarding --- src/micropub/mod.rs | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) (limited to 'src/micropub/mod.rs') diff --git a/src/micropub/mod.rs b/src/micropub/mod.rs index f3152d7..8f5ca09 100644 --- a/src/micropub/mod.rs +++ b/src/micropub/mod.rs @@ -1,4 +1,5 @@ use std::convert::Infallible; +use std::fmt::Display; use either::Either; use log::warn; use warp::http::StatusCode; @@ -38,7 +39,7 @@ enum ErrorType { } #[derive(Serialize, Deserialize, Debug)] -struct MicropubError { +pub(crate) struct MicropubError { error: ErrorType, error_description: String } @@ -55,6 +56,15 @@ impl From for MicropubError { } } +impl std::error::Error for MicropubError {} + +impl Display for MicropubError { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.write_str("Micropub error: ")?; + f.write_str(&self.error_description) + } +} + impl From<&MicropubError> for StatusCode { fn from(err: &MicropubError) -> Self { use ErrorType::*; @@ -98,6 +108,7 @@ impl MicropubError { impl warp::reject::Reject for MicropubError {} mod post; +pub(crate) use post::normalize_mf2; #[allow(unused_variables)] pub mod media { @@ -197,7 +208,7 @@ mod util { } // TODO actually save the post to the database and schedule post-processing -async fn _post( +pub(crate) async fn _post( user: crate::indieauth::User, uid: String, mf2: serde_json::Value, @@ -301,7 +312,8 @@ async fn _post