about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorVika <vika@fireburn.ru>2024-03-04 04:48:03 +0300
committerVika <vika@fireburn.ru>2024-03-04 04:48:03 +0300
commit596c64818f6cdb0567c30a599861f74ee0898cd9 (patch)
treead958bd1baad2c682607a63308bb47e3fb217892 /src
parentefc10086cbb6726c3728c8edda93b8fd00436717 (diff)
downloadkittybox-596c64818f6cdb0567c30a599861f74ee0898cd9.tar.zst
Expose ?q=category queries in Micropub API
Diffstat (limited to 'src')
-rw-r--r--src/micropub/mod.rs16
1 files changed, 15 insertions, 1 deletions
diff --git a/src/micropub/mod.rs b/src/micropub/mod.rs
index 4a501bb..835457f 100644
--- a/src/micropub/mod.rs
+++ b/src/micropub/mod.rs
@@ -26,6 +26,7 @@ enum QueryType {
     Config,
     Channel,
     SyndicateTo,
+    Category
 }
 
 #[derive(Serialize, Deserialize, Debug)]
@@ -593,7 +594,8 @@ pub(crate) async fn query<D: Storage, A: AuthBackend>(
                     QueryType::Source,
                     QueryType::Config,
                     QueryType::Channel,
-                    QueryType::SyndicateTo
+                    QueryType::SyndicateTo,
+                    QueryType::Category
                 ],
                 "channels": channels,
                 "_kittybox_authority": user.me.as_str(),
@@ -643,6 +645,18 @@ pub(crate) async fn query<D: Storage, A: AuthBackend>(
         },
         QueryType::SyndicateTo => {
             axum::response::Json(json!({ "syndicate-to": [] })).into_response()
+        },
+        QueryType::Category => {
+            let categories = match db.categories(&user_domain).await {
+                Ok(categories) => categories,
+                Err(err) => {
+                    return MicropubError::new(
+                        ErrorType::InternalServerError,
+                        &format!("Error fetching categories: {}", err)
+                    ).into_response()
+                }
+            };
+            axum::response::Json(json!({ "categories": categories })).into_response()
         }
     }
 }