aboutsummaryrefslogtreecommitdiffstats
path: root/routes
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2025-01-17 06:02:01 -0800
committerAdam Soltys <[email protected]>2025-01-17 06:02:01 -0800
commit4da8b4e77e64fb1f410acb635c0f85d2a8b3603b (patch)
tree78644e3230b01c9ea8ce5c3fe960265ae675115d /routes
parentef71c296071be3081b3ac0d742283a261135ae6d (diff)
downloadcoinos-server-4da8b4e77e64fb1f410acb635c0f85d2a8b3603b.tar.gz
coinos-server-4da8b4e77e64fb1f410acb635c0f85d2a8b3603b.zip
handle no zaps case
Diffstat (limited to 'routes')
-rw-r--r--routes/nostr.ts13
1 files changed, 8 insertions, 5 deletions
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();