chore: cleanup functions

This commit is contained in:
Kieran 2023-03-30 12:54:01 +01:00
parent bf194a8545
commit f5e6ef679b
Signed by: Kieran
GPG Key ID: DE71CEB3925BE941
2 changed files with 42 additions and 32 deletions

View File

@ -5,21 +5,26 @@ export const onRequest: PagesFunction<Env> = async (context) => {
const id = context.params.id as string; const id = context.params.id as string;
const next = await context.next(); const next = await context.next();
console.debug(next.status); try {
console.debug("Fetching data for: ", id); const rsp = await fetch(`https://api.snort.social/api/v1/og/tag/e/${id}`, {
method: "POST",
const rsp = await fetch(`https://api.snort.social/api/v1/og/tag/e/${id}`, { body: await next.arrayBuffer(),
method: "POST", headers: {
body: await next.arrayBuffer(), "content-type": "text/plain"
headers: { }
"content-type": "text/plain" });
if (rsp.ok) {
const body = await rsp.text();
if (body.length > 0) {
return new Response(body, {
headers: {
"content-type": "text/html"
}
});
}
} }
}); } catch {
console.debug(rsp.status, rsp.statusText); // ignore
const body = await rsp.text(); }
return new Response(body, { return next;
headers: {
"content-type": "text/html"
}
});
} }

View File

@ -5,21 +5,26 @@ export const onRequest: PagesFunction<Env> = async (context) => {
const id = context.params.id as string; const id = context.params.id as string;
const next = await context.next(); const next = await context.next();
console.debug(next.status); try {
console.debug("Fetching data for: ", id); const rsp = await fetch(`https://api.snort.social/api/v1/og/tag/p/${id}`, {
method: "POST",
const rsp = await fetch(`https://api.snort.social/api/v1/og/tag/p/${id}`, { body: await next.arrayBuffer(),
method: "POST", headers: {
body: await next.arrayBuffer(), "content-type": "text/plain"
headers: { }
"content-type": "text/plain" });
if (rsp.ok) {
const body = await rsp.text();
if (body.length > 0) {
return new Response(body, {
headers: {
"content-type": "text/html"
}
});
}
} }
}); } catch {
console.debug(rsp.status, rsp.statusText); // ignore
const body = await rsp.text(); }
return new Response(body, { return next;
headers: {
"content-type": "text/html"
}
});
} }