aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2024-12-18 13:44:00 -0800
committerAdam Soltys <[email protected]>2024-12-18 13:44:00 -0800
commit93d494bc5d149458ea50a8d7017e155b2e1936ab (patch)
tree3b4b8500089228737f1b2c3005b8d69ebd0f068c
parentad8605c99dab31e41d23918e3811bb3bbf1b38b5 (diff)
downloadcoinos-server-93d494bc5d149458ea50a8d7017e155b2e1936ab.tar.gz
coinos-server-93d494bc5d149458ea50a8d7017e155b2e1936ab.zip
printer endpoint
-rw-r--r--.gitignore2
-rw-r--r--index.ts1
-rw-r--r--lib/invoices.ts19
-rw-r--r--lib/payments.ts1
-rwxr-xr-xmklittlefsbin0 -> 109520 bytes
-rw-r--r--routes/users.ts28
6 files changed, 42 insertions, 9 deletions
diff --git a/.gitignore b/.gitignore
index ec4accfc..312970e2 100644
--- a/.gitignore
+++ b/.gitignore
@@ -16,3 +16,5 @@ watcher.log
res
req
nobal.sh
+littlefs.img
+printer
diff --git a/index.ts b/index.ts
index abdbeef1..8af31a85 100644
--- a/index.ts
+++ b/index.ts
@@ -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
new file mode 100755
index 00000000..2d521801
--- /dev/null
+++ b/mklittlefs
Binary files differ
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" });
+ }
+ },
};