diff options
| author | Adam Soltys <[email protected]> | 2024-08-20 12:11:15 -0700 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2024-08-20 12:11:20 -0700 |
| commit | 0dd1feac21158c13cf99a96a306f3c8bf92e31cd (patch) | |
| tree | 584f535e170b12d7bac22fa48fb068c535bfe108 /routes | |
| parent | fccc373c0e59222d7253740337ccc34409af9639 (diff) | |
| download | coinos-server-0dd1feac21158c13cf99a96a306f3c8bf92e31cd.tar.gz coinos-server-0dd1feac21158c13cf99a96a306f3c8bf92e31cd.zip | |
update nip5 endpoint
Diffstat (limited to 'routes')
| -rw-r--r-- | routes/nostr.js | 16 | ||||
| -rw-r--r-- | routes/users.js | 1 |
2 files changed, 11 insertions, 6 deletions
diff --git a/routes/nostr.js b/routes/nostr.js index 95186078..1bd6ffff 100644 --- a/routes/nostr.js +++ b/routes/nostr.js @@ -1,4 +1,4 @@ -import { bail, nada, uniq } from "$lib/utils"; +import { bail, nada, getUser, uniq } from "$lib/utils"; import config from "$config"; import { g, s, db } from "$lib/db"; import { pool, q } from "$lib/nostr"; @@ -192,12 +192,16 @@ export default { } }, - async identities(req, res) { + async identities({ query: { name } }, res) { let names = {}; - for await (let k of db.scanIterator({ MATCH: "user:*" })) { - let u = await g(k); - if (typeof u === "string") u = await g(`user:${u}`); - if (u && u.username && u.pubkey && u.nip5) names[u.username] = u.pubkey; + if (name) { + names = { [name]: (await getUser(name)).pubkey }; + } else { + let records = await db.sMembers("nip5"); + for (let s of records) { + let [name, pubkey] = s.split(":"); + names[name] = pubkey; + } } res.send({ names }); diff --git a/routes/users.js b/routes/users.js index 7ded7e01..f46136c0 100644 --- a/routes/users.js +++ b/routes/users.js @@ -276,6 +276,7 @@ export default { ); await s(`user:${user.id}`, user); + if (user.nip5) await db.sAdd('nip5', `${user.username}:${user.pubkey}`); emit(user.id, "user", user); res.send({ user, token }); |
