aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2023-11-23 23:39:15 +0000
committerAdam Soltys <[email protected]>2023-11-23 23:39:19 +0000
commit3d38a3656103b117fe1e68fa23aca3c1410fa969 (patch)
tree36439ccee411ff8da6699f5ab160d1399065361c
parentab44bc3815c233a16586eada624672ff03e51224 (diff)
downloadcoinos-server-3d38a3656103b117fe1e68fa23aca3c1410fa969.tar.gz
coinos-server-3d38a3656103b117fe1e68fa23aca3c1410fa969.zip
new printer endpoints
-rw-r--r--index.js2
-rw-r--r--lib/mqtt.js3
-rw-r--r--lib/payments.js9
-rw-r--r--routes/users.js44
4 files changed, 39 insertions, 19 deletions
diff --git a/index.js b/index.js
index 4a645f15..6cc1fb3c 100644
--- a/index.js
+++ b/index.js
@@ -81,6 +81,8 @@ app.post("/user", auth, users.update);
app.post("/reset", auth, users.reset);
app.post("/upload/:type", users.upload);
app.get("/users/delete/:username", users.del);
+app.post("/acl", users.acl);
+app.post("/superuser", users.superuser);
app.post("/login", users.login);
diff --git a/lib/mqtt.js b/lib/mqtt.js
index df87f42e..f8e19c19 100644
--- a/lib/mqtt.js
+++ b/lib/mqtt.js
@@ -1,4 +1,5 @@
import mqtt from "mqtt";
import config from "$config";
-export default mqtt.connect("mqtt://ln.coinos.io", config.mqtt);
+export let mqtt1 = mqtt.connect("mqtt://ln.coinos.io", config.mqtt);
+export let mqtt2 = mqtt.connect("mqtt://mqtt.coinos.io", config.mqtt);
diff --git a/lib/payments.js b/lib/payments.js
index f39e2937..148a6ea1 100644
--- a/lib/payments.js
+++ b/lib/payments.js
@@ -14,7 +14,7 @@ import ffmpeg from "fluent-ffmpeg";
import fs from "fs";
import EventEmitter from "events";
import crc32 from "buffer-crc32";
-import mqtt from "$lib/mqtt";
+import { mqtt1, mqtt2 } from "$lib/mqtt";
export const types = {
internal: "internal",
@@ -176,7 +176,12 @@ export let credit = async (hash, amount, memo, ref, type = types.internal) => {
notify(user, `Received ${amount} sats`);
callWebhook(invoice, p);
- mqtt.publish(
+ mqtt1.publish(
+ username,
+ `pay:${p.amount}:${p.tip}:${p.rate}:${p.created}:${p.id}`
+ );
+
+ mqtt2.publish(
username,
`pay:${p.amount}:${p.tip}:${p.rate}:${p.created}:${p.id}`
);
diff --git a/routes/users.js b/routes/users.js
index 187ffa2e..3270e2a9 100644
--- a/routes/users.js
+++ b/routes/users.js
@@ -9,7 +9,7 @@ import {
wait,
bail,
fail,
- getUser
+ getUser,
} from "$lib/utils";
import bcrypt from "bcrypt";
import jwt from "jsonwebtoken";
@@ -98,7 +98,7 @@ export default {
username: key,
display: key.substr(0, 6),
pubkey: key,
- anon: true
+ anon: true,
};
}
@@ -116,7 +116,7 @@ export default {
"pubkey",
"display",
"prompt",
- "id"
+ "id",
];
if (user.pubkey)
@@ -141,7 +141,7 @@ export default {
pubkey,
password,
username,
- salt
+ salt,
};
user = await register(user, ip, false);
@@ -194,7 +194,7 @@ export default {
newpin,
username,
shopifyToken,
- shopifyStore
+ shopifyStore,
} = body;
if (user.pin && !(pin === user.pin)) throw new Error("Pin required");
@@ -236,7 +236,7 @@ export default {
"tokens",
"twofa",
"shopifyToken",
- "shopifyStore"
+ "shopifyStore",
];
for (let a of attributes) {
@@ -284,7 +284,7 @@ export default {
if (!token) fail();
user = await got(`${classic}/admin/migrate/${username}?zero=true`, {
- headers: { authorization: `Bearer ${config.admin}` }
+ headers: { authorization: `Bearer ${config.admin}` },
}).json();
let { balance } = user;
@@ -297,7 +297,7 @@ export default {
id: uid,
about: user.address,
migrated: true,
- haspin: !!user.pin
+ haspin: !!user.pin,
};
await s(`user:${username}`, uid);
@@ -305,7 +305,7 @@ export default {
await s(`balance:${uid}`, balance);
let payments = await got(`${classic}/payments`, {
- headers: { authorization: `Bearer ${token}` }
+ headers: { authorization: `Bearer ${token}` },
}).json();
for (let p of payments) {
@@ -315,7 +315,7 @@ export default {
"confirmed",
"rate",
"currency",
- "preimage"
+ "preimage",
]);
n.id = v4();
n.created = parseISO(p.createdAt).getTime();
@@ -333,7 +333,7 @@ export default {
u = await got(
`${classic}/admin/migrate/${p.with.username.toLowerCase()}`,
{
- headers: { authorization: `Bearer ${config.admin}` }
+ headers: { authorization: `Bearer ${config.admin}` },
}
).json();
@@ -401,7 +401,7 @@ export default {
if (!subscriptions) subscriptions = [];
if (
!subscriptions.find(
- s => JSON.stringify(s) === JSON.stringify(subscription)
+ (s) => JSON.stringify(s) === JSON.stringify(subscription)
)
)
subscriptions.push(subscription);
@@ -439,8 +439,10 @@ export default {
let contacts = (await g(`${id}:contacts`)) || [];
for (let { ref } of (
- await Promise.all(payments.reverse().map(async id => await g(`payment:${id}`)))
- ).filter(p => p.type === types.internal && p.ref)) {
+ await Promise.all(
+ payments.reverse().map(async (id) => await g(`payment:${id}`))
+ )
+ ).filter((p) => p.type === types.internal && p.ref)) {
if (!~contacts.findIndex(({ id }) => id === ref)) {
contacts.unshift(await g(`user:${ref}`));
}
@@ -448,7 +450,7 @@ export default {
await s(`${id}:contacts`, contacts);
- res.send(contacts.map(u => pick(u, fields)));
+ res.send(contacts.map((u) => pick(u, fields)));
},
async del({ params: { username }, headers: { authorization } }, res) {
@@ -492,5 +494,15 @@ export default {
} catch (e) {
bail(res, e.message);
}
- }
+ },
+
+ async acl({ body: { username, topic } }, res) {
+ if (username === topic) res.send({ ok: true });
+ else bail(res, "unauthorized");
+ },
+
+ async superuser({ body: { username } }, res) {
+ if (username === config.mqtt.username) res.send({ ok: true });
+ else bail(res, "unauthorized");
+ },
};