about summary refs log tree commit diff
path: root/src/micropub
diff options
context:
space:
mode:
authorVika <vika@fireburn.ru>2022-03-23 04:34:56 +0300
committerVika <vika@fireburn.ru>2022-03-23 04:34:56 +0300
commit8964a0330d77fe5a75d33c504791db601d2b0ac7 (patch)
tree04cc9ec0a9d9d84a390474d902f5da7e3c71b7d9 /src/micropub
parent45b3a5acc5fdae7d9ced9607e0f29352bf7a3748 (diff)
downloadkittybox-8964a0330d77fe5a75d33c504791db601d2b0ac7.tar.zst
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.
Diffstat (limited to 'src/micropub')
-rw-r--r--src/micropub/mod.rs36
1 files changed, 32 insertions, 4 deletions
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<D: Storage>(
                     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<D: Storage>(
                             ))
                         },
                         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<MicropubChannel> = 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": [] })))
+        }
     }
 }