fix: only run function inject for nostr entity

This commit is contained in:
2024-01-10 14:40:11 +00:00
parent 576c9a2b9e
commit 721edb6527

View File

@ -1,9 +1,11 @@
interface Env {} interface Env {}
export const onRequest: PagesFunction<Env> = async context => { export const onRequest: PagesFunction<Env> = async context => {
const id = context.params.id as string; const id = context.params.id as string | undefined;
const prefixes = ["npub1", "nprofile1", "naddr1", "nevent1", "note1"];
const next = await context.next(); const next = await context.next();
if (id && prefixes.some(a => id.startsWith(a))) {
try { try {
const rsp = await fetch( const rsp = await fetch(
`http://nostr.api.v0l.io/api/v1/opengraph/${id}?canonical=${encodeURIComponent("https://zap.stream/%s")}`, `http://nostr.api.v0l.io/api/v1/opengraph/${id}?canonical=${encodeURIComponent("https://zap.stream/%s")}`,
@ -30,5 +32,6 @@ export const onRequest: PagesFunction<Env> = async context => {
} catch { } catch {
// ignore // ignore
} }
}
return next; return next;
}; };