diff options
| -rw-r--r-- | lib/utils.ts | 2 | ||||
| -rw-r--r-- | routes/nostr.ts | 13 |
2 files changed, 9 insertions, 6 deletions
diff --git a/lib/utils.ts b/lib/utils.ts index 6649c752..a0a831d9 100644 --- a/lib/utils.ts +++ b/lib/utils.ts @@ -51,7 +51,7 @@ export const bip21 = (address, { amount, memo, tip, type }) => { return `${network}:${address}?${url.toString()}`; }; -export const getUser = async (username, fields) => { +export const getUser = async (username, fields = undefined) => { let update; if (username === "undefined") fail("invalid user"); const user = await migrate(username); diff --git a/routes/nostr.ts b/routes/nostr.ts index 21f85aea..0ebc879b 100644 --- a/routes/nostr.ts +++ b/routes/nostr.ts @@ -1,5 +1,5 @@ import config from "$config"; -import { db, g } from "$lib/db"; +import { db } from "$lib/db"; import ln from "$lib/ln"; import { anon, @@ -12,6 +12,7 @@ import { import { scan, sync } from "$lib/strfry"; import { bail, fail, fields, getUser } from "$lib/utils"; import got from "got"; +import type { Event } from "nostr-tools"; import { decode } from "nostr-tools/nip19"; import type { ProfilePointer } from "nostr-tools/nip19"; import { getZapEndpoint, makeZapRequest } from "nostr-tools/nip57"; @@ -23,10 +24,12 @@ export default { if (id.startsWith("note")) id = decode(id).data; const filter = { ids: [id] }; let events = await scan(filter); + if (!events.length) { await sync("wss://relay.primal.net", filter); events = await scan(filter); } + if (!events.length) return bail(res, "event not found"); res.send(events[0]); }, @@ -42,7 +45,7 @@ export default { await sync("wss://relay.primal.net", filter); events = await scan(filter); } - if (!events.length) return bail(res, "event not found"); + if (!events.length) return res.send([]); const zaps = []; for (const { tags } of events) { @@ -202,7 +205,7 @@ export default { } = req; let names = {}; if (name) { - names = { [name]: (await getUser(name)).pubkey }; + names = { [name]: (await getUser(name, fields)).pubkey }; } else { const records = await db.sMembers("nip5"); for (const s of records) { @@ -249,9 +252,9 @@ export default { const amount = event.tags.find((t) => t[0] === "amount")[1]; const pubkey = event.tags.find((t) => t[0] === "p")[1]; const content = JSON.stringify(await getProfile(pubkey)); - const callback = await getZapEndpoint({ content }); + const callback = await getZapEndpoint({ content } as Event); const url = new URL(callback); - url.searchParams.set("amount", amount * 1000); + url.searchParams.set("amount", (amount * 1000).toString()); url.searchParams.set("nostr", encodeURIComponent(JSON.stringify(event))); const json = await got(url.toString()).json(); |
