diff options
| author | Adam Soltys <[email protected]> | 2023-12-19 14:37:18 -0800 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2023-12-20 14:39:08 -0800 |
| commit | b67ca07bac3a0cb78f9b3c19a783c3253f06c29f (patch) | |
| tree | 1664d33bd1c514d016a7a1983af257197d4e5ac7 /routes | |
| parent | 337ca8c555f188d64c9f065972d443377adf042f (diff) | |
| download | coinos-server-b67ca07bac3a0cb78f9b3c19a783c3253f06c29f.tar.gz coinos-server-b67ca07bac3a0cb78f9b3c19a783c3253f06c29f.zip | |
biome
Diffstat (limited to 'routes')
| -rw-r--r-- | routes/email.js | 18 | ||||
| -rw-r--r-- | routes/info.js | 4 | ||||
| -rw-r--r-- | routes/invoices.js | 8 | ||||
| -rw-r--r-- | routes/lnurl.js | 14 | ||||
| -rw-r--r-- | routes/locations.js | 2 | ||||
| -rw-r--r-- | routes/nostr.js | 28 | ||||
| -rw-r--r-- | routes/payments.js | 25 | ||||
| -rw-r--r-- | routes/rates.js | 2 | ||||
| -rw-r--r-- | routes/requests.js | 10 | ||||
| -rw-r--r-- | routes/shopify.js | 8 | ||||
| -rw-r--r-- | routes/users.js | 26 |
11 files changed, 73 insertions, 72 deletions
diff --git a/routes/email.js b/routes/email.js index ac2fd721..63c88ab0 100644 --- a/routes/email.js +++ b/routes/email.js @@ -17,8 +17,8 @@ export default { .post("https://www.google.com/recaptcha/api/siteverify", { form: { secret, - response - } + response, + }, }) .json(); @@ -31,23 +31,23 @@ export default { new SendEmailCommand({ Destination: { CcAddresses: [], - ToAddresses: [config.support] + ToAddresses: [config.support], }, Message: { Body: { Html: { Charset, Data: message.replace(/\n/g, "<br>") }, - Text: { Charset, Data: message } + Text: { Charset, Data: message }, }, Subject: { Charset, Data: body.subject || - "Support Request" + (username ? " From " + username : "") - } + "Support Request" + (username ? " From " + username : ""), + }, }, ReplyToAddresses: [email], - Source: config.support - }) + Source: config.support, + }), ); res.send({ ok: true }); @@ -57,5 +57,5 @@ export default { } catch (e) { console.log(e); } - } + }, }; diff --git a/routes/info.js b/routes/info.js index ae347b56..13b1de57 100644 --- a/routes/info.js +++ b/routes/info.js @@ -18,9 +18,9 @@ export default { const info = { lnchannel, lnwallet, - total + total, }; res.send(info); - } + }, }; diff --git a/routes/invoices.js b/routes/invoices.js index 329f163d..898938dd 100644 --- a/routes/invoices.js +++ b/routes/invoices.js @@ -19,7 +19,7 @@ export default { "banner", "currency", "username", - "pubkey" + "pubkey", ]); } else if (config.classic) { invoice = await got(`${config.classic}/invoice/${id}`).json(); @@ -49,11 +49,11 @@ export default { .post(`${config.classic}/invoice`, { json: { invoice: { amount: 0, network: "lightning" }, - user: { username } - } + user: { username }, + }, }) .json(); res.send(invoice); - } + }, }; diff --git a/routes/lnurl.js b/routes/lnurl.js index 011db286..a1e7dde8 100644 --- a/routes/lnurl.js +++ b/routes/lnurl.js @@ -36,7 +36,7 @@ export default { async decode({ query: { text } }, res) { try { let url = Buffer.from( - bech32.fromWords(bech32.decode(text, 20000).words) + bech32.fromWords(bech32.decode(text, 20000).words), ).toString(); res.send(await got(url).json()); @@ -51,7 +51,7 @@ export default { let metadata = JSON.stringify([ ["text/plain", `Paying ${username}@${host}`], - ["text/identifier", `${username}@${host}`] + ["text/identifier", `${username}@${host}`], ]); let id = v4(); @@ -64,7 +64,7 @@ export default { metadata, nostrPubkey, callback: `${URL}/api/lnurl/${id}`, - tag: "payRequest" + tag: "payRequest", }); } catch (e) { warn("problem generating lnurlp request", e.message); @@ -82,7 +82,7 @@ export default { let metadata = JSON.stringify([ ["text/plain", `Paying ${username}@${host}`], - ["text/identifier", `${username}@${host}`] + ["text/identifier", `${username}@${host}`], ]); if (nostr) { @@ -99,12 +99,12 @@ export default { let { text: pr } = await generate({ invoice: { amount: Math.round(amount / 1000), - type: types.lightning + type: types.lightning, }, memo: metadata, - user + user, }); res.send({ pr, routes: [] }); - } + }, }; diff --git a/routes/locations.js b/routes/locations.js index 0f71fde9..e9a6843c 100644 --- a/routes/locations.js +++ b/routes/locations.js @@ -4,5 +4,5 @@ export default { async list(req, res) { let locations = await g("locations"); res.send({ locations }); - } + }, }; diff --git a/routes/nostr.js b/routes/nostr.js index 5c22fa7b..990317a9 100644 --- a/routes/nostr.js +++ b/routes/nostr.js @@ -15,7 +15,7 @@ export default { pubkey, anon: true, follows: [], - followers: [] + followers: [], }; res.send(event); @@ -31,12 +31,12 @@ export default { pubkey, anon: true, follows: [], - followers: [] + followers: [], }; let params = { kinds: [1], - authors: [pubkey] + authors: [pubkey], }, opts = { since: 0 }; @@ -54,7 +54,7 @@ export default { async messages({ params: { pubkey, since = 0 } }, res) { let params = { kinds: [4], - authors: [pubkey] + authors: [pubkey], }; let opts = { since }; @@ -63,7 +63,7 @@ export default { params = { kinds: [4], - "#p": [pubkey] + "#p": [pubkey], }; await q(`${pubkey}:messages`, params, opts).catch(nada); @@ -81,7 +81,7 @@ export default { m.recipient = await g(`user:${rid}`); return m; - }) + }), ); res.send(messages); @@ -98,7 +98,7 @@ export default { params = { limit: 1, kinds: [3], - authors: [pubkey] + authors: [pubkey], }, opts = { timeout: 60000, eager: 60000 }; @@ -114,7 +114,7 @@ export default { q(`${pubkey}:profile:f1`, { limit: 1, kinds: [0], - authors: [pubkey] + authors: [pubkey], }).catch(nada); let uid = await g(`user:${pubkey}`); @@ -124,7 +124,7 @@ export default { user = { username: pubkey.substr(0, 6), pubkey, - anon: true + anon: true, }; follows.push(user); @@ -139,7 +139,7 @@ export default { async followers({ params: { pubkey } }, res) { try { let pubkeys = [ - ...new Set([...(await db.sMembers(`${pubkey}:followers`))]) + ...new Set([...(await db.sMembers(`${pubkey}:followers`))]), ]; let followers = []; @@ -147,7 +147,7 @@ export default { q( `${pubkey}:followers`, { kinds: [3], "#p": [pubkey] }, - { timeout: 60000, eager: 60000 } + { timeout: 60000, eager: 60000 }, ).catch(nada); for (let pubkey of pubkeys) { @@ -157,7 +157,7 @@ export default { await q(`${pubkey}:profile:f2`, { limit: 1, kinds: [0], - authors: [pubkey] + authors: [pubkey], }).catch(nada); uid = await g(`user:${pubkey}`); @@ -168,7 +168,7 @@ export default { user = { username: pubkey.substr(0, 6), pubkey, - anon: true + anon: true, }; followers.push(user); @@ -193,5 +193,5 @@ export default { } res.send({ names }); - } + }, }; diff --git a/routes/payments.js b/routes/payments.js index bbbcf9d2..2b332221 100644 --- a/routes/payments.js +++ b/routes/payments.js @@ -44,8 +44,9 @@ export default { if (typeof amount !== "undefined") { amount = parseInt(amount); - if (amount < 0 || amount > SATS || isNaN(amount)) fail("Invalid amount"); - } + if (amount < 0 || amount > SATS || isNaN(amount)) + fail("Invalid amount"); + } await requirePin({ body, user }); @@ -98,7 +99,7 @@ export default { if (p.created < start || p.created > end) return; if (p.type === types.internal) p.with = await g(`user:${p.ref}`); return p; - }) + }), ) ) .filter((p) => p) @@ -124,7 +125,7 @@ export default { ).toFixed(2), }, }), - {} + {}, ); if (limit) payments = payments.slice(offset, offset + limit); @@ -168,7 +169,7 @@ export default { payments = await Promise.all(payments.map((hash) => g(`payment:${hash}`))); await Promise.all( - payments.map(async (p) => (p.user = await g(`user:${p.uid}`))) + payments.map(async (p) => (p.user = await g(`user:${p.uid}`))), ); payments = payments.filter((p) => p); @@ -235,7 +236,7 @@ export default { sats(amount), "", `${txid}:${vout}`, - types.bitcoin + types.bitcoin, ); } else if (confirmations >= 1) { await confirm(address, txid, vout); @@ -250,7 +251,7 @@ export default { } }, - async fee({ body: { amount, address, feeRate, subtract }, user }, res) { + async fee({ body: { amount, address, feeRate, subtract }, user }, res) { try { let ourfee = Math.round(amount * config.fee); let credit = await g(`credit:bitcoin:${user.id}`); @@ -268,10 +269,10 @@ export default { let fee = sats(tx.fee); - if (amount + fee + ourfee > await g(`balance:${user.id}`)) { + if (amount + fee + ourfee > (await g(`balance:${user.id}`))) { tx = await bc.fundRawTransaction(raw, { replaceable: true, - subtractFeeFromOutputs: [0] + subtractFeeFromOutputs: [0], }); } @@ -485,12 +486,12 @@ export default { mqtt1.publish( username, - `pay:${p.amount}:${p.tip}:${p.rate}:${p.created}:${p.id}` + `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}` + `pay:${p.amount}:${p.tip}:${p.rate}:${p.created}:${p.id}`, ); res.send({ ok: true }); @@ -507,7 +508,7 @@ export default { let maxfee = 5000; let [username, domain] = lnaddress.split("@"); let { minSendable, maxSendable, callback, metadata } = await got( - `https://${domain}/.well-known/lnurlp/${username}` + `https://${domain}/.well-known/lnurlp/${username}`, ).json(); let memo = metadata["text/plain"] || ""; diff --git a/routes/rates.js b/routes/rates.js index c36c7ae8..08b604bb 100644 --- a/routes/rates.js +++ b/routes/rates.js @@ -7,5 +7,5 @@ export default { async index(req, res) { res.send(store.rates); - } + }, }; diff --git a/routes/requests.js b/routes/requests.js index ccc7d739..a0d55739 100644 --- a/routes/requests.js +++ b/routes/requests.js @@ -26,7 +26,7 @@ export default { r.requester = await g(`user:${r.requester_id}`); r.recipient = await g(`user:${r.recipient_id}`); return r; - }) + }), ); let sent = requests.filter((r) => r.requester_id === id); @@ -56,9 +56,9 @@ export default { async create( { body: { recipient, ...params }, - user: { id: requester_id, username, profile } + user: { id: requester_id, username, profile }, }, - res + res, ) { let recipient_id = await g(`user:${recipient}`); @@ -67,7 +67,7 @@ export default { id, recipient_id, requester_id, - ...params + ...params, }; await s(`request:${id}`, request); @@ -81,5 +81,5 @@ export default { async destroy({ body: { request_id }, user: { id } }, res) { await db.lrem(`user:${id}:requests`, request_id); res.send(); - } + }, }; diff --git a/routes/shopify.js b/routes/shopify.js index cdfbedba..bcb60ea3 100644 --- a/routes/shopify.js +++ b/routes/shopify.js @@ -24,13 +24,13 @@ export default async ({ body: { hash }, params: { id } }, res) => { { headers: { "Content-Type": "application/json", - "X-Shopify-Access-Token": user.shopifyToken + "X-Shopify-Access-Token": user.shopifyToken, }, json: { query, - variables: { input: { id: `gid://shopify/Order/${id}` } } - } - } + variables: { input: { id: `gid://shopify/Order/${id}` } }, + }, + }, ) .json(); diff --git a/routes/users.js b/routes/users.js index ebcbbc85..432908e9 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"; @@ -99,7 +99,7 @@ export default { username: key, display: key.substr(0, 6), pubkey: key, - anon: true + anon: true, }; } @@ -117,7 +117,7 @@ export default { "pubkey", "display", "prompt", - "id" + "id", ]; if (user.pubkey) @@ -142,7 +142,7 @@ export default { pubkey, password, username, - salt + salt, }; user = await register(user, ip, false); @@ -195,7 +195,7 @@ export default { newpin, username, shopifyToken, - shopifyStore + shopifyStore, } = body; if (user.pin && !(pin === user.pin)) throw new Error("Pin required"); @@ -239,7 +239,7 @@ export default { "tokens", "twofa", "shopifyToken", - "shopifyStore" + "shopifyStore", ]; for (let a of attributes) { @@ -254,7 +254,7 @@ export default { await s(`user:${user.pubkey}`, user.id); await s( `user:${user.username.toLowerCase().replace(/\s/g, "")}`, - user.id + user.id, ); await s(`user:${user.id}`, user); @@ -319,7 +319,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); @@ -364,7 +364,7 @@ export default { for (let { ref } of ( await Promise.all( - payments.reverse().map(async (id) => await g(`payment:${id}`)) + payments.reverse().map(async (id) => await g(`payment:${id}`)), ) ).filter((p) => p.type === types.internal && p.ref)) { let i = contacts.findIndex((c) => c && c.id === ref); @@ -385,7 +385,7 @@ export default { return res.code(401).send("unauthorized"); let { id, pubkey } = await g( - `user:${await g(`user:${username.replace(/\s/g, "").toLowerCase()}`)}` + `user:${await g(`user:${username.replace(/\s/g, "").toLowerCase()}`)}`, ); let invoices = await db.lRange(`${id}:invoices`, 0, -1); let payments = await db.lRange(`${id}:payments`, 0, -1); @@ -470,7 +470,7 @@ export default { await mail(user, subject, templates.verifyEmail, { username, - link + link, }); res.send({ ok: true }); @@ -507,7 +507,7 @@ export default { await mail(user, "Password reset", templates.passwordReset, { ...user, - link + link, }); } @@ -515,5 +515,5 @@ export default { } catch (e) { bail(res, e.message); } - } + }, }; |
