diff options
| -rw-r--r-- | .gitignore | 2 | ||||
| -rw-r--r-- | index.ts | 1 | ||||
| -rw-r--r-- | lib/invoices.ts | 19 | ||||
| -rw-r--r-- | lib/payments.ts | 1 | ||||
| -rwxr-xr-x | mklittlefs | bin | 0 -> 109520 bytes | |||
| -rw-r--r-- | routes/users.ts | 28 |
6 files changed, 42 insertions, 9 deletions
@@ -16,3 +16,5 @@ watcher.log res req nobal.sh +littlefs.img +printer @@ -106,6 +106,7 @@ app.get("/verify/:code", users.verify); app.post("/request", auth, users.request); app.post("/forgot", users.forgot); app.post("/login", users.login); +app.post("/printer", users.printer); app.get("/subscriptions", auth, users.subscriptions); app.post("/subscription", auth, users.subscription); diff --git a/lib/invoices.ts b/lib/invoices.ts index 5e59fd83..3259c46b 100644 --- a/lib/invoices.ts +++ b/lib/invoices.ts @@ -14,7 +14,6 @@ const lq = rpc(config.liquid); export const generate = async ({ invoice, user }) => { let { bolt11, - bolt12, aid, currency, expiry, @@ -73,13 +72,6 @@ export const generate = async ({ invoice, user }) => { if (r.payee !== nodeid) fail("invalid invoice"); amount = Math.round(r.amount_msat / 1000); r.bolt11 = bolt11; - } else if (bolt12) { - r = await ln.offer({ - amount_msat: amount ? `${amount + tip}sat` : "any", - label: id, - description: memo || "", - absolute_expiry: expiry, - }); } else { expiry ||= 60 * 60 * 24 * 30; r = await ln.invoice({ @@ -94,6 +86,17 @@ export const generate = async ({ invoice, user }) => { hash = r.bolt11; text = r.bolt11; + } else if (type === types.bolt12) { + const r = await ln.offer({ + amount: amount ? `${amount + tip}sat` : "any", + label: id, + description: memo || "", + absolute_expiry: expiry, + }); + + console.log("R", r); + hash = r.bolt12; + text = r.bolt12; } else if (type === types.bitcoin) { hash = await bc.getNewAddress(); text = bip21(hash, invoice); diff --git a/lib/payments.ts b/lib/payments.ts index af838758..3cc5a501 100644 --- a/lib/payments.ts +++ b/lib/payments.ts @@ -38,6 +38,7 @@ export const types = { liquid: "liquid", ecash: "ecash", reconcile: "reconcile", + bolt12: "bolt12", }; export const debit = async ({ diff --git a/mklittlefs b/mklittlefs Binary files differnew file mode 100755 index 00000000..2d521801 --- /dev/null +++ b/mklittlefs 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" }); + } + }, }; |
