From d4b51f98036e1f08adce1a89da629096cced6471 Mon Sep 17 00:00:00 2001 From: Kieran Date: Sat, 18 Mar 2023 06:58:43 +0000 Subject: [PATCH 1/2] test --- functions/e/[id].ts | 28 ++++++++++++++++++++++++++++ functions/tsconfig.json | 8 ++++++++ package.json | 3 ++- yarn.lock | 5 +++++ 4 files changed, 43 insertions(+), 1 deletion(-) create mode 100644 functions/e/[id].ts create mode 100644 functions/tsconfig.json diff --git a/functions/e/[id].ts b/functions/e/[id].ts new file mode 100644 index 00000000..58f0b518 --- /dev/null +++ b/functions/e/[id].ts @@ -0,0 +1,28 @@ + +interface Env { + KV: KVNamespace; +} + +interface RawEvent { + id: string, + content: string, + created_at: string, + pubkey: string +} + +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/raw/e/${id}`); + console.debug(rsp.status, rsp.statusText); + if (rsp.ok) { + const json: RawEvent = await rsp.json(); + console.debug(json); + + } + return new Response("test"); +} \ No newline at end of file diff --git a/functions/tsconfig.json b/functions/tsconfig.json new file mode 100644 index 00000000..e0b6870e --- /dev/null +++ b/functions/tsconfig.json @@ -0,0 +1,8 @@ +{ + "compilerOptions": { + "target": "esnext", + "module": "esnext", + "lib": ["esnext"], + "types": ["@cloudflare/workers-types"] + } + } \ No newline at end of file diff --git a/package.json b/package.json index 0fe9faf5..8e2e17d5 100644 --- a/package.json +++ b/package.json @@ -8,6 +8,7 @@ "start": "yarn workspace @snort/nostr build && yarn workspace @snort/app start" }, "devDependencies": { - "@tauri-apps/cli": "^1.2.3" + "@tauri-apps/cli": "^1.2.3", + "@cloudflare/workers-types": "^4.20230307.0" } } \ No newline at end of file diff --git a/yarn.lock b/yarn.lock index 1eaed49e..768014c0 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1083,6 +1083,11 @@ resolved "https://registry.yarnpkg.com/@bcoe/v8-coverage/-/v8-coverage-0.2.3.tgz#75a2e8b51cb758a7553d6804a5932d7aace75c39" integrity sha512-0hYQ8SB4Db5zvZB4axdMHGwEaQjkZzFjQiN9LVYvIFB2nSUHW9tYpxWriPrWDASIxiaXax83REcLxuSdnGPZtw== +"@cloudflare/workers-types@^4.20230307.0": + version "4.20230307.0" + resolved "https://registry.yarnpkg.com/@cloudflare/workers-types/-/workers-types-4.20230307.0.tgz#58a20fe167a5c48e20edba8e1fbfe4231bcfa223" + integrity sha512-Go968aDDcqONHQcUdgIiPRkPdT4QTzD0ecHJsI1u7ZiHPMOoZn+Dy7hYsdUJ5ldX9wTZDrICBM1rDKTRaDUitg== + "@csstools/normalize.css@*": version "12.0.0" resolved "https://registry.yarnpkg.com/@csstools/normalize.css/-/normalize.css-12.0.0.tgz#a9583a75c3f150667771f30b60d9f059473e62c4" From a9ce012ccb289bdb5e8d20ae97d39c22dd030e35 Mon Sep 17 00:00:00 2001 From: Kieran Date: Thu, 30 Mar 2023 12:18:35 +0100 Subject: [PATCH 2/2] 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 58f0b518..805ce1ea 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 00000000..13123aa6 --- /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