Add banner endpoint

This commit is contained in:
Joscha 2025-07-19 22:04:52 +02:00
parent b192bf06e1
commit 524670b7c9
8 changed files with 97 additions and 0 deletions

View file

@ -1,5 +1,6 @@
use showbits_typst::Typst;
pub mod banner;
pub mod calendar;
pub mod cells;
pub mod chat;

View file

@ -0,0 +1,4 @@
{
"text": "Hello world! äöüßÄÖÜẞ😒",
"feed": false
}

View file

@ -0,0 +1 @@
../lib

View file

@ -0,0 +1,11 @@
#import "lib/main.typ" as lib;
#show: it => lib.init(it)
#let data = json("data.json")
#set text(size: 16pt * 16)
#align(center, rotate(90deg, data.text, reflow: true))
#if data.feed {
lib.feed
}

View file

@ -0,0 +1,29 @@
use axum::{Form, extract::State};
use serde::{Deserialize, Serialize};
use crate::server::{Server, somehow};
#[derive(Serialize)]
struct Data {
text: String,
feed: bool,
}
#[derive(Deserialize)]
pub struct FormData {
pub text: String,
pub feed: Option<bool>,
}
pub async fn post(server: State<Server>, Form(form): Form<FormData>) -> somehow::Result<()> {
let data = Data {
text: form.text,
feed: form.feed.unwrap_or(true),
};
let typst = super::typst_with_lib()
.with_json("/data.json", &data)
.with_main_file(include_str!("main.typ"));
server.print_typst(typst).await
}

View file

@ -43,6 +43,7 @@ pub async fn run(
.route("/fonts/{*path}", get(r#static::get_font))
.route("/photo.html", get(r#static::get_photo))
// API
.route("/api/banner", post(documents::banner::post))
.route("/api/calendar", post(documents::calendar::post))
.route("/api/cells", post(documents::cells::post))
.route("/api/chat", post(documents::chat::post))