Typstify /tictactoe endpoint
This commit is contained in:
parent
d32be913fd
commit
8bece23baf
8 changed files with 64 additions and 84 deletions
|
|
@ -0,0 +1,3 @@
|
|||
{
|
||||
"feed": false
|
||||
}
|
||||
1
showbits-thermal-printer/src/documents/tictactoe/lib
Symbolic link
1
showbits-thermal-printer/src/documents/tictactoe/lib
Symbolic link
|
|
@ -0,0 +1 @@
|
|||
../lib
|
||||
20
showbits-thermal-printer/src/documents/tictactoe/main.typ
Normal file
20
showbits-thermal-printer/src/documents/tictactoe/main.typ
Normal 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
|
||||
}
|
||||
34
showbits-thermal-printer/src/documents/tictactoe/mod.rs
Normal file
34
showbits-thermal-printer/src/documents/tictactoe/mod.rs
Normal 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(())
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue