diff options
Diffstat (limited to 'src/micropub/post.rs')
-rw-r--r-- | src/micropub/post.rs | 7 |
1 files changed, 4 insertions, 3 deletions
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<FixedOffset>; @@ -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<S: Storage>(req: Request<ApplicationState<S>>, body: serde_json::Value) -> Result { +pub async fn new_post<S: Storage>(req: Request<ApplicationState<S>>, body: serde_json::Value) -> Result { // First, check for rights. let user = req.ext::<User>().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<S: Storage>(req: Request<ApplicationState<S>>, 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)) |