diff options
| author | Adam Soltys <[email protected]> | 2025-01-23 16:39:52 -0800 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2025-01-23 16:39:52 -0800 |
| commit | 615e3d3de3ea9af086ecded723e8a2a5787ac8c7 (patch) | |
| tree | bde16aa6de78d2bd0ee9f87cab5ef369ffda1f65 /lib | |
| parent | a1f4ed6408655dde0f1e6d71f7a571571b9cc826 (diff) | |
| download | coinos-server-615e3d3de3ea9af086ecded723e8a2a5787ac8c7.tar.gz coinos-server-615e3d3de3ea9af086ecded723e8a2a5787ac8c7.zip | |
unified event endpoint
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/nostr.ts | 20 |
1 files changed, 13 insertions, 7 deletions
diff --git a/lib/nostr.ts b/lib/nostr.ts index 9f31f6ad..aca518b6 100644 --- a/lib/nostr.ts +++ b/lib/nostr.ts @@ -7,6 +7,8 @@ import { finalizeEvent, getPublicKey, nip19 } from "nostr-tools"; import { AbstractSimplePool } from "nostr-tools/abstract-pool"; import { Relay } from "nostr-tools/relay"; +export const EX = 60 * 60 * 24; + export const serverPubkey = getPublicKey( nip19.decode(config.nostrKey).data as Uint8Array, ); @@ -144,7 +146,7 @@ export const getProfile = async (pubkey) => { profile = anon(pubkey); } - await db.set(`profile:${pubkey}`, JSON.stringify(profile), { EX: 300 }); + await db.set(`profile:${pubkey}`, JSON.stringify(profile), { EX }); return profile; }; @@ -153,17 +155,21 @@ export const getCount = async (pubkey) => { try { let follows = await g(`${pubkey}:follows:n`); - if (!follows) { + if (follows === null) { const result = await get({ authors: [pubkey], kinds: [3] }); follows = result ? result.tags.filter((t) => t[0] === "p").length : 0; - await db.set(`${pubkey}:follows:n`, follows, { EX: 300 }); + await db.set(`${pubkey}:follows:n`, follows, { EX }); } - let followers = await g(`${pubkey}:followers:n`); + const k = `${pubkey}:followers:n`; + let followers = await g(k); - if (!followers) { - [followers] = await count({ "#p": [pubkey], kinds: [3] }); - await db.set(`${pubkey}:followers:n`, followers, { EX: 300 }); + if (followers === null) { + [followers] = await count({ + "#p": [pubkey], + kinds: [3], + }); + await db.set(k, followers, { EX }); } return { follows, followers }; |
