very fast at protocol indexer with flexible filtering, xrpc queries, cursor-backed event stream, and more, built on fjall
rust fjall at-protocol atproto indexer
at main 59 lines 1.5 kB view raw
1use crate::control::Hydrant; 2use axum::{ 3 Json, Router, 4 extract::State, 5 http::StatusCode, 6 routing::{delete, post}, 7}; 8use serde::Deserialize; 9 10pub fn router() -> Router<Hydrant> { 11 Router::new() 12 .route("/db/train", post(handle_train_dict)) 13 .route("/db/compact", post(handle_compact)) 14 .route("/cursors", delete(handle_reset_cursor)) 15} 16 17pub async fn handle_train_dict( 18 State(hydrant): State<Hydrant>, 19) -> Result<StatusCode, (StatusCode, String)> { 20 hydrant 21 .db 22 .train_dicts() 23 .await 24 .map_err(|e| (StatusCode::INTERNAL_SERVER_ERROR, e.to_string()))?; 25 Ok(StatusCode::OK) 26} 27 28#[derive(Deserialize)] 29pub struct ResetCursorBody { 30 pub key: String, 31} 32 33pub async fn handle_reset_cursor( 34 State(hydrant): State<Hydrant>, 35 Json(body): Json<ResetCursorBody>, 36) -> Result<StatusCode, (StatusCode, String)> { 37 hydrant 38 .crawler 39 .reset_cursor(&body.key) 40 .await 41 .map_err(|e| (StatusCode::INTERNAL_SERVER_ERROR, e.to_string()))?; 42 hydrant 43 .firehose 44 .reset_cursor(&body.key) 45 .await 46 .map_err(|e| (StatusCode::INTERNAL_SERVER_ERROR, e.to_string()))?; 47 Ok(StatusCode::OK) 48} 49 50pub async fn handle_compact( 51 State(hydrant): State<Hydrant>, 52) -> Result<StatusCode, (StatusCode, String)> { 53 hydrant 54 .db 55 .compact() 56 .await 57 .map_err(|e| (StatusCode::INTERNAL_SERVER_ERROR, e.to_string()))?; 58 Ok(StatusCode::OK) 59}