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 /lib | |
| parent | 337ca8c555f188d64c9f065972d443377adf042f (diff) | |
| download | coinos-server-b67ca07bac3a0cb78f9b3c19a783c3253f06c29f.tar.gz coinos-server-b67ca07bac3a0cb78f9b3c19a783c3253f06c29f.zip | |
biome
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/app.js | 10 | ||||
| -rw-r--r-- | lib/auth.js | 14 | ||||
| -rw-r--r-- | lib/countries.js | 2 | ||||
| -rw-r--r-- | lib/db.js | 6 | ||||
| -rw-r--r-- | lib/invoices.js | 6 | ||||
| -rw-r--r-- | lib/lightning.js | 2 | ||||
| -rw-r--r-- | lib/locations.js | 4 | ||||
| -rw-r--r-- | lib/mail.js | 12 | ||||
| -rw-r--r-- | lib/nostr.js | 16 | ||||
| -rw-r--r-- | lib/notifications.js | 2 | ||||
| -rw-r--r-- | lib/payments.js | 10 | ||||
| -rw-r--r-- | lib/rates.js | 6 | ||||
| -rw-r--r-- | lib/register.js | 4 | ||||
| -rw-r--r-- | lib/rpc.js | 12 | ||||
| -rw-r--r-- | lib/sockets.js | 2 | ||||
| -rw-r--r-- | lib/store.js | 2 | ||||
| -rw-r--r-- | lib/upload.js | 2 | ||||
| -rw-r--r-- | lib/utils.js | 2 | ||||
| -rw-r--r-- | lib/webhooks.js | 4 | ||||
| -rw-r--r-- | lib/whitelist.js | 2 |
20 files changed, 60 insertions, 60 deletions
@@ -16,11 +16,11 @@ import { socketServer } from "$lib/sockets"; const app = fastify({ logger: pino(), disableRequestLogging: true, - maxParamLength: 500 + maxParamLength: 500, }); app.register(fastifySecureSession, { - key: Buffer.from(config.jwt, "hex") + key: Buffer.from(config.jwt, "hex"), }); app.register(fastifyPassport.initialize()); @@ -32,18 +32,18 @@ app.register(fastifyMultipart); app.register(fastifyStatic, { root: path.join("/app/data/uploads"), - prefix: "/public/" + prefix: "/public/", }); app.register(fastifyWs, { errorHandler: (err, conn, req, reply) => { console.log("socket error", err); conn.destroy(err); - } + }, }); await app.register(cors, { - origin: true + origin: true, }); app.register(socketServer); diff --git a/lib/auth.js b/lib/auth.js index 0e96218a..575d826e 100644 --- a/lib/auth.js +++ b/lib/auth.js @@ -9,15 +9,15 @@ export const optional = { { session: false }, function (req, res, err, user, info) { req.user = user; - } - ) + }, + ), }; export const auth = { preValidation: fastifyPassport.authenticate("jwt", { authInfo: false, - session: false - }) + session: false, + }), }; export const requirePin = async ({ body, user }) => { @@ -29,9 +29,9 @@ export const jwtStrategy = new jwt.Strategy( { jwtFromRequest: jwt.ExtractJwt.fromExtractors([ jwt.ExtractJwt.fromAuthHeaderAsBearerToken(), - (req) => (req.cookies ? req.cookies.token : null) + (req) => (req.cookies ? req.cookies.token : null), ]), - secretOrKey: config.jwt + secretOrKey: config.jwt, }, async (payload, next) => { let user; @@ -41,5 +41,5 @@ export const jwtStrategy = new jwt.Strategy( } next(null, user); - } + }, ); diff --git a/lib/countries.js b/lib/countries.js index cfebc573..0d201c06 100644 --- a/lib/countries.js +++ b/lib/countries.js @@ -244,5 +244,5 @@ export default { VN: "VNM", YE: "YEM", ZM: "ZMB", - ZW: "ZWE" + ZW: "ZWE", }; @@ -30,15 +30,15 @@ return {ok = 'ok'} let debit = defineScript({ NUMBER_OF_KEYS: 2, SCRIPT, - transformArguments: (...args) => args.map((a) => a.toString()) + transformArguments: (...args) => args.map((a) => a.toString()), }); export let db = createClient({ url: config.db, scripts: { debit }, socket: { - reconnectStrategy: (retries) => Math.min(retries * 50, 5000) - } + reconnectStrategy: (retries) => Math.min(retries * 50, 5000), + }, }); async function connectWithRetry() { diff --git a/lib/invoices.js b/lib/invoices.js index 1a1adda2..0cf2d72b 100644 --- a/lib/invoices.js +++ b/lib/invoices.js @@ -21,7 +21,7 @@ export let generate = async ({ invoice, user, sender, memo }) => { prompt, type, webhook, - secret + secret, } = invoice; amount = parseInt(amount || 0); @@ -45,7 +45,7 @@ export let generate = async ({ invoice, user, sender, memo }) => { label: id, description: memo || "", expiry: expiry || 60 * 60 * 24 * 30, - deschashonly: true + deschashonly: true, }); hash = r.bolt11; @@ -76,7 +76,7 @@ export let generate = async ({ invoice, user, sender, memo }) => { tip, type, uid: user.id, - webhook + webhook, }; l(type, "invoice", user.username, amount); diff --git a/lib/lightning.js b/lib/lightning.js index d4664458..8bde9633 100644 --- a/lib/lightning.js +++ b/lib/lightning.js @@ -16,7 +16,7 @@ export async function listenForLightning() { pay_index, status, amount_received_msat, - payment_preimage: preimage + payment_preimage: preimage, } = inv; await s("pay_index", pay_index); diff --git a/lib/locations.js b/lib/locations.js index dc2c9d54..72bc20b5 100644 --- a/lib/locations.js +++ b/lib/locations.js @@ -7,14 +7,14 @@ import { fields, pick } from "$lib/utils"; export let getLocations = async () => { try { let locations = await got( - "https://api.btcmap.org/v2/elements?updated_since=2022-09-19T00:00:00Z" + "https://api.btcmap.org/v2/elements?updated_since=2022-09-19T00:00:00Z", ).json(); locations = locations.filter( (l) => l["osm_json"].tags && l["osm_json"].tags["payment:coinos"] === "yes" && - l["osm_json"]["type"] === "node" + l["osm_json"]["type"] === "node", ); for await (let l of locations) { diff --git a/lib/mail.js b/lib/mail.js index bda50bec..586de5c7 100644 --- a/lib/mail.js +++ b/lib/mail.js @@ -11,7 +11,7 @@ let Charset = "UTF-8"; export let templates = { verifyEmail: "templates/payments/verify.html", paymentReceived: "templates/payments/received.html", - passwordReset: "templates/payments/reset.html" + passwordReset: "templates/payments/reset.html", }; export let mail = async (user, subject, template, params) => { @@ -27,16 +27,16 @@ export let mail = async (user, subject, template, params) => { await client.send( new SendEmailCommand({ Destination: { - ToAddresses: [user.email] + ToAddresses: [user.email], }, Message: { Body: { - Html: { Charset, Data: html } + Html: { Charset, Data: html }, }, - Subject: { Charset, Data: subject } + Subject: { Charset, Data: subject }, }, - Source: config.support - }) + Source: config.support, + }), ); } catch (e) { console.log(e); diff --git a/lib/nostr.js b/lib/nostr.js index 4dd14a0e..64009168 100644 --- a/lib/nostr.js +++ b/lib/nostr.js @@ -64,7 +64,7 @@ export let fillPool = () => { user = { ...user, ...content, - updated: ev.created_at + updated: ev.created_at, }; await s(`user:${pubkey}`, JSON.stringify(user)); @@ -103,7 +103,7 @@ let timeouts = {}; export let q = async ( sub, query, - { timeout = 20000, since = 3600, eager = 200 } + { timeout = 20000, since = 3600, eager = 200 }, ) => new Promise(async (r, j) => { let start = Date.now(); @@ -149,7 +149,7 @@ export let q = async ( rejected = true; }, timeout); }, - timer: undefined + timer: undefined, }; timeouts[sub].extend(); @@ -176,7 +176,7 @@ let getUser = async (pubkey) => { user || { username: pubkey.substr(0, 6), pubkey, - anon: true + anon: true, } ); }; @@ -219,7 +219,7 @@ export async function handleZap(invoice) { } let ptags = zapreq.tags.filter( - (t) => t && t.length && t.length >= 2 && t[0] === "p" + (t) => t && t.length && t.length >= 2 && t[0] === "p", ); if (ptags.length !== 1) { @@ -227,7 +227,7 @@ export async function handleZap(invoice) { } let etags = zapreq.tags.filter( - (t) => t && t.length && t.length >= 2 && t[0] === "e" + (t) => t && t.length && t.length >= 2 && t[0] === "e", ); if (!(etags.length === 0 || etags.length === 1)) { @@ -235,7 +235,7 @@ export async function handleZap(invoice) { } let relays_tag = zapreq.tags.find( - (t) => t && t.length && t.length >= 2 && t[0] === "relays" + (t) => t && t.length && t.length >= 2 && t[0] === "relays", ); if (!relays_tag) { @@ -263,5 +263,5 @@ export async function handleZap(invoice) { l("sending receipt"); - await Promise.allSettled(relays.map(r => send(ev, r))); + await Promise.allSettled(relays.map((r) => send(ev, r))); } diff --git a/lib/notifications.js b/lib/notifications.js index 8f092c5c..af47a6d7 100644 --- a/lib/notifications.js +++ b/lib/notifications.js @@ -5,7 +5,7 @@ if (config.vapid) { webpush.setVapidDetails( config.vapid.url, config.vapid.publicKey, - config.vapid.privateKey + config.vapid.privateKey, ); } diff --git a/lib/payments.js b/lib/payments.js index 82a26824..20429864 100644 --- a/lib/payments.js +++ b/lib/payments.js @@ -32,7 +32,7 @@ export let debit = async ( memo, user, type = types.internal, - id = v4() + id = v4(), ) => { let ref; let { id: uid, currency, username } = user; @@ -70,7 +70,7 @@ export let debit = async ( amount || 0, tip || 0, fee || 0, - ourfee || 0 + ourfee || 0, ); if (r !== "ok") fail("Insufficient funds"); @@ -187,7 +187,7 @@ export let credit = async (hash, amount, memo, ref, type = types.internal) => { sats: "⚡️" + new Intl.NumberFormat("en-US", { maximumFractionDigits: 0 }).format( - p.amount + p.amount, ), link: `${process.env.URL}/payment/${p.id}`, }); @@ -195,12 +195,12 @@ export let credit = async (hash, amount, memo, ref, type = types.internal) => { 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}`, ); return p; diff --git a/lib/rates.js b/lib/rates.js index d1cbb92b..1172d202 100644 --- a/lib/rates.js +++ b/lib/rates.js @@ -49,12 +49,12 @@ export let getRates = async () => { date = Date.now(); try { let r = await got( - `http://data.fixer.io/api/latest?access_key=${config.fixer}` + `http://data.fixer.io/api/latest?access_key=${config.fixer}`, ).json(); let { rates: fx } = r; - let USD = fx['USD']; + let USD = fx["USD"]; - Object.keys(fx).map(k => { + Object.keys(fx).map((k) => { fx[k] = fx[k] / USD; }); diff --git a/lib/register.js b/lib/register.js index 2459d3a8..487413a8 100644 --- a/lib/register.js +++ b/lib/register.js @@ -28,9 +28,9 @@ export default async (user, ip, requireChallenge) => { if (config.ipregistry) { try { let { - location: { country: { code } } + location: { country: { code } }, } = await got( - `https://api.ipregistry.co/${ip}?key=${config.ipregistry}&fields=location.country.code` + `https://api.ipregistry.co/${ip}?key=${config.ipregistry}&fields=location.country.code`, ).json(); user.currency = countries[code]; @@ -13,16 +13,16 @@ export default ({ host, port, wallet, username, password }) => .post(url, { json: { method, - params + params, }, headers: { authorization: `Basic ${Buffer.from( - `${username}:${password}` - ).toString("base64")}` - } + `${username}:${password}`, + ).toString("base64")}`, + }, }) .json() .then(({ result }) => result); - })(prop.toLowerCase(), ...params) - } + })(prop.toLowerCase(), ...params), + }, ); diff --git a/lib/sockets.js b/lib/sockets.js index 948c419d..c1a704c9 100644 --- a/lib/sockets.js +++ b/lib/sockets.js @@ -107,7 +107,7 @@ export async function socketServer(app) { ws.send(JSON.stringify({ type: "logout" })); setTimeout( () => ws && ws.close(code, `closing due to error ${e.message}`), - 1000 + 1000, ); } break; diff --git a/lib/store.js b/lib/store.js index bf71219e..4c86761c 100644 --- a/lib/store.js +++ b/lib/store.js @@ -18,5 +18,5 @@ export default { last: {}, payments: [], fetching: {}, - timeouts: {} + timeouts: {}, }; diff --git a/lib/upload.js b/lib/upload.js index 39c4a07f..9bc41388 100644 --- a/lib/upload.js +++ b/lib/upload.js @@ -28,7 +28,7 @@ async function getSha256Hash(stream) { export default async (req, res) => { let { - params: { type } + params: { type }, } = req; let width = type === "banner" ? 1920 : 240; diff --git a/lib/utils.js b/lib/utils.js index a1612483..1e12214b 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -53,7 +53,7 @@ export const fields = [ "haspin", "profile", "prompt", - "banner" + "banner", ]; export const getUser = async (username) => { diff --git a/lib/webhooks.js b/lib/webhooks.js index e5403b51..5d9113d0 100644 --- a/lib/webhooks.js +++ b/lib/webhooks.js @@ -21,8 +21,8 @@ export const callWebhook = async (invoice, payment) => { memo, received, text, - secret - } + secret, + }, }); return res; } diff --git a/lib/whitelist.js b/lib/whitelist.js index a1a48223..4debb2ad 100644 --- a/lib/whitelist.js +++ b/lib/whitelist.js @@ -33,5 +33,5 @@ export default [ "username", "verified", "shopifyStore", - "shopifyToken" + "shopifyToken", ]; |
