diff options
| author | Adam Soltys <[email protected]> | 2023-01-06 17:31:22 -0800 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2023-01-06 17:31:22 -0800 |
| commit | e3266ddecd825b8716df7dc418246441d4dcb0f7 (patch) | |
| tree | 650dac95a42a09627f33fb3f3e76e6e0a0e23b9f /routes | |
| parent | 6f7ad86583ee4e9e359829b55cb041d014902e07 (diff) | |
| download | coinos-server-e3266ddecd825b8716df7dc418246441d4dcb0f7.tar.gz coinos-server-e3266ddecd825b8716df7dc418246441d4dcb0f7.zip | |
background nostr fetching
Diffstat (limited to 'routes')
| -rw-r--r-- | routes/events.js | 5 | ||||
| -rw-r--r-- | routes/users.js | 59 |
2 files changed, 47 insertions, 17 deletions
diff --git a/routes/events.js b/routes/events.js index 1734af24..bbdd8891 100644 --- a/routes/events.js +++ b/routes/events.js @@ -26,14 +26,15 @@ app.get("/nostr/:pubkey", async (req, res) => { followers: [] }; - await q(pubkey, { + q(`${pubkey}:notes`, { kinds: [1], authors: [pubkey] - }); + }).catch(console.log); await redis.set(`user:${pubkey}`, JSON.stringify(user)); let ids = await redis.sMembers(pubkey); + console.log("IDS", ids); let events = ids.length ? (await redis.mGet(ids.map(k => "ev:" + k))).map(JSON.parse) diff --git a/routes/users.js b/routes/users.js index d2cb1540..d209c3d9 100644 --- a/routes/users.js +++ b/routes/users.js @@ -3,7 +3,7 @@ import redis from "$lib/redis"; import config from "$config"; import store from "$lib/store"; import { auth, optionalAuth } from "$lib/passport"; -import { getUser, uniq, wait } from "$lib/utils"; +import { getUser, nada, uniq, wait } from "$lib/utils"; import bcrypt from "bcrypt"; import jwt from "jsonwebtoken"; import { authenticator } from "otplib"; @@ -74,7 +74,9 @@ app.get("/users/:username", async (req, res) => { "profile", "address", "currency", - "pubkey" + "pubkey", + "display", + "prompt" ], where: { [Sequelize.Op.or]: [ @@ -214,9 +216,11 @@ app.post("/user", auth, async (req, res) => { "cipher", "currencies", "currency", + "display", "email", "fiat", "locktime", + "prompt", "pubkey", "salt", "seed", @@ -654,11 +658,17 @@ app.get("/:pubkey/follows", async (req, res) => { let { tagsonly } = req.query; let sub = `${pubkey}:follows`; - await q(sub, { - limit: 1, - kinds: [3], - authors: [pubkey] - }); + q( + sub, + { + limit: 1, + kinds: [3], + authors: [pubkey] + }, + 60000, + 3600, + 60000 + ).catch(nada); let tags = JSON.parse(await redis.get(`${pubkey}:follows`)) || []; if (tagsonly) return res.send(tags); @@ -667,14 +677,22 @@ app.get("/:pubkey/follows", async (req, res) => { for (let f of tags) { let [_, pubkey] = f; - await q(`${pubkey}:profile:f1`, { + q(`${pubkey}:profile:f1`, { limit: 1, kinds: [0], authors: [pubkey] - }); + }).catch(nada); let user = JSON.parse(await redis.get(`user:${pubkey}`)); - if (user) follows.push(user); + + if (!user) + user = { + username: pubkey.substr(0, 6), + pubkey, + anon: true + }; + + follows.push(user); } follows = uniq(follows, e => e.pubkey); @@ -691,20 +709,31 @@ app.get("/:pubkey/followers", async (req, res) => { try { let { pubkey } = req.params; - let pubkeys = await got( - `${config.nostr}/followers?pubkey=${pubkey}` - ).json(); + let pubkeys = [ + ...new Set([ + ...(await got(`${config.nostr}/followers?pubkey=${pubkey}`).json()), + ...(await redis.sMembers(`${pubkey}:followers`)) + ]) + ]; let followers = []; + q( + `${pubkey}:followers`, + { kinds: [3], "#p": [pubkey] }, + 60000, + 3600, + 60000 + ).catch(nada); + for (let pubkey of pubkeys) { let user = JSON.parse(await redis.get(`user:${pubkey}`)); if (!user || !user.updated) { - await q(`${pubkey}:profile:f2`, { + q(`${pubkey}:profile:f2`, { limit: 1, kinds: [0], authors: [pubkey] - }); + }).catch(nada); user = JSON.parse(await redis.get(`user:${pubkey}`)); } |
