This commit is contained in:
thePR0M3TH3AN
2025-07-02 20:39:08 -04:00
parent 2d60dd2d5e
commit 63901d43ce

View File

@@ -32,7 +32,7 @@
<body class="bg-gray-900 text-gray-200"> <body class="bg-gray-900 text-gray-200">
<main id="app" class="w-full max-w-sm p-6 space-y-6 text-center"> <main id="app" class="w-full max-w-sm p-6 space-y-6 text-center">
<h1 class="text-3xl font-extrabold accent-gradient">Nostr Event Explorer</h1> <h1 class="text-3xl font-extrabold accent-gradient">Nostr Event Explorer</h1>
<p class="text-gray-400">Enter a relay URL and an event ID (hex, note1..., or nevent1...). If an nevent is provided with relays, those will be used; otherwise, the specified relay will be used.</p> <p class="text-gray-400">Enter a relay URL (optional if using nevent with relays) and an event ID (hex, note1..., or nevent1...).</p>
<form id="form" class="space-y-4"> <form id="form" class="space-y-4">
<input <input
id="relay" id="relay"
@@ -79,7 +79,15 @@
const dec = nip19.decode(eventIdInputClean); const dec = nip19.decode(eventIdInputClean);
if (dec.type === "nevent") { if (dec.type === "nevent") {
eventId = dec.data.id; eventId = dec.data.id;
relaysToUse = dec.data.relays && dec.data.relays.length > 0 ? dec.data.relays : [relay]; if (dec.data.relays && dec.data.relays.length > 0) {
relaysToUse = dec.data.relays;
} else {
if (!relay) {
showError("Please provide a relay URL");
return;
}
relaysToUse = [relay];
}
} else { } else {
showError("Invalid nevent"); showError("Invalid nevent");
return; return;
@@ -88,36 +96,39 @@
showError("Invalid nevent"); showError("Invalid nevent");
return; return;
} }
} else if (eventIdInputClean.startsWith("note1")) { } else {
try { if (!relay) {
const dec = nip19.decode(eventIdInputClean); showError("Please provide a relay URL");
if (dec.type === "note") { return;
eventId = dec.data; }
relaysToUse = [relay]; if (eventIdInputClean.startsWith("note1")) {
} else { try {
const dec = nip19.decode(eventIdInputClean);
if (dec.type === "note") {
eventId = dec.data;
} else {
showError("Invalid note bech32");
return;
}
} catch {
showError("Invalid note bech32"); showError("Invalid note bech32");
return; return;
} }
} catch { } else {
showError("Invalid note bech32"); if (!/^[0-9a-f]{64}$/.test(eventIdInputClean)) {
return; showError("Invalid event ID: must be 64 hex characters");
return;
}
eventId = eventIdInputClean;
} }
} else {
if (!/^[0-9a-f]{64}$/.test(eventIdInputClean)) {
showError("Invalid event ID: must be 64 hex characters");
return;
}
eventId = eventIdInputClean;
relaysToUse = [relay]; relaysToUse = [relay];
} }
// Check if relaysToUse are valid
if (relaysToUse.some(r => !r.startsWith("wss://"))) { if (relaysToUse.some(r => !r.startsWith("wss://"))) {
showError("Invalid relay URL: must start with wss://"); showError("Invalid relay URL: must start with wss://");
return; return;
} }
// Fetch the event
resultDiv.innerHTML = "<p>Loading...</p>"; resultDiv.innerHTML = "<p>Loading...</p>";
try { try {
const pool = new SimplePool(); const pool = new SimplePool();
@@ -126,7 +137,7 @@
const timer = setTimeout(() => { const timer = setTimeout(() => {
sub.unsub(); sub.unsub();
pool.close(); pool.close(relaysToUse);
showError("Timeout: event not found"); showError("Timeout: event not found");
}, TIMEOUT_MS); }, TIMEOUT_MS);
@@ -134,7 +145,7 @@
clearTimeout(timer); clearTimeout(timer);
event = ev; event = ev;
sub.unsub(); sub.unsub();
pool.close(); pool.close(relaysToUse);
displayEvent(event); displayEvent(event);
}); });