diff --git a/meta/dev-thermal-printer b/meta/dev-thermal-printer new file mode 100755 index 0000000..bbf6139 --- /dev/null +++ b/meta/dev-thermal-printer @@ -0,0 +1,27 @@ +#!/usr/bin/env fish + +argparse h/help p/print r/release -- $argv +and not set -ql _flag_help +or begin + echo "Usage:" (status filename) "[OPTIONS]" + echo + echo "Options:" + echo " -h, --help Show this help" + echo " -p, --print Attach to printer at /dev/usb/lp0" + echo " -r, --release Use 'cargo run --release'" + return +end + +set -l arg_release +if set -ql _flag_release + set arg_release --release +end + +set -l arg_print +if set -ql _flag_print + set arg_print -p /dev/usb/lp0 +end + +cargo run $arg_release \ + --package showbits-thermal-printer \ + -- target/queue -e target/image.png $arg_print diff --git a/meta/dev-thermal-printer-ui b/meta/dev-thermal-printer-ui new file mode 100755 index 0000000..159f4e6 --- /dev/null +++ b/meta/dev-thermal-printer-ui @@ -0,0 +1,4 @@ +#!/usr/bin/env fish + +pushd showbits-thermal-printer-ui +pnpm dev diff --git a/showbits-thermal-printer-ui/vite.config.ts b/showbits-thermal-printer-ui/vite.config.ts index 0e028fa..1997450 100644 --- a/showbits-thermal-printer-ui/vite.config.ts +++ b/showbits-thermal-printer-ui/vite.config.ts @@ -9,4 +9,7 @@ export default defineConfig({ resolve: { alias: { "@": fileURLToPath(new URL("./src", import.meta.url)) }, }, + server: { + proxy: { "/api": "http://localhost:8080" }, + }, }); diff --git a/showbits-thermal-printer/src/main.rs b/showbits-thermal-printer/src/main.rs index 7509fd2..e43c33e 100644 --- a/showbits-thermal-printer/src/main.rs +++ b/showbits-thermal-printer/src/main.rs @@ -15,12 +15,13 @@ use self::{drawer::Drawer, persistent_printer::PersistentPrinter}; #[derive(Parser)] struct Args { - /// Address the web server will listen at. - addr: String, - /// Path to the queue directory. queue: PathBuf, + /// Address the web server will listen at. + #[arg(long, short, default_value = "localhost:8080")] + address: String, + /// Path to the printer's USB device file. /// /// Usually, this is located at `/dev/usb/lp0` or a similar location. @@ -41,7 +42,7 @@ fn main() -> anyhow::Result<()> { let mut drawer = Drawer::new(rx, printer); let runtime = Runtime::new()?; - runtime.spawn(server::run(tx.clone(), args.addr)); + runtime.spawn(server::run(tx.clone(), args.address)); runtime.spawn(async move { loop { let _ = tx.send(Command::Backlog).await; diff --git a/showbits-thermal-printer/src/server.rs b/showbits-thermal-printer/src/server.rs index 72156ae..6181041 100644 --- a/showbits-thermal-printer/src/server.rs +++ b/showbits-thermal-printer/src/server.rs @@ -27,31 +27,13 @@ impl Server { pub async fn run(tx: mpsc::Sender, addr: String) -> anyhow::Result<()> { let app = Router::new() - .route( - "/calendar", - post(documents::calendar::post).fallback(get_static_file), - ) - .route( - "/cells", - post(documents::cells::post).fallback(get_static_file), - ) - .route( - "/chat", - post(documents::chat::post).fallback(get_static_file), - ) - .route("/egg", post(documents::egg::post).fallback(get_static_file)) - .route( - "/image", - post(documents::image::post).fallback(get_static_file), - ) - .route( - "/text", - post(documents::text::post).fallback(get_static_file), - ) - .route( - "/tictactoe", - post(documents::tictactoe::post).fallback(get_static_file), - ) + .route("/api/calendar", post(documents::calendar::post)) + .route("/api/cells", post(documents::cells::post)) + .route("/api/chat", post(documents::chat::post)) + .route("/api/egg", post(documents::egg::post)) + .route("/api/image", post(documents::image::post)) + .route("/api/text", post(documents::text::post)) + .route("/api/tictactoe", post(documents::tictactoe::post)) .fallback(get(get_static_file)) .layer(DefaultBodyLimit::max(32 * 1024 * 1024)) // 32 MiB .with_state(Server { tx });