From 8964a0330d77fe5a75d33c504791db601d2b0ac7 Mon Sep 17 00:00:00 2001 From: Vika Date: Wed, 23 Mar 2022 04:34:56 +0300 Subject: Get rid of todo!() invocations This stubs the neccesary code with enough stuff that it will work and be accepted by most compliant Micropub implementations. Later, this can be extended when the neccesary amendments and refactors are done. --- src/micropub/mod.rs | 36 ++++++++++++++++++++++++++++++++---- 1 file changed, 32 insertions(+), 4 deletions(-) (limited to 'src/micropub') diff --git a/src/micropub/mod.rs b/src/micropub/mod.rs index fbab582..ac038f8 100644 --- a/src/micropub/mod.rs +++ b/src/micropub/mod.rs @@ -569,7 +569,8 @@ async fn _query( QueryType::SyndicateTo ], "channels": channels, - "_kittybox_authority": user_authority.as_str() + "_kittybox_authority": user_authority.as_str(), + "syndicate-to": [] }).as_object().unwrap())) }, QueryType::Source => { @@ -596,17 +597,44 @@ async fn _query( )) }, Err(err) => { - return Box::new(warp::reply::json(&MicropubError::new( + Box::new(warp::reply::json(&MicropubError::new( ErrorType::InternalServerError, &format!("Backend error: {}", err) ))) } } }, - None => todo!() + None => { + // Here, one should probably attempt to query at least the main feed and collect posts + // Using a pre-made query function can't be done because it does unneeded filtering + // Don't implement for now, this is optional + Box::new(warp::reply::with_status( + warp::reply::json(&MicropubError::new( + ErrorType::InvalidRequest, + "Querying for post list is not implemented yet." + )), + StatusCode::BAD_REQUEST + )) + } } }, - _ => todo!() + QueryType::Channel => { + let channels: Vec = match db.get_channels(user_authority.as_str()).await { + Ok(chans) => chans, + Err(err) => return Box::new(warp::reply::with_status( + warp::reply::json(&MicropubError::new( + ErrorType::InternalServerError, + &format!("Error fetching channels: {}", err) + )), + StatusCode::INTERNAL_SERVER_ERROR + )) + }; + + Box::new(warp::reply::json(&json!({ "channels": channels }))) + }, + QueryType::SyndicateTo => { + Box::new(warp::reply::json(&json!({ "syndicate-to": [] }))) + } } } -- cgit 1.4.1