diff options
| author | Adam Soltys <[email protected]> | 2025-01-16 14:57:14 -0800 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2025-01-16 14:57:14 -0800 |
| commit | ef71c296071be3081b3ac0d742283a261135ae6d (patch) | |
| tree | ad74616c3e32c306ad5c1ded6b1ecf4da85f0591 /lib | |
| parent | 127806d1b703eb3d144e302f20268a7555f9b016 (diff) | |
| download | coinos-server-ef71c296071be3081b3ac0d742283a261135ae6d.tar.gz coinos-server-ef71c296071be3081b3ac0d742283a261135ae6d.zip | |
zap endpoints
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/nostr.ts | 41 |
1 files changed, 13 insertions, 28 deletions
diff --git a/lib/nostr.ts b/lib/nostr.ts index 5ef8af3d..f5d85ea0 100644 --- a/lib/nostr.ts +++ b/lib/nostr.ts @@ -1,7 +1,7 @@ import config from "$config"; -import { g, s } from "$lib/db"; +import { db, g, s } from "$lib/db"; import { l } from "$lib/logging"; -import { count, scan } from "$lib/strfry"; +import { count, scan, sync } from "$lib/strfry"; import { fail } from "$lib/utils"; import { finalizeEvent, getPublicKey, nip19 } from "nostr-tools"; import { AbstractSimplePool } from "nostr-tools/abstract-pool"; @@ -125,36 +125,21 @@ export const getRelays = async (pubkey): Promise<any> => { return { read, write }; }; -export const getProfile = async (pubkey, relays = [config.nostr]) => { - let profile = await g(`${pubkey}:profile`); +export const getProfile = async (pubkey) => { + let profile = await g(`profile:${pubkey}`); + if (profile) return profile; - if (!profile) { - const pubkeys = [pubkey]; - let filter: any = { authors: pubkeys, kinds: [0] }; + const filter = { authors: [pubkey], kinds: [0] }; + const events = await scan(filter); - let ev = await pool.get(relays, filter, opts); - - if (!ev) { - ({ write: relays } = await getRelays(pubkey)); - ev = await pool.get(relays, filter, opts); - } - - if (!ev) { - filter = { cache: ["user_infos", { pubkeys }] }; - ev = (await pool.querySync([config.cache], filter, opts)).find( - (e) => e.kind === 0, - ); - } - - if (ev) { - send(ev); - profile = JSON.parse(ev.content); - } else { - profile = anon(pubkey); - } + if (events.length) { + profile = JSON.parse(events[0].content); + } else { + profile = anon(pubkey); } - await s(`${pubkey}:profile`, profile); + await db.set(`profile:${pubkey}`, JSON.stringify(profile), { EX: 300 }); + return profile; }; |
