aboutsummaryrefslogtreecommitdiffstats
path: root/routes
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2023-01-17 11:53:24 -0800
committerAdam Soltys <[email protected]>2023-01-17 11:53:24 -0800
commite918a818acf789a6619cbf4432f0c4713d4c53e6 (patch)
tree0d30f8b6e519aaf31079f337e8808992f63f92ef /routes
parent46913d34e77f19c3dd7c105b1deec452348dd1db (diff)
downloadcoinos-server-e918a818acf789a6619cbf4432f0c4713d4c53e6.tar.gz
coinos-server-e918a818acf789a6619cbf4432f0c4713d4c53e6.zip
nostr cleanup
Diffstat (limited to 'routes')
-rw-r--r--routes/events.js1
-rw-r--r--routes/locations.js8
-rw-r--r--routes/nostr.js32
-rw-r--r--routes/send.js2
4 files changed, 20 insertions, 23 deletions
diff --git a/routes/events.js b/routes/events.js
index cea82118..21ee37d8 100644
--- a/routes/events.js
+++ b/routes/events.js
@@ -4,4 +4,3 @@ import redis from "$lib/db";
import { coinos, pool, q } from "$lib/nostr";
import store from "$lib/store";
import { nada, wait } from "$lib/utils";
-
diff --git a/routes/locations.js b/routes/locations.js
index e080a7b9..fb4487f7 100644
--- a/routes/locations.js
+++ b/routes/locations.js
@@ -1,7 +1,7 @@
import { g } from "$lib/db";
export default {
-async list(req, res) {
- res.send({ locations: await g('locations') });
-}
-}
+ async list(req, res) {
+ res.send({ locations: await g("locations") });
+ }
+};
diff --git a/routes/nostr.js b/routes/nostr.js
index 3d326e94..35b40c07 100644
--- a/routes/nostr.js
+++ b/routes/nostr.js
@@ -1,9 +1,14 @@
+import { nada, uniq } from "$lib/utils";
+import config from "$config";
+import { g, s, db } from "$lib/db";
+import { q } from "$lib/nostr";
+
export default {
async event({ params: { id } }, res) {
- let event = JSON.parse(await g(`ev:${id}`));
+ let event = await g(`ev:${id}`);
let { pubkey } = event;
- event.user = JSON.parse(await g(`user:${pubkey}`)) || {
+ event.user = (await g(`user:${pubkey}`)) || {
username: pubkey.substr(0, 6),
pubkey,
anon: true,
@@ -15,13 +20,7 @@ export default {
},
async notes({ params: { pubkey } }, res) {
- let user = JSON.parse(await g(`user:${pubkey}`));
-
- if (!user) {
- user = await db.User.findOne({
- where: { pubkey }
- });
- }
+ let user = await g(`user:${pubkey}`);
if (!user)
user = {
@@ -40,7 +39,7 @@ export default {
q(`${pubkey}:notes`, params, opts).catch(nada);
- await g(`user:${pubkey}`, JSON.stringify(user));
+ await s(`user:${pubkey}`, user);
let ids = await db.sMembers(pubkey);
@@ -57,7 +56,7 @@ export default {
res.send(event);
},
- async follows({ params: { pubkey }, query: { tagsOnly } }, res) {
+ async follows({ params: { pubkey }, query: { tagsonly } }, res) {
let sub = `${pubkey}:follows`,
params = {
limit: 1,
@@ -68,7 +67,7 @@ export default {
q(sub, params, opts).catch(nada);
- let tags = JSON.parse(await g(`${pubkey}:follows`)) || [];
+ let tags = (await g(`${pubkey}:follows`)) || [];
if (tagsonly) return res.send(tags);
let follows = [];
@@ -81,7 +80,7 @@ export default {
authors: [pubkey]
}).catch(nada);
- let user = JSON.parse(await g(`user:${pubkey}`));
+ let user = await g(`user:${pubkey}`);
if (!user)
user = {
@@ -99,11 +98,10 @@ export default {
res.send(follows);
},
- async followers({ params: { pubkey}}, res) {
+ async followers({ params: { pubkey } }, res) {
try {
let pubkeys = [
...new Set([
- ...(await got(`${config.nostr}/followers?pubkey=${pubkey}`).json()),
...(await db.sMembers(`${pubkey}:followers`))
])
];
@@ -117,7 +115,7 @@ export default {
).catch(nada);
for (let pubkey of pubkeys) {
- let user = JSON.parse(await g(`user:${pubkey}`));
+ let user = await g(`user:${pubkey}`);
if (!user || !user.updated) {
q(`${pubkey}:profile:f2`, {
limit: 1,
@@ -125,7 +123,7 @@ export default {
authors: [pubkey]
}).catch(nada);
- user = JSON.parse(await g(`user:${pubkey}`));
+ user = await g(`user:${pubkey}`);
}
if (!user)
diff --git a/routes/send.js b/routes/send.js
index 1bd4910a..4b954616 100644
--- a/routes/send.js
+++ b/routes/send.js
@@ -8,7 +8,7 @@ export default async (req, res, next) => {
let payment = await sendInternal(req.body, req.user);
res.send(payment);
} catch (e) {
- console.log(e)
+ console.log(e);
err("problem sending internal payment", e.message);
return res.code(500).send(e.message);
}