feat: opengraph tag injector
Some checks reported errors
continuous-integration/drone/push Build encountered an error

This commit is contained in:
Kieran 2024-01-10 14:36:21 +00:00
parent 632e17f236
commit 84bbc5fbef
Signed by: Kieran
GPG Key ID: DE71CEB3925BE941
4 changed files with 48 additions and 0 deletions

31
functions/[id].ts Normal file
View File

@ -0,0 +1,31 @@
interface Env {}
export const onRequest: PagesFunction<Env> = async context => {
const id = context.params.id as string;
const next = await context.next();
try {
const rsp = await fetch(`http://nostr.api.v0l.io/api/v1/opengraph/${id}?canonical=${encodeURIComponent("https://zap.stream/%s")}`, {
method: "POST",
body: await next.arrayBuffer(),
headers: {
"user-agent": "zap.stream/1.0 (https://zap.stream)",
"content-type": "text/html",
"accept": "text/html"
},
});
if (rsp.ok) {
const body = await rsp.text();
if (body.length > 0) {
return new Response(body, {
headers: {
"content-type": "text/html",
},
});
}
}
} catch {
// ignore
}
return next;
};

8
functions/tsconfig.json Normal file
View File

@ -0,0 +1,8 @@
{
"compilerOptions": {
"target": "esnext",
"module": "esnext",
"lib": ["esnext"],
"types": ["@cloudflare/workers-types"]
}
}

View File

@ -79,6 +79,7 @@
]
},
"devDependencies": {
"@cloudflare/workers-types": "^4.20231218.0",
"@formatjs/cli": "^6.1.3",
"@formatjs/ts-transformer": "^3.13.3",
"@testing-library/dom": "^9.3.1",

View File

@ -1556,6 +1556,13 @@ __metadata:
languageName: node
linkType: hard
"@cloudflare/workers-types@npm:^4.20231218.0":
version: 4.20231218.0
resolution: "@cloudflare/workers-types@npm:4.20231218.0"
checksum: b7e50a76ee8e9d662227bbb74798b93b6102acc224f1071a9c99a9adb419ad0b3bdabf7561e7e1b4a320a6a4616badeecdfb1848fbdaada197c7b37d845b8774
languageName: node
linkType: hard
"@emoji-mart/data@npm:^1.1.2":
version: 1.1.2
resolution: "@emoji-mart/data@npm:1.1.2"
@ -7792,6 +7799,7 @@ __metadata:
version: 0.0.0-use.local
resolution: "stream_ui@workspace:."
dependencies:
"@cloudflare/workers-types": ^4.20231218.0
"@emoji-mart/data": ^1.1.2
"@emoji-mart/react": ^1.1.1
"@formatjs/cli": ^6.1.3