aboutsummaryrefslogtreecommitdiffstats
path: root/routes
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2024-10-31 09:29:04 -0700
committerAdam Soltys <[email protected]>2024-10-31 09:34:42 -0700
commitaa4cd39c943b67169def224e224bd07b815b70ec (patch)
tree2af857ac971705f4d20eb017864f0365d0b57ea6 /routes
parentbc9c04f6519f32d3b444d4df0b276eba960480a9 (diff)
downloadcoinos-server-aa4cd39c943b67169def224e224bd07b815b70ec.tar.gz
coinos-server-aa4cd39c943b67169def224e224bd07b815b70ec.zip
biome lint
Diffstat (limited to 'routes')
-rw-r--r--routes/email.ts14
-rw-r--r--routes/info.ts4
-rw-r--r--routes/invoices.ts2
-rw-r--r--routes/items.ts22
-rw-r--r--routes/lnurl.ts48
-rw-r--r--routes/locations.ts2
-rw-r--r--routes/nostr.ts70
-rw-r--r--routes/payments.ts2
-rw-r--r--routes/rates.ts2
-rw-r--r--routes/shopify.ts10
-rw-r--r--routes/users.ts20
11 files changed, 99 insertions, 97 deletions
diff --git a/routes/email.ts b/routes/email.ts
index 63c88ab0..9f0a8228 100644
--- a/routes/email.ts
+++ b/routes/email.ts
@@ -8,12 +8,12 @@ import { SendEmailCommand } from "@aws-sdk/client-ses";
export default {
async send({ body }, res) {
try {
- let { email, message, username, token: response } = body;
+ const { email, message, username, token: response } = body;
- let Charset = "UTF-8";
+ const Charset = "UTF-8";
- let { recaptcha: secret } = config;
- let { success } = await got
+ const { recaptcha: secret } = config;
+ const { success } = await got
.post("https://www.google.com/recaptcha/api/siteverify", {
form: {
secret,
@@ -23,10 +23,10 @@ export default {
.json();
if (success || response === config.adminpass) {
- delete body.token;
+ body.token = undefined;
warn("support request from", email);
- let client = new SESClient({ region: "us-east-2" });
+ const client = new SESClient({ region: "us-east-2" });
await client.send(
new SendEmailCommand({
Destination: {
@@ -42,7 +42,7 @@ export default {
Charset,
Data:
body.subject ||
- "Support Request" + (username ? " From " + username : ""),
+ `Support Request${username ? ` From ${username}` : ""}`,
},
},
ReplyToAddresses: [email],
diff --git a/routes/info.ts b/routes/info.ts
index f2e262f6..09361a01 100644
--- a/routes/info.ts
+++ b/routes/info.ts
@@ -9,11 +9,11 @@ export default {
let total = 0;
- for await (let k of db.scanIterator({ MATCH: "balance:*" })) {
+ for await (const k of db.scanIterator({ MATCH: "balance:*" })) {
total += parseInt(await db.get(k));
}
- for await (let k of archive.scanIterator({ MATCH: "balance:*" })) {
+ for await (const k of archive.scanIterator({ MATCH: "balance:*" })) {
total += parseInt(await archive.get(k));
}
diff --git a/routes/invoices.ts b/routes/invoices.ts
index c571f4de..4f0f6feb 100644
--- a/routes/invoices.ts
+++ b/routes/invoices.ts
@@ -12,7 +12,7 @@ export default {
if (typeof invoice === "string") invoice = await g(`invoice:${invoice}`);
if (invoice) {
- delete invoice.secret;
+ invoice.secret = undefined;
invoice.user = pick(await g(`user:${invoice.uid}`), [
"id",
"profile",
diff --git a/routes/items.ts b/routes/items.ts
index a7586a69..df1d86ea 100644
--- a/routes/items.ts
+++ b/routes/items.ts
@@ -4,12 +4,12 @@ import { bail, fail } from "$lib/utils";
export default {
async list(req, res) {
- let {
+ const {
params: { id: uid },
} = req;
- let items = [];
- for (let id of await db.lRange(`${uid}:items`, 0, -1)) {
- let item = await g(`item:${id}`);
+ const items = [];
+ for (const id of await db.lRange(`${uid}:items`, 0, -1)) {
+ const item = await g(`item:${id}`);
if (item) items.push(item);
else await db.lRem(`${uid}:items`, 0, id);
}
@@ -18,11 +18,11 @@ export default {
},
async get(req, res) {
- let {
+ const {
params: { id },
} = req;
try {
- let item = await g(`item:${id}`);
+ const item = await g(`item:${id}`);
if (!item) fail("Item not found");
res.send(item);
} catch (e) {
@@ -31,7 +31,7 @@ export default {
},
async create(req, res) {
- let {
+ const {
body: item,
user: { id },
} = req;
@@ -53,12 +53,12 @@ export default {
},
async del(req, res) {
- let {
+ const {
body: { item },
user: { id },
} = req;
try {
- let n = await db.lRem(`${id}:items`, 0, item.id);
+ const n = await db.lRem(`${id}:items`, 0, item.id);
if (n) db.del(`item:${item.id}`);
else fail("item not found");
@@ -69,14 +69,14 @@ export default {
},
async sort(req, res) {
- let {
+ const {
body: { items },
user: { id },
} = req;
try {
await db.del(`${id}:items`);
- for (let item of items) {
+ for (const item of items) {
await db.rPush(`${id}:items`, item.id);
}
diff --git a/routes/lnurl.ts b/routes/lnurl.ts
index fec516c1..a93e63e4 100644
--- a/routes/lnurl.ts
+++ b/routes/lnurl.ts
@@ -8,36 +8,36 @@ import { bech32 } from "bech32";
import { types } from "$lib/payments";
import { serverPubkey } from "$lib/nostr";
-let { URL } = process.env;
-let host = URL.split("/").at(-1);
+const { URL } = process.env;
+const host = URL.split("/").at(-1);
export default {
async encode(req, res) {
- let {
+ const {
query: { address },
} = req;
- let [name, domain] = address.split("@");
- let url = `https://${domain}/.well-known/lnurlp/${name}`;
+ const [name, domain] = address.split("@");
+ const url = `https://${domain}/.well-known/lnurlp/${name}`;
try {
- let r = await got(url).json();
+ const r = await got(url).json();
if (r.tag !== "payRequest") fail("not an ln address");
} catch (e) {
- let m = `failed to lookup lightning address ${address}`;
+ const m = `failed to lookup lightning address ${address}`;
warn(m);
return bail(res, m);
}
- let enc = bech32.encode("lnurl", bech32.toWords(Buffer.from(url)), 20000);
+ const enc = bech32.encode("lnurl", bech32.toWords(Buffer.from(url)), 20000);
res.send(enc);
},
async decode(req, res) {
- let {
+ const {
query: { text },
} = req;
try {
- let url = Buffer.from(
+ const url = Buffer.from(
bech32.fromWords(bech32.decode(text, 20000).words),
).toString();
@@ -48,19 +48,19 @@ export default {
},
async lnurlp(req, res) {
- let {
+ const {
params: { username },
query: { minSendable = 1000, maxSendable = 100000000000 },
} = req;
try {
- let { id: uid } = await getUser(username);
+ const { id: uid } = await getUser(username);
- let metadata = JSON.stringify([
+ const metadata = JSON.stringify([
["text/plain", `Paying ${username}@${host}`],
["text/identifier", `${username}@${host}`],
]);
- let id = v4();
+ const id = v4();
await s(`lnurl:${id}`, uid);
res.send({
@@ -80,18 +80,18 @@ export default {
},
async lnurl(req, res) {
- let {
+ const {
params: { id },
query: { amount, comment, nostr },
} = req;
try {
- let uid = await g(`lnurl:${id}`);
- let user = await getUser(uid);
+ const uid = await g(`lnurl:${id}`);
+ const user = await getUser(uid);
if (!user) fail("user not found");
let { username } = user;
username = username.replace(/\s/g, "").toLowerCase();
- let memo = `Paying ${username}@${host}`;
+ const memo = `Paying ${username}@${host}`;
let metadata = JSON.stringify([
["text/plain", memo],
["text/identifier", `${username}@${host}`],
@@ -99,7 +99,7 @@ export default {
if (nostr) {
try {
- let event = JSON.parse(decodeURIComponent(nostr));
+ const event = JSON.parse(decodeURIComponent(nostr));
// TODO: validate the event
await s(`zap:${id}`, event);
metadata = nostr;
@@ -108,7 +108,7 @@ export default {
}
}
- let { id: iid, text: pr } = await generate({
+ const { id: iid, text: pr } = await generate({
invoice: {
amount: Math.round(amount / 1000),
memo: metadata,
@@ -124,15 +124,15 @@ export default {
},
async verify(req, res) {
- let {
+ const {
params: { id },
} = req;
- let inv = await g(`invoice:${id}`);
+ const inv = await g(`invoice:${id}`);
if (!inv) return res.send({ status: "ERROR", reason: "Not found" });
- let { received, amount, preimage } = inv;
- let settled = received >= amount;
+ const { received, amount, preimage } = inv;
+ const settled = received >= amount;
res.send({ status: "OK", settled, preimage });
},
diff --git a/routes/locations.ts b/routes/locations.ts
index 5aaeb02b..d7a5b636 100644
--- a/routes/locations.ts
+++ b/routes/locations.ts
@@ -2,7 +2,7 @@ import { g } from "$lib/db";
export default {
async list(_, res) {
- let locations = await g("locations");
+ const locations = await g("locations");
res.send({ locations });
},
};
diff --git a/routes/nostr.ts b/routes/nostr.ts
index f6caa10d..1ad86baf 100644
--- a/routes/nostr.ts
+++ b/routes/nostr.ts
@@ -10,17 +10,17 @@ import {
pool,
} from "$lib/nostr";
-let opts = { maxWait: 2000 };
+const opts = { maxWait: 2000 };
export default {
async event(req, res) {
- let {
+ const {
params: { id },
} = req;
- let event = await g(`ev:${id}`);
+ const event = await g(`ev:${id}`);
if (!event) return bail(res, "event not found");
- let { pubkey } = event;
+ const { pubkey } = event;
event.user = (await g(`user:${pubkey}`)) || anon(pubkey);
@@ -29,13 +29,13 @@ export default {
async publish(req, res) {
try {
- let { event } = req.body;
- let { pubkey } = req.user;
- let { write: relays } = await getRelays(pubkey);
+ const { event } = req.body;
+ const { pubkey } = req.user;
+ const { write: relays } = await getRelays(pubkey);
if (!relays.includes(config.nostr)) relays.push(config.nostr);
let ok;
- for (let url of relays) {
+ for (const url of relays) {
try {
await send(event, url);
ok = true;
@@ -54,7 +54,7 @@ export default {
},
async follows(req, res) {
- let {
+ const {
params: { pubkey },
query: { pubkeysOnly, nocache },
} = req;
@@ -63,7 +63,7 @@ export default {
let follows = [];
let pubkeys = await g(`${pubkey}:pubkeys`);
- if (!pubkeys || !pubkeysOnly || nocache) {
+ if (!pubkeys || !pubkeysOnly || nocache) {
let filter = { kinds: [3], authors: [pubkey] };
let ev = await pool.get([config.nostr], filter, opts);
@@ -87,27 +87,27 @@ export default {
}
if (!pubkeys.length || pubkeysOnly) return res.send(pubkeys);
- let cache = await g(`${pubkey}:follows`);
+ const cache = await g(`${pubkey}:follows`);
if (cache && cache.t >= created_at) ({ follows } = cache);
else {
- let filter: any = { cache: ["user_infos", { pubkeys }] };
- let infos = await pool.querySync([config.cache], filter, opts);
- let profiles = infos.filter((e) => e.kind === 0);
+ const filter: any = { cache: ["user_infos", { pubkeys }] };
+ const infos = await pool.querySync([config.cache], filter, opts);
+ const profiles = infos.filter((e) => e.kind === 0);
- let f = infos.find((e) => e.kind === 10000133);
+ const f = infos.find((e) => e.kind === 10000133);
let counts = {};
if (f) counts = JSON.parse(f.content);
- for (let p of profiles) {
- let { content, pubkey } = p;
- let user = JSON.parse(content);
+ for (const p of profiles) {
+ const { content, pubkey } = p;
+ const user = JSON.parse(content);
user.count = counts[pubkey];
user.pubkey = pubkey;
follows.push(user);
}
- let followKeys = follows.map((f) => f.pubkey);
- let missing = pubkeys
+ const followKeys = follows.map((f) => f.pubkey);
+ const missing = pubkeys
.filter((p) => !followKeys.includes(p))
.map((pubkey) => anon(pubkey));
@@ -125,34 +125,34 @@ export default {
},
async followers(req, res) {
- let {
+ const {
params: { pubkey },
} = req;
try {
let filter: any = { kinds: [3], "#p": [pubkey] };
- let ev = await pool.get([config.nostr], filter, opts);
+ const ev = await pool.get([config.nostr], filter, opts);
let created_at;
if (ev) ({ created_at } = ev);
let followers = [];
- let cache = await g(`${pubkey}:followers`);
+ const cache = await g(`${pubkey}:followers`);
if (cache && cache.t >= created_at) ({ followers } = cache);
else {
filter = { cache: ["user_followers", { pubkey }] };
- let data = await pool.querySync([config.cache], filter, opts);
- for (let ev of data.filter((f) => f.kind === 0)) {
- let { content, pubkey } = ev;
- let user = JSON.parse(content);
+ const data = await pool.querySync([config.cache], filter, opts);
+ for (const ev of data.filter((f) => f.kind === 0)) {
+ const { content, pubkey } = ev;
+ const user = JSON.parse(content);
user.pubkey = pubkey;
followers.push(user);
}
- let pubkeys = followers.map((f) => f.pubkey);
+ const pubkeys = followers.map((f) => f.pubkey);
filter = { cache: ["user_infos", { pubkeys }] };
- let infos = await pool.querySync([config.cache], filter, opts);
+ const infos = await pool.querySync([config.cache], filter, opts);
let counts = {};
- let f = infos.find((e) => e.kind === 10000133);
+ const f = infos.find((e) => e.kind === 10000133);
if (f) counts = JSON.parse(f.content);
followers.map((f) => (f.count = counts[f.pubkey]));
followers.sort((a: any, b: any) => b.count - a.count);
@@ -169,7 +169,7 @@ export default {
async count(req, res) {
try {
- let { pubkey } = req.params;
+ const { pubkey } = req.params;
res.send(await getCount(pubkey));
} catch (e) {
console.log(e);
@@ -178,16 +178,16 @@ export default {
},
async identities(req, res) {
- let {
+ const {
query: { name },
} = req;
let names = {};
if (name) {
names = { [name]: (await getUser(name)).pubkey };
} else {
- let records = await db.sMembers("nip5");
- for (let s of records) {
- let [name, pubkey] = s.split(":");
+ const records = await db.sMembers("nip5");
+ for (const s of records) {
+ const [name, pubkey] = s.split(":");
names[name] = pubkey;
}
}
diff --git a/routes/payments.ts b/routes/payments.ts
index 618e9195..21720e17 100644
--- a/routes/payments.ts
+++ b/routes/payments.ts
@@ -368,7 +368,7 @@ export default {
);
let msg = e.message;
if (msg.includes("500")) msg = "";
- bail(res, "Failed to prepare transaction " + msg);
+ bail(res, `Failed to prepare transaction ${msg}`);
}
},
diff --git a/routes/rates.ts b/routes/rates.ts
index e904d438..67c111d7 100644
--- a/routes/rates.ts
+++ b/routes/rates.ts
@@ -3,7 +3,7 @@ import { rate } from "$lib/rates";
export default {
async fx(_, res) {
- let { fx } = await g("fx");
+ const { fx } = await g("fx");
res.send({ fx });
},
diff --git a/routes/shopify.ts b/routes/shopify.ts
index f5c26208..33592705 100644
--- a/routes/shopify.ts
+++ b/routes/shopify.ts
@@ -3,7 +3,7 @@ import { g } from "$lib/db";
import { err } from "$lib/logging";
import { getPayment } from "$lib/utils";
-let query = `mutation orderMarkAsPaid($input: OrderMarkAsPaidInput!) {
+const query = `mutation orderMarkAsPaid($input: OrderMarkAsPaidInput!) {
orderMarkAsPaid(input: $input) {
order { id }
userErrors {
@@ -14,15 +14,15 @@ let query = `mutation orderMarkAsPaid($input: OrderMarkAsPaidInput!) {
}`;
export default async (req, res) => {
- let {
+ const {
body: { hash },
params: { id },
} = req;
- let p = await getPayment(hash);
- let user = await g(`user:${p.uid}`);
+ const p = await getPayment(hash);
+ const user = await g(`user:${p.uid}`);
try {
- let r = await got
+ const r = await got
.post(
`https://${user.shopifyStore}.myshopify.com/admin/api/2023-07/graphql.json`,
{
diff --git a/routes/users.ts b/routes/users.ts
index 8bbef621..c1cce6e7 100644
--- a/routes/users.ts
+++ b/routes/users.ts
@@ -89,14 +89,14 @@ export default {
if (nostr) {
nostr.username = nostr.name || key.substr(0, 6);
nostr.display = nostr.display_name || nostr.displayName;
- delete nostr.display_name;
- delete nostr.displayName;
- delete nostr.name;
+ nostr.display_name = undefined;
+ nostr.displayName = undefined;
+ nostr.name = undefined;
}
if (user) {
user.anon = false;
- delete nostr.display;
+ nostr.display = undefined;
}
user = {
@@ -211,12 +211,13 @@ export default {
if (user.pin && !(pin === user.pin)) fail("Pin required");
if (typeof newpin !== "undefined" && newpin.length === 6)
user.pin = newpin;
- if (user.pin === "delete") delete user.pin;
+ if (user.pin === "delete") user.pin = undefined;
let exists;
if (username) exists = await getUser(username);
- let token, oldname;
+ let token;
+ let oldname;
if (user.username.toLowerCase() !== username.toLowerCase() && exists) {
err("username taken", username, user.username, exists.username);
fail("Username taken");
@@ -444,7 +445,7 @@ export default {
headers: { authorization },
} = req;
username = username.toLowerCase();
- if (!(authorization && authorization.includes(config.admin)))
+ if (!authorization?.includes(config.admin))
return res.code(401).send("unauthorized");
const { id, pubkey } = await g(
@@ -467,8 +468,9 @@ export default {
body: { code, username, password },
user: u,
} = req;
- const admin = u && u.admin;
- let id, user;
+ const admin = u?.admin;
+ let id;
+ let user;
if (admin) {
id = await g(`user:${username.toLowerCase().replace(/\s/g, "")}`);