|
20 | 20 | //! - Мб рейтлимит |
21 | 21 | //! - Бан лист (:)) |
22 | 22 |
|
| 23 | +pub mod lock; |
23 | 24 | pub mod logger; |
24 | 25 | pub mod png; |
25 | 26 | pub mod skin; |
26 | 27 |
|
27 | | -use ohkami::{Ohkami, Route, claw::status}; |
| 28 | +use std::sync::Arc; |
28 | 29 |
|
29 | | -use crate::app::skin::skin_router; |
| 30 | +use ohkami::{ |
| 31 | + Ohkami, Route, |
| 32 | + claw::{content::Html, status}, |
| 33 | + fang::Context, |
| 34 | + openapi, |
| 35 | +}; |
| 36 | +use tokio::fs; |
| 37 | + |
| 38 | +const DOC_HTML_TEMPLATE: &str = include_str!("../.static/scalar.html"); |
| 39 | +const DOC_HTML_PATH: &str = "./static/doc.html"; |
| 40 | + |
| 41 | +use crate::{app::skin::skin_router, cache::Cache, rsync::lock::Lock}; |
| 42 | +#[inline] |
30 | 43 | async fn health_check() -> status::NoContent { |
31 | 44 | status::NoContent |
32 | 45 | } |
33 | 46 |
|
34 | | -pub async fn app() { |
35 | | - Ohkami::new(( |
| 47 | +async fn doc() -> Html { |
| 48 | + Html(fs::read_to_string(DOC_HTML_PATH).await.expect("wtf")) |
| 49 | +} |
| 50 | + |
| 51 | +pub struct AppState<'a> { |
| 52 | + pub lock: Lock, |
| 53 | + pub cache: Cache<'a>, |
| 54 | +} |
| 55 | + |
| 56 | +pub async fn app( |
| 57 | + lock: Lock, |
| 58 | + cache: Cache<'static>, |
| 59 | +) { |
| 60 | + let router = Ohkami::new(( |
| 61 | + Context::new(Arc::new(AppState { |
| 62 | + lock, |
| 63 | + cache, |
| 64 | + })), |
36 | 65 | "/skin".By(skin_router()), |
37 | 66 | "/uvs".GET(health_check), |
38 | 67 | "/health".GET(health_check), |
39 | | - )) |
40 | | - .howl("localhost:3000") |
| 68 | + )); |
| 69 | + |
| 70 | + let bytes = router.__openapi_document_bytes__(openapi::OpenAPI { |
| 71 | + title: "DDNET Tee generator", |
| 72 | + version: "1", |
| 73 | + servers: &[], |
| 74 | + }); |
| 75 | + fs::write( |
| 76 | + DOC_HTML_PATH, |
| 77 | + DOC_HTML_TEMPLATE.replace("$spec", &String::from_utf8(bytes).unwrap()), |
| 78 | + ) |
41 | 79 | .await |
| 80 | + .expect("wtf"); |
| 81 | + |
| 82 | + let router = Ohkami::new(("/doc".GET(doc), "/".By(router))); |
| 83 | + router.howl("localhost:3000").await; |
42 | 84 | } |
0 commit comments