Constellation, Spacedust, Slingshot, UFOs: atproto crates and services for microcosm
0

Configure Feed

Select the types of activity you want to include in your feed.

serve openapi as the home page

+57
+1
Cargo.lock
··· 3808 3808 "dropshot", 3809 3809 "env_logger", 3810 3810 "fjall", 3811 + "http", 3811 3812 "jetstream", 3812 3813 "log", 3813 3814 "lsm-tree",
+1
ufos/Cargo.toml
··· 12 12 dropshot = "0.16.0" 13 13 env_logger = "0.11.7" 14 14 fjall = { version = "2.8.0", features = ["lz4"] } 15 + http = "1.3.1" 15 16 jetstream = { path = "../jetstream" } 16 17 log = "0.4.26" 17 18 lsm-tree = "2.6.6"
+29
ufos/src/index_html.rs
··· 1 + pub const INDEX_HTML: &str = r#"<!DOCTYPE html> 2 + <html lang="en"> 3 + <head> 4 + <meta charset="utf-8" /> 5 + <title>UFOs API Documentation</title> 6 + <meta name="viewport" content="width=device-width, initial-scale=1" /> 7 + <meta name="description" content="API Documentation for UFOs: Samples and stats for all atproto lexicons." /> 8 + <link rel="stylesheet" href="https://unpkg.com/swagger-ui-dist@5.11.0/swagger-ui.css" /> 9 + </head> 10 + <body> 11 + <div id="swagger-ui"></div> 12 + <script src="https://unpkg.com/swagger-ui-dist@5.11.0/swagger-ui-bundle.js" crossorigin></script> 13 + <script src="https://unpkg.com/swagger-ui-dist@5.11.0/swagger-ui-standalone-preset.js" crossorigin></script> 14 + <script> 15 + window.onload = () => { 16 + window.ui = SwaggerUIBundle({ 17 + url: '/openapi', 18 + dom_id: '#swagger-ui', 19 + presets: [ 20 + SwaggerUIBundle.presets.apis, 21 + SwaggerUIStandalonePreset 22 + ], 23 + layout: "StandaloneLayout", 24 + }); 25 + }; 26 + </script> 27 + </body> 28 + </html> 29 + "#;
+2
ufos/src/lib.rs
··· 2 2 pub mod db_types; 3 3 pub mod error; 4 4 pub mod file_consumer; 5 + pub mod index_html; 5 6 pub mod server; 6 7 pub mod storage; 7 8 pub mod storage_fjall; ··· 212 213 } 213 214 214 215 #[derive(Debug, Serialize, JsonSchema)] 216 + #[serde(rename_all = "camelCase")] 215 217 pub enum ConsumerInfo { 216 218 Jetstream { 217 219 endpoint: String,
+24
ufos/src/server.rs
··· 1 + use crate::index_html::INDEX_HTML; 1 2 use crate::storage::StoreReader; 2 3 use crate::{ConsumerInfo, Nsid, TopCollections, UFOsRecord}; 3 4 use dropshot::endpoint; 4 5 use dropshot::ApiDescription; 6 + use dropshot::Body; 5 7 use dropshot::ConfigDropshot; 6 8 use dropshot::ConfigLogging; 7 9 use dropshot::ConfigLoggingLevel; ··· 11 13 use dropshot::Query; 12 14 use dropshot::RequestContext; 13 15 use dropshot::ServerBuilder; 16 + use http::{Response, StatusCode}; 14 17 use schemars::JsonSchema; 15 18 use serde::{Deserialize, Serialize}; 16 19 use std::collections::HashMap; ··· 21 24 storage: Box<dyn StoreReader>, 22 25 } 23 26 27 + /// Serve index page as html 28 + #[endpoint { 29 + method = GET, 30 + path = "/", 31 + /* 32 + * not useful to have this in openapi 33 + */ 34 + unpublished = true, 35 + }] 36 + async fn index(_ctx: RequestContext<Context>) -> Result<Response<Body>, HttpError> { 37 + Ok(Response::builder() 38 + .status(StatusCode::OK) 39 + .header(http::header::CONTENT_TYPE, "text/html") 40 + .body(INDEX_HTML.into())?) 41 + } 42 + 24 43 /// Meta: get the openapi spec for this api 25 44 #[endpoint { 26 45 method = GET, 27 46 path = "/openapi", 47 + /* 48 + * not useful to have this in openapi 49 + */ 50 + unpublished = true, 28 51 }] 29 52 async fn get_openapi(ctx: RequestContext<Context>) -> OkCorsResponse<serde_json::Value> { 30 53 let spec = (*ctx.context().spec).clone(); ··· 214 237 215 238 let mut api = ApiDescription::new(); 216 239 240 + api.register(index).unwrap(); 217 241 api.register(get_openapi).unwrap(); 218 242 api.register(get_meta_info).unwrap(); 219 243 api.register(get_records_by_collections).unwrap();