From 596c64818f6cdb0567c30a599861f74ee0898cd9 Mon Sep 17 00:00:00 2001 From: Vika Date: Mon, 4 Mar 2024 04:48:03 +0300 Subject: Expose ?q=category queries in Micropub API --- src/micropub/mod.rs | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'src/micropub') 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( 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( }, 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() } } } -- cgit 1.4.1