Typstify /tictactoe endpoint

This commit is contained in:
Joscha 2025-03-01 22:57:02 +01:00
parent d32be913fd
commit 8bece23baf
8 changed files with 64 additions and 84 deletions

View file

@ -0,0 +1,3 @@
{
"feed": false
}

View file

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

View file

@ -0,0 +1,20 @@
#import "@preview/cetz:0.3.2"
#import "lib/main.typ" as lib;
#show: it => lib.init(it)
#let data = json("data.json")
#cetz.canvas(
length: lib.width,
{
import cetz.draw: *
line((1 / 3, 0), (1 / 3, 1), stroke: 4pt)
line((2 / 3, 0), (2 / 3, 1), stroke: 4pt)
line((0, 1 / 3), (1, 1 / 3), stroke: 4pt)
line((0, 2 / 3), (1, 2 / 3), stroke: 4pt)
},
)
#if data.feed {
lib.feed
}

View file

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