From a9ce012ccb289bdb5e8d20ae97d39c22dd030e35 Mon Sep 17 00:00:00 2001 From: Kieran Date: Thu, 30 Mar 2023 12:18:35 +0100 Subject: [PATCH] Offload tagging to api --- functions/e/[id].ts | 29 +++++++++++++---------------- functions/p/[id].ts | 25 +++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 16 deletions(-) create mode 100644 functions/p/[id].ts diff --git a/functions/e/[id].ts b/functions/e/[id].ts index 58f0b51..805ce1e 100644 --- a/functions/e/[id].ts +++ b/functions/e/[id].ts @@ -1,13 +1,4 @@ - interface Env { - KV: KVNamespace; -} - -interface RawEvent { - id: string, - content: string, - created_at: string, - pubkey: string } export const onRequest: PagesFunction = async (context) => { @@ -17,12 +8,18 @@ export const onRequest: PagesFunction = async (context) => { console.debug(next.status); console.debug("Fetching data for: ", id); - const rsp = await fetch(`https://api.snort.social/api/v1/raw/e/${id}`); + const rsp = await fetch(`https://api.snort.social/api/v1/og/tag/e/${id}`, { + method: "POST", + body: await next.arrayBuffer(), + headers: { + "content-type": "text/plain" + } + }); console.debug(rsp.status, rsp.statusText); - if (rsp.ok) { - const json: RawEvent = await rsp.json(); - console.debug(json); - - } - return new Response("test"); + const body = await rsp.text(); + return new Response(body, { + headers: { + "content-type": "text/html" + } + }); } \ No newline at end of file diff --git a/functions/p/[id].ts b/functions/p/[id].ts new file mode 100644 index 0000000..13123aa --- /dev/null +++ b/functions/p/[id].ts @@ -0,0 +1,25 @@ +interface Env { +} + +export const onRequest: PagesFunction = async (context) => { + const id = context.params.id as string; + + const next = await context.next(); + console.debug(next.status); + console.debug("Fetching data for: ", id); + + const rsp = await fetch(`https://api.snort.social/api/v1/og/tag/p/${id}`, { + method: "POST", + body: await next.arrayBuffer(), + headers: { + "content-type": "text/plain" + } + }); + console.debug(rsp.status, rsp.statusText); + const body = await rsp.text(); + return new Response(body, { + headers: { + "content-type": "text/html" + } + }); +} \ No newline at end of file