chore: cleanup functions

This commit is contained in:
2023-03-30 12:54:01 +01:00
parent bf194a8545
commit f5e6ef679b
2 changed files with 42 additions and 32 deletions

View File

@ -5,9 +5,7 @@ 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}`, { const rsp = await fetch(`https://api.snort.social/api/v1/og/tag/e/${id}`, {
method: "POST", method: "POST",
body: await next.arrayBuffer(), body: await next.arrayBuffer(),
@ -15,11 +13,18 @@ export const onRequest: PagesFunction<Env> = async (context) => {
"content-type": "text/plain" "content-type": "text/plain"
} }
}); });
console.debug(rsp.status, rsp.statusText); if (rsp.ok) {
const body = await rsp.text(); const body = await rsp.text();
if (body.length > 0) {
return new Response(body, { return new Response(body, {
headers: { headers: {
"content-type": "text/html" "content-type": "text/html"
} }
}); });
} }
}
} catch {
// ignore
}
return next;
}

View File

@ -5,9 +5,7 @@ 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}`, { const rsp = await fetch(`https://api.snort.social/api/v1/og/tag/p/${id}`, {
method: "POST", method: "POST",
body: await next.arrayBuffer(), body: await next.arrayBuffer(),
@ -15,11 +13,18 @@ export const onRequest: PagesFunction<Env> = async (context) => {
"content-type": "text/plain" "content-type": "text/plain"
} }
}); });
console.debug(rsp.status, rsp.statusText); if (rsp.ok) {
const body = await rsp.text(); const body = await rsp.text();
if (body.length > 0) {
return new Response(body, { return new Response(body, {
headers: { headers: {
"content-type": "text/html" "content-type": "text/html"
} }
}); });
} }
}
} catch {
// ignore
}
return next;
}