use std::sync::Arc; use anyhow::Result; use atrium_api::com::atproto::sync::request_crawl; use bytes::Buf; use http_body_util::BodyExt; use hyper::{body::Incoming, Request, Response}; use crate::{ http::{body_empty, body_full, ServerResponse}, indexer::index_server, RelayServer, }; pub async fn handle_request_crawl( server: Arc, req: Request, ) -> Result { let body = req.collect().await?.aggregate(); let input = match serde_json::from_reader::<_, request_crawl::Input>(body.reader()) { Ok(input) => input, Err(_) => { // TODO: surely we can build out an XRPC abstraction or something return Ok(Response::builder().status(400).body(body_full( r#"{ "error": "InvalidRequest", "message": "Failed to parse request body" }"#, ))?); } }; let hostname = input.data.hostname; tokio::task::spawn(async move { if let Err(e) = index_server(server, hostname).await { tracing::warn!("encountered error subscribing to PDS: {e:?}"); } }); Ok(Response::builder().status(200).body(body_empty())?) }