about summary refs log tree commit diff
path: root/src/micropub/util.rs
diff options
context:
space:
mode:
authorVika <vika@fireburn.ru>2025-04-09 23:31:02 +0300
committerVika <vika@fireburn.ru>2025-04-09 23:31:57 +0300
commit8826d9446e6c492db2243b9921e59ce496027bef (patch)
tree63738aa9001cb73b11cb0e974e93129bcdf1adbb /src/micropub/util.rs
parent519cadfbb298f50cbf819dde757037ab56e2863e (diff)
downloadkittybox-8826d9446e6c492db2243b9921e59ce496027bef.tar.zst
cargo fmt
Change-Id: I80e81ebba3f0cdf8c094451c9fe3ee4126b8c888
Diffstat (limited to 'src/micropub/util.rs')
-rw-r--r--src/micropub/util.rs70
1 files changed, 32 insertions, 38 deletions
diff --git a/src/micropub/util.rs b/src/micropub/util.rs
index 99aec8e..8c5d5e9 100644
--- a/src/micropub/util.rs
+++ b/src/micropub/util.rs
@@ -1,7 +1,7 @@
 use crate::database::Storage;
-use kittybox_indieauth::TokenData;
 use chrono::prelude::*;
 use core::iter::Iterator;
+use kittybox_indieauth::TokenData;
 use newbase60::num_to_sxg;
 use serde_json::json;
 use std::convert::TryInto;
@@ -35,7 +35,7 @@ fn reset_dt(post: &mut serde_json::Value) -> DateTime<FixedOffset> {
 
 pub struct NormalizedPost {
     pub id: String,
-    pub post: serde_json::Value
+    pub post: serde_json::Value,
 }
 
 pub fn normalize_mf2(mut body: serde_json::Value, user: &TokenData) -> NormalizedPost {
@@ -142,12 +142,12 @@ pub fn normalize_mf2(mut body: serde_json::Value, user: &TokenData) -> Normalize
     }
     // If there is no explicit channels, and the post is not marked as "unlisted",
     // post it to one of the default channels that makes sense for the post type.
-    if body["properties"]["channel"][0].as_str().is_none() && (!body["properties"]["visibility"]
-        .as_array()
-        .map(|v| v.contains(
-            &serde_json::Value::String("unlisted".to_owned())
-        )).unwrap_or(false)
-    ) {
+    if body["properties"]["channel"][0].as_str().is_none()
+        && (!body["properties"]["visibility"]
+            .as_array()
+            .map(|v| v.contains(&serde_json::Value::String("unlisted".to_owned())))
+            .unwrap_or(false))
+    {
         match body["type"][0].as_str() {
             Some("h-entry") => {
                 // Set the channel to the main channel...
@@ -249,7 +249,7 @@ mod tests {
             client_id: "https://quill.p3k.io/".parse().unwrap(),
             scope: kittybox_indieauth::Scopes::new(vec![kittybox_indieauth::Scope::Create]),
             exp: Some(u64::MAX),
-            iat: Some(0)
+            iat: Some(0),
         }
     }
 
@@ -279,12 +279,15 @@ mod tests {
             }
         });
 
-        let NormalizedPost { id: _, post: normalized } = normalize_mf2(
-            mf2.clone(),
-            &token_data()
-        );
+        let NormalizedPost {
+            id: _,
+            post: normalized,
+        } = normalize_mf2(mf2.clone(), &token_data());
         assert!(
-            normalized["properties"]["channel"].as_array().unwrap_or(&vec![]).is_empty(),
+            normalized["properties"]["channel"]
+                .as_array()
+                .unwrap_or(&vec![])
+                .is_empty(),
             "Returned post was added to a channel despite the `unlisted` visibility"
         );
     }
@@ -300,10 +303,10 @@ mod tests {
             }
         });
 
-        let NormalizedPost { id, post: normalized } = normalize_mf2(
-            mf2.clone(),
-            &token_data(),
-        );
+        let NormalizedPost {
+            id,
+            post: normalized,
+        } = normalize_mf2(mf2.clone(), &token_data());
         assert_eq!(
             normalized["properties"]["uid"][0], mf2["properties"]["uid"][0],
             "UID was replaced"
@@ -325,10 +328,10 @@ mod tests {
             }
         });
 
-        let NormalizedPost { id: _, post: normalized } = normalize_mf2(
-            mf2.clone(),
-            &token_data(),
-        );
+        let NormalizedPost {
+            id: _,
+            post: normalized,
+        } = normalize_mf2(mf2.clone(), &token_data());
 
         assert_eq!(
             normalized["properties"]["channel"],
@@ -347,10 +350,10 @@ mod tests {
             }
         });
 
-        let NormalizedPost { id: _, post: normalized } = normalize_mf2(
-            mf2.clone(),
-            &token_data(),
-        );
+        let NormalizedPost {
+            id: _,
+            post: normalized,
+        } = normalize_mf2(mf2.clone(), &token_data());
 
         assert_eq!(
             normalized["properties"]["channel"][0],
@@ -367,10 +370,7 @@ mod tests {
             }
         });
 
-        let NormalizedPost { id, post } = normalize_mf2(
-            mf2,
-            &token_data(),
-        );
+        let NormalizedPost { id, post } = normalize_mf2(mf2, &token_data());
         assert_eq!(
             post["properties"]["published"]
                 .as_array()
@@ -432,10 +432,7 @@ mod tests {
             },
         });
 
-        let NormalizedPost { id: _, post } = normalize_mf2(
-            mf2,
-            &token_data(),
-        );
+        let NormalizedPost { id: _, post } = normalize_mf2(mf2, &token_data());
         assert!(
             post["properties"]["url"]
                 .as_array()
@@ -461,10 +458,7 @@ mod tests {
             }
         });
 
-        let NormalizedPost { id, post } = normalize_mf2(
-            mf2,
-            &token_data(),
-        );
+        let NormalizedPost { id, post } = normalize_mf2(mf2, &token_data());
         assert_eq!(
             post["properties"]["uid"][0], id,
             "UID of a post and its supposed location don't match"