diff options
Diffstat (limited to 'src/micropub')
-rw-r--r-- | src/micropub/mod.rs | 7 | ||||
-rw-r--r-- | src/micropub/post.rs | 7 |
2 files changed, 8 insertions, 6 deletions
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<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)) |