feat: opengraph tag injector
This commit is contained in:
parent
632e17f236
commit
84bbc5fbef
31
functions/[id].ts
Normal file
31
functions/[id].ts
Normal 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
8
functions/tsconfig.json
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
{
|
||||||
|
"compilerOptions": {
|
||||||
|
"target": "esnext",
|
||||||
|
"module": "esnext",
|
||||||
|
"lib": ["esnext"],
|
||||||
|
"types": ["@cloudflare/workers-types"]
|
||||||
|
}
|
||||||
|
}
|
@ -79,6 +79,7 @@
|
|||||||
]
|
]
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
"@cloudflare/workers-types": "^4.20231218.0",
|
||||||
"@formatjs/cli": "^6.1.3",
|
"@formatjs/cli": "^6.1.3",
|
||||||
"@formatjs/ts-transformer": "^3.13.3",
|
"@formatjs/ts-transformer": "^3.13.3",
|
||||||
"@testing-library/dom": "^9.3.1",
|
"@testing-library/dom": "^9.3.1",
|
||||||
|
@ -1556,6 +1556,13 @@ __metadata:
|
|||||||
languageName: node
|
languageName: node
|
||||||
linkType: hard
|
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":
|
"@emoji-mart/data@npm:^1.1.2":
|
||||||
version: 1.1.2
|
version: 1.1.2
|
||||||
resolution: "@emoji-mart/data@npm:1.1.2"
|
resolution: "@emoji-mart/data@npm:1.1.2"
|
||||||
@ -7792,6 +7799,7 @@ __metadata:
|
|||||||
version: 0.0.0-use.local
|
version: 0.0.0-use.local
|
||||||
resolution: "stream_ui@workspace:."
|
resolution: "stream_ui@workspace:."
|
||||||
dependencies:
|
dependencies:
|
||||||
|
"@cloudflare/workers-types": ^4.20231218.0
|
||||||
"@emoji-mart/data": ^1.1.2
|
"@emoji-mart/data": ^1.1.2
|
||||||
"@emoji-mart/react": ^1.1.1
|
"@emoji-mart/react": ^1.1.1
|
||||||
"@formatjs/cli": ^6.1.3
|
"@formatjs/cli": ^6.1.3
|
||||||
|
Loading…
x
Reference in New Issue
Block a user