From 696ae495aca701c3431710e5dfc03e15aba2f74e Mon Sep 17 00:00:00 2001 From: Vika Date: Mon, 17 May 2021 04:12:48 +0300 Subject: Refactoring, easter egg, healthcheck endpoint, support for rel= indieweb APIs and preparation for onboarding --- src/micropub/mod.rs | 7 ++++--- src/micropub/post.rs | 7 ++++--- 2 files changed, 8 insertions(+), 6 deletions(-) (limited to 'src/micropub') diff --git a/src/micropub/mod.rs b/src/micropub/mod.rs index ec5cd87..9bc553c 100644 --- a/src/micropub/mod.rs +++ b/src/micropub/mod.rs @@ -1,5 +1,6 @@ -mod get; -mod post; +pub mod get; +pub mod post; pub use get::get_handler; -pub use post::post_handler; \ No newline at end of file +pub use post::post_handler; +pub use post::normalize_mf2; \ No newline at end of file diff --git a/src/micropub/post.rs b/src/micropub/post.rs index c1efd61..6183906 100644 --- a/src/micropub/post.rs +++ b/src/micropub/post.rs @@ -47,7 +47,7 @@ fn get_folder_from_type(post_type: &str) -> String { }).to_string() } -fn normalize_mf2(mut body: serde_json::Value, user: &User) -> (String, serde_json::Value) { +pub fn normalize_mf2(mut body: serde_json::Value, user: &User) -> (String, serde_json::Value) { // Normalize the MF2 object here. let me = &user.me; let published: DateTime; @@ -150,9 +150,10 @@ fn normalize_mf2(mut body: serde_json::Value, user: &User) -> (String, serde_jso return (body["properties"]["uid"][0].as_str().unwrap().to_string(), body) } -async fn new_post(req: Request>, body: serde_json::Value) -> Result { +pub async fn new_post(req: Request>, body: serde_json::Value) -> Result { // First, check for rights. let user = req.ext::().unwrap(); + let storage = &req.state().storage; if !user.check_scope("create") { return error_json!(401, "invalid_scope", "Not enough privileges to post. Try a token with a \"create\" scope instead.") } @@ -169,7 +170,7 @@ async fn new_post(req: Request>, body: serde_jso return error_json!(403, "forbidden", "You're trying to post to someone else's website...") } - let storage = &req.state().storage; + match storage.post_exists(&uid).await { Ok(exists) => if exists { return error_json!(409, "already_exists", format!("A post with the exact same UID already exists in the database: {}", uid)) -- cgit 1.4.1