aboutsummaryrefslogtreecommitdiffstats
path: root/routes
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2023-01-06 23:02:01 -0800
committerAdam Soltys <[email protected]>2023-01-06 23:02:01 -0800
commit018732b4544fd95b7f1830db8b43dce26ebec1aa (patch)
tree1829685a50906b7f21434e64bfad92d876466697 /routes
parent6df7873c907024285504f6ad684ecc1d1f9b7141 (diff)
downloadcoinos-server-018732b4544fd95b7f1830db8b43dce26ebec1aa.tar.gz
coinos-server-018732b4544fd95b7f1830db8b43dce26ebec1aa.zip
event endpoint, send uuid with contacts
Diffstat (limited to 'routes')
-rw-r--r--routes/events.js33
-rw-r--r--routes/users.js10
2 files changed, 31 insertions, 12 deletions
diff --git a/routes/events.js b/routes/events.js
index 554be5d8..e52b8a7c 100644
--- a/routes/events.js
+++ b/routes/events.js
@@ -5,6 +5,25 @@ import { coinos, pool, q } from "$lib/nostr";
import store from "$lib/store";
import { nada, wait } from "$lib/utils";
+app.get("/event/:id", async (req, res) => {
+ try {
+ let event = JSON.parse(await redis.get(`ev:${req.params.id}`));
+ let { pubkey } = event;
+
+ event.user = JSON.parse(await redis.get(`user:${pubkey}`)) || {
+ username: pubkey.substr(0, 6),
+ pubkey,
+ anon: true,
+ follows: [],
+ followers: []
+ };
+
+ res.send(event);
+ } catch (e) {
+ res.code(500).send("Problem fetching event");
+ }
+});
+
app.get("/nostr/:pubkey", async (req, res) => {
try {
let { pubkey } = req.params;
@@ -26,10 +45,14 @@ app.get("/nostr/:pubkey", async (req, res) => {
followers: []
};
- q(`${pubkey}:notes`, {
- kinds: [1],
- authors: [pubkey]
- }).catch(nada);
+ q(
+ `${pubkey}:notes`,
+ {
+ kinds: [1],
+ authors: [pubkey]
+ },
+ { since: 0 }
+ ).catch(nada);
await redis.set(`user:${pubkey}`, JSON.stringify(user));
@@ -39,7 +62,7 @@ app.get("/nostr/:pubkey", async (req, res) => {
? (await redis.mGet(ids.map(k => "ev:" + k))).map(JSON.parse)
: [];
- res.send(events);
+ res.send(events.map(e => ({ ...e, user })));
} catch (e) {
console.log(e);
res.code(500).send("problem fetching user events");
diff --git a/routes/users.js b/routes/users.js
index 329210c8..4e6b8a63 100644
--- a/routes/users.js
+++ b/routes/users.js
@@ -619,7 +619,7 @@ app.get("/contacts", auth, async function(req, res) {
with_id: { [Sequelize.Op.ne]: null }
},
include: {
- attributes: ["username", "profile"],
+ attributes: ["username", "profile", "uuid"],
model: db.User,
as: "with"
},
@@ -666,9 +666,7 @@ app.get("/:pubkey/follows", async (req, res) => {
kinds: [3],
authors: [pubkey]
},
- 60000,
- 3600,
- 60000
+ { timeout: 60000, eager: 60000 }
).catch(nada);
let tags = JSON.parse(await redis.get(`${pubkey}:follows`)) || [];
@@ -722,9 +720,7 @@ app.get("/:pubkey/followers", async (req, res) => {
q(
`${pubkey}:followers`,
{ kinds: [3], "#p": [pubkey] },
- 60000,
- 3600,
- 60000
+ { timeout: 60000, eager: 60000 }
).catch(nada);
for (let pubkey of pubkeys) {