aboutsummaryrefslogtreecommitdiffstats
path: root/routes
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2023-04-06 15:25:07 -0700
committerAdam Soltys <[email protected]>2023-04-06 15:25:07 -0700
commit99b72e143866d5cc62ba04847885070dc9a5c645 (patch)
treeabda08ae881b6e9bfff2ebbcf58d1409d7395fcf /routes
parent5083648dc113547c1c604e0c93ed0ee961f01ea3 (diff)
downloadcoinos-server-99b72e143866d5cc62ba04847885070dc9a5c645.tar.gz
coinos-server-99b72e143866d5cc62ba04847885070dc9a5c645.zip
prettier
Diffstat (limited to 'routes')
-rw-r--r--routes/email.js20
-rw-r--r--routes/info.js4
-rw-r--r--routes/invoices.js6
-rw-r--r--routes/lnurl.js14
-rw-r--r--routes/locations.js2
-rw-r--r--routes/nostr.js41
-rw-r--r--routes/payments.js45
-rw-r--r--routes/rates.js2
-rw-r--r--routes/requests.js16
-rw-r--r--routes/users.js28
10 files changed, 91 insertions, 87 deletions
diff --git a/routes/email.js b/routes/email.js
index ba590d4c..c043f0c8 100644
--- a/routes/email.js
+++ b/routes/email.js
@@ -13,8 +13,8 @@ export default {
.post("https://www.google.com/recaptcha/api/siteverify", {
form: {
secret,
- response,
- },
+ response
+ }
})
.json();
@@ -26,25 +26,25 @@ export default {
new SendEmailCommand({
Destination: {
CcAddresses: [],
- ToAddresses: ["[email protected]"],
+ ToAddresses: ["[email protected]"]
},
Message: {
Body: {
Html: {
Charset: "UTF-8",
- Data: JSON.stringify(body),
+ Data: JSON.stringify(body)
},
Text: {
Charset: "UTF-8",
- Data: JSON.stringify(body),
- },
+ Data: JSON.stringify(body)
+ }
},
Subject: {
Charset: "UTF-8",
- Data: body.subject || "Support Request",
- },
+ Data: body.subject || "Support Request"
+ }
},
- Source: "[email protected]",
+ Source: "[email protected]"
})
);
@@ -52,5 +52,5 @@ export default {
} else {
bail(res, "failed captcha");
}
- },
+ }
};
diff --git a/routes/info.js b/routes/info.js
index 13b1de57..ae347b56 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 5d36edf0..8e23e5f1 100644
--- a/routes/invoices.js
+++ b/routes/invoices.js
@@ -41,11 +41,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 1f45627b..bcb3f234 100644
--- a/routes/lnurl.js
+++ b/routes/lnurl.js
@@ -46,7 +46,7 @@ export default {
let { id: uid } = await getUser(username);
if (!uid) {
let u = await got(`${classic}/admin/migrate/${username}?zero=true`, {
- headers: { authorization: `Bearer ${admin}` },
+ headers: { authorization: `Bearer ${admin}` }
}).json();
if (!u) fail("user not found");
@@ -66,7 +66,7 @@ export default {
let metadata = JSON.stringify([
["text/plain", `Paying ${username}@${host}`],
- ["text/identifier", `${username}@${host}`],
+ ["text/identifier", `${username}@${host}`]
]);
let id = v4();
@@ -77,7 +77,7 @@ export default {
maxSendable: 100000000000,
metadata,
callback: `${URL}/api/lnurl/${id}`,
- tag: "payRequest",
+ tag: "payRequest"
});
} catch (e) {
warn("problem generating lnurlp request", e.message);
@@ -95,21 +95,21 @@ export default {
let metadata = JSON.stringify([
["text/plain", `Paying ${username}@${host}`],
- ["text/identifier", `${username}@${host}`],
+ ["text/identifier", `${username}@${host}`]
]);
({ text: pr } = await generate({
invoice: {
amount: Math.round(amount / 1000),
- type: types.lightning,
+ type: types.lightning
},
memo: metadata,
- user,
+ user
}));
await s(`lnurlp:${id}`, pr);
}
res.send({ pr, routes: [] });
- },
+ }
};
diff --git a/routes/locations.js b/routes/locations.js
index 04a94175..fb4487f7 100644
--- a/routes/locations.js
+++ b/routes/locations.js
@@ -3,5 +3,5 @@ import { g } from "$lib/db";
export default {
async list(req, res) {
res.send({ locations: await g("locations") });
- },
+ }
};
diff --git a/routes/nostr.js b/routes/nostr.js
index e45c0cbd..33233a7a 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 };
@@ -45,16 +45,16 @@ export default {
let ids = await db.sMembers(pubkey);
let events = ids.length
- ? (await db.mGet(ids.map((k) => "ev:" + k))).map(JSON.parse)
+ ? (await db.mGet(ids.map(k => "ev:" + k))).map(JSON.parse)
: [];
- res.send(events.map((e) => ({ ...e, user })));
+ res.send(events.map(e => ({ ...e, user })));
},
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);
@@ -71,7 +71,7 @@ export default {
let messages = await db.sMembers(`${pubkey}:messages`);
messages = await Promise.all(
- messages.map(async (id) => {
+ messages.map(async id => {
let m = await g(`ev:${id}`);
let aid = await g(`user:${m.pubkey}`);
@@ -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,13 +124,13 @@ export default {
user = {
username: pubkey.substr(0, 6),
pubkey,
- anon: true,
+ anon: true
};
follows.push(user);
}
- follows = uniq(follows, (e) => e.pubkey);
+ follows = uniq(follows, e => e.pubkey);
follows.sort((a, b) => a.username.localeCompare(b.username));
res.send(follows);
@@ -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 = [];
@@ -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,13 +168,13 @@ export default {
user = {
username: pubkey.substr(0, 6),
pubkey,
- anon: true,
+ anon: true
};
followers.push(user);
}
- followers = uniq(followers, (e) => e.pubkey);
+ followers = uniq(followers, e => e.pubkey);
followers.sort((a, b) => a.username.localeCompare(b.username));
res.send(followers);
@@ -187,10 +187,11 @@ export default {
async identities(req, res) {
res.send({
names: {
- adam: "566c166f3adab0c8fba5da015b0b3bcc8eb3696b455f2a1d43bfbd97059646a8",
- asoltys:
+ adam:
"566c166f3adab0c8fba5da015b0b3bcc8eb3696b455f2a1d43bfbd97059646a8",
- },
+ asoltys:
+ "566c166f3adab0c8fba5da015b0b3bcc8eb3696b455f2a1d43bfbd97059646a8"
+ }
});
- },
+ }
};
diff --git a/routes/payments.js b/routes/payments.js
index 5985f2ed..571d84f4 100644
--- a/routes/payments.js
+++ b/routes/payments.js
@@ -15,12 +15,12 @@ import ln from "$lib/ln";
let seen = [];
let catchUp = async () => {
let txns = await bc.listTransactions("*", 50);
- txns = txns.filter((tx) => tx.category === "receive" && tx.confirmations > 0);
+ txns = txns.filter(tx => tx.category === "receive" && tx.confirmations > 0);
for (let { txid } of txns) {
try {
if (seen.includes(txid)) continue;
await got.post(`http://localhost:${process.env.PORT || 3119}/bitcoin`, {
- json: { txid, wallet: config.bitcoin.wallet },
+ json: { txid, wallet: config.bitcoin.wallet }
});
seen.push(txid);
@@ -54,7 +54,7 @@ export default {
await got
.post(`${config.classic}/admin/credit`, {
json: { username, amount, source },
- headers: { authorization: `Bearer ${config.admin}` },
+ headers: { authorization: `Bearer ${config.admin}` }
})
.json();
} else if (payreq) {
@@ -74,7 +74,7 @@ export default {
r = await ln.pay({
bolt11: payreq.replace(/\s/g, "").toLowerCase(),
amount_msat: msatoshi ? undefined : `${amount}sats`,
- maxfee,
+ maxfee
});
if (r.status !== "complete") fail("payment did not complete");
@@ -129,7 +129,7 @@ export default {
let payments = (await db.lRange(`${id}:payments`, 0, -1)) || [];
payments = (
await Promise.all(
- payments.map(async (id) => {
+ payments.map(async id => {
let p = await g(`payment:${id}`);
if (p.created < start || p.created > end) return;
if (p.type === types.internal) p.with = await g(`user:${p.ref}`);
@@ -137,7 +137,7 @@ export default {
})
)
)
- .filter((p) => p)
+ .filter(p => p)
.sort((a, b) => b.created - a.created);
let total = payments.length;
@@ -165,7 +165,7 @@ export default {
let twoWeeksAgo = new Date(new Date().setDate(new Date().getDate() - 14));
let decoded = await ln.decodepay(payreq);
let { msatoshi, payee } = decoded;
- let node = nodes.find((n) => n.nodeid === payee);
+ let node = nodes.find(n => n.nodeid === payee);
let alias = node ? node.alias : payee.substr(0, 12);
res.send({ alias, amount: Math.round(msatoshi / 1000) });
@@ -178,13 +178,13 @@ export default {
let amount = await g(`pot:${name}`);
if (!amount) return bail(res, "pot not found");
let payments = (await db.lRange(`pot:${name}:payments`, 0, -1)) || [];
- payments = await Promise.all(payments.map((hash) => g(`payment:${hash}`)));
+ 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);
+ payments = payments.filter(p => p);
res.send({ amount, payments });
},
@@ -192,13 +192,16 @@ export default {
amount = parseInt(amount);
await t(`pot:${name}`, async (balance, db) => {
if (balance < amount) fail("Insufficient funds");
- await db.multi().decrBy(`pot:${name}`, amount).exec();
+ await db
+ .multi()
+ .decrBy(`pot:${name}`, amount)
+ .exec();
});
let hash = v4();
await s(`invoice:${hash}`, {
uid: user.id,
- received: 0,
+ received: 0
});
let payment = await credit(hash, amount, "", name, types.pot);
@@ -258,7 +261,7 @@ export default {
let tx = await bc.fundRawTransaction(raw, {
feeRate,
subtractFeeFromOutputs,
- replaceable,
+ replaceable
});
let fee = sats(tx.fee);
@@ -301,7 +304,7 @@ export default {
for (let {
scriptPubKey: { address },
- value,
+ value
} of tx.vout) {
total += sats(value);
if (
@@ -336,13 +339,13 @@ export default {
"card[number]": number,
"card[exp_month]": month,
"card[exp_year]": year,
- "card[cvc]": cvc,
+ "card[cvc]": cvc
};
let { id: source } = await got
.post(`${stripe}/tokens`, {
form,
- username,
+ username
})
.json();
@@ -351,13 +354,13 @@ export default {
amount,
currency,
source,
- description: "starter coupon",
+ description: "starter coupon"
};
let r = await got
.post(`${stripe}/charges`, {
form,
- username,
+ username
})
.json();
@@ -367,7 +370,7 @@ export default {
let memo = "stripe";
await s(`invoice:${hash}`, {
uid: user.id,
- received: 0,
+ received: 0
});
amount = sats(amount / store.rates[currency]);
let uid = await g("user:coinos");
@@ -387,7 +390,7 @@ export default {
"estimatesmartfee",
"echo",
"getblockchaininfo",
- "getnetworkinfo",
+ "getnetworkinfo"
];
if (!whitelist.includes(method)) fail("unsupported method");
@@ -431,5 +434,5 @@ export default {
} catch (e) {
bail(res, e.message);
}
- },
+ }
};
diff --git a/routes/rates.js b/routes/rates.js
index 08b604bb..c36c7ae8 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 02560733..11bf9a36 100644
--- a/routes/requests.js
+++ b/routes/requests.js
@@ -19,21 +19,21 @@ export default {
let requests = await db.lRange(`${id}:requests`, 0, -1);
- requests = await Promise.all(requests.map((id) => g(`request:${id}`)));
+ requests = await Promise.all(requests.map(id => g(`request:${id}`)));
requests = await Promise.all(
- requests.map(async (r) => {
+ requests.map(async r => {
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);
+ let sent = requests.filter(r => r.requester_id === id);
let received = requests
- .filter((r) => r.recipient_id === id)
- .filter((r) => !r.invoice_id);
+ .filter(r => r.recipient_id === id)
+ .filter(r => !r.invoice_id);
let invoices = [];
for (let r of sent) {
@@ -56,7 +56,7 @@ export default {
async create(
{
body: { recipient, ...params },
- user: { id: requester_id, username, profile },
+ user: { id: requester_id, username, profile }
},
res
) {
@@ -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/users.js b/routes/users.js
index 1e4d00cc..9130b249 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";
@@ -92,7 +92,7 @@ export default {
username: key,
display: key.substr(0, 6),
pubkey: key,
- anon: true,
+ anon: true
};
}
@@ -109,7 +109,7 @@ export default {
"pubkey",
"display",
"prompt",
- "id",
+ "id"
];
if (user.pubkey)
@@ -133,7 +133,7 @@ export default {
pubkey,
password,
username,
- salt,
+ salt
};
user = await register(user, ip, false);
@@ -210,7 +210,7 @@ export default {
"salt",
"seed",
"tokens",
- "twofa",
+ "twofa"
];
for (let a of attributes) {
@@ -254,7 +254,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;
@@ -266,7 +266,7 @@ export default {
...pick(user, fields),
id: uid,
about: user.address,
- migrated: true,
+ migrated: true
};
await s(`user:${username}`, uid);
@@ -274,7 +274,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) {
@@ -284,7 +284,7 @@ export default {
"confirmed",
"rate",
"currency",
- "preimage",
+ "preimage"
]);
n.id = v4();
n.created = parseISO(p.createdAt).getTime();
@@ -302,7 +302,7 @@ export default {
u = await got(
`${classic}/admin/migrate/${p.with.username.toLowerCase()}`,
{
- headers: { authorization: `Bearer ${config.admin}` },
+ headers: { authorization: `Bearer ${config.admin}` }
}
).json();
@@ -374,7 +374,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);
@@ -411,8 +411,8 @@ export default {
let contacts = (await g(`${id}:contacts`)) || [];
for (let { ref } of (
- await Promise.all(payments.map(async (id) => await g(`payment:${id}`)))
- ).filter((p) => p.type === types.internal && p.ref)) {
+ await Promise.all(payments.map(async id => await g(`payment:${id}`)))
+ ).filter(p => p.type === types.internal && p.ref)) {
!~contacts.findIndex(({ id }) => id === ref) &&
contacts.push(await g(`user:${ref}`));
}
@@ -476,5 +476,5 @@ export default {
} catch (e) {
bail(res, e.message);
}
- },
+ }
};