diff options
| author | Adam Soltys <[email protected]> | 2024-12-18 13:44:00 -0800 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2024-12-18 13:44:00 -0800 |
| commit | 93d494bc5d149458ea50a8d7017e155b2e1936ab (patch) | |
| tree | 3b4b8500089228737f1b2c3005b8d69ebd0f068c /routes | |
| parent | ad8605c99dab31e41d23918e3811bb3bbf1b38b5 (diff) | |
| download | coinos-server-93d494bc5d149458ea50a8d7017e155b2e1936ab.tar.gz coinos-server-93d494bc5d149458ea50a8d7017e155b2e1936ab.zip | |
printer endpoint
Diffstat (limited to 'routes')
| -rw-r--r-- | routes/users.ts | 28 |
1 files changed, 27 insertions, 1 deletions
diff --git a/routes/users.ts b/routes/users.ts index 8a11b662..5c5f1a6f 100644 --- a/routes/users.ts +++ b/routes/users.ts @@ -1,4 +1,5 @@ -import { appendFile } from "node:fs/promises"; +import { createReadStream } from "node:fs"; +import { appendFile, unlink } from "node:fs/promises"; import config from "$config"; import { requirePin } from "$lib/auth"; import { db, g, s } from "$lib/db"; @@ -12,6 +13,7 @@ import upload from "$lib/upload"; import { bail, fail, getUser, pick } from "$lib/utils"; import whitelist from "$lib/whitelist"; import rpc from "@coinos/rpc"; +import { $ } from "bun"; import jwt from "jsonwebtoken"; import { nip19 } from "nostr-tools"; import { authenticator } from "otplib"; @@ -754,4 +756,28 @@ export default { bail(res, e.message); } }, + + async printer(req, res) { + const { ssid, key, username, password } = req.body; + const dir = "./printer"; + const path = `${dir}/config.txt`; + + try { + await unlink(path); + await appendFile(path, `${ssid}\n`, "utf8"); + await appendFile(path, `${key}\n`, "utf8"); + await appendFile(path, `${username}\n`, "utf8"); + await appendFile(path, `${password}\n`, "utf8"); + + const output = "./littlefs.img"; + await $`./mklittlefs -c ${dir} -p 256 -b 4096 -s 0x20000 ${output}`; + + res.header("Content-Type", "application/octet-stream"); + res.header("Content-Disposition", "attachment; filename=littlefs.img"); + console.log("sending back"); + return res.send(createReadStream(output)); + } catch (error) { + res.code(500).send({ error: "Failed to generate LittleFS image" }); + } + }, }; |
