diff options
author | Vika <vika@fireburn.ru> | 2021-05-17 04:12:48 +0300 |
---|---|---|
committer | Vika <vika@fireburn.ru> | 2021-05-17 04:12:48 +0300 |
commit | 696ae495aca701c3431710e5dfc03e15aba2f74e (patch) | |
tree | 3b58d7cb23a8edd5fdb7121ab420ed60a9af64cb /src/micropub | |
parent | 3dbe61f57873881dfbf5da8a335762a0e1dccbb5 (diff) | |
download | kittybox-696ae495aca701c3431710e5dfc03e15aba2f74e.tar.zst |
Refactoring, easter egg, healthcheck endpoint, support for rel= indieweb APIs and preparation for onboarding
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)) |