about summary refs log tree commit diff
diff options
context:
space:
mode:
authorVika <vika@fireburn.ru>2023-06-22 22:36:51 +0300
committerVika <vika@fireburn.ru>2023-06-22 22:36:51 +0300
commit51c1b32ce14a2ad7615b45609924b40a5eb92fe9 (patch)
treebe5075a25f6bcd2613fd0b51a119a7fec6d5b6e9
parent37fa8a2043233c7e96422f46a4c7200f20a9cb0f (diff)
Better Micropub update object typing
-rw-r--r--kittybox-rs/src/micropub/mod.rs17
1 files changed, 13 insertions, 4 deletions
diff --git a/kittybox-rs/src/micropub/mod.rs b/kittybox-rs/src/micropub/mod.rs
index da9c6a5..a55ea15 100644
--- a/kittybox-rs/src/micropub/mod.rs
+++ b/kittybox-rs/src/micropub/mod.rs
@@ -1,3 +1,5 @@
+use std::collections::HashMap;
+
 use crate::database::{MicropubChannel, Storage, StorageError};
 use crate::indieauth::backend::AuthBackend;
 use crate::indieauth::User;
@@ -317,6 +319,12 @@ enum ActionType {
     Update,
 }
 
+#[derive(Serialize, Deserialize, Debug)]
+#[serde(untagged)]
+pub enum MicropubPropertyDeletion {
+    Properties(Vec<String>),
+    Values(HashMap<String, serde_json::Value>)
+}
 #[derive(Serialize, Deserialize)]
 struct MicropubFormAction {
     action: ActionType,
@@ -324,19 +332,20 @@ struct MicropubFormAction {
 }
 
 #[derive(Serialize, Deserialize, Debug)]
-struct MicropubAction {
+pub struct MicropubAction {
     action: ActionType,
     url: String,
     #[serde(skip_serializing_if = "Option::is_none")]
-    replace: Option<serde_json::Value>,
+    replace: Option<HashMap<String, serde_json::Value>>,
     #[serde(skip_serializing_if = "Option::is_none")]
-    add: Option<serde_json::Value>,
+    add: Option<HashMap<String, serde_json::Value>>,
     #[serde(skip_serializing_if = "Option::is_none")]
-    delete: Option<serde_json::Value>,
+    delete: Option<MicropubPropertyDeletion>,
 }
 
 impl From<MicropubFormAction> for MicropubAction {
     fn from(a: MicropubFormAction) -> Self {
+        debug_assert!(matches!(a.action, ActionType::Delete));
         Self {
             action: a.action,
             url: a.url,