fix: temp remove try-catch for log purposes

This commit is contained in:
Bart van der Braak 2024-01-21 22:39:16 +01:00
parent 1d7f8878da
commit b4bf22ea84

View file

@ -11,66 +11,66 @@ const height = 630;
const width = 1200; const width = 1200;
const getImageData = async () => { const getImageData = async () => {
try { // try {
const imagePath = path.join(process.cwd(), 'src', 'lib', 'assets', 'og', 'me.jpg'); const imagePath = path.join(process.cwd(), 'src', 'lib', 'assets', 'og', 'me.jpg');
const meImage = await readFile(imagePath); const meImage = await readFile(imagePath);
return Buffer.from(meImage).toString('base64'); return Buffer.from(meImage).toString('base64');
} catch (error) { // } catch (error) {
console.error('Error reading image:', error); // console.error('Error reading image:', error);
throw error; // throw error;
} // }
}; };
/** @type {import('./$types').RequestHandler} */ /** @type {import('./$types').RequestHandler} */
export const GET = async ({ url }) => { export const GET = async ({ url }) => {
try { // try {
const title = url.searchParams.get('title') ?? undefined; const title = url.searchParams.get('title') ?? undefined;
const subTitle = url.searchParams.get('subTitle') ?? undefined; const subTitle = url.searchParams.get('subTitle') ?? undefined;
const imageData = await getImageData(); const imageData = await getImageData();
// eslint-disable-next-line @typescript-eslint/no-explicit-any // eslint-disable-next-line @typescript-eslint/no-explicit-any
const result = (OgImage as any).render({ title, subTitle, imageData }); const result = (OgImage as any).render({ title, subTitle, imageData });
const element = toReactNode(`${result.html}<style>${result.css.code}</style>`); const element = toReactNode(`${result.html}<style>${result.css.code}</style>`);
const svg = await satori(element, { const svg = await satori(element, {
fonts: [ fonts: [
{ {
name: 'Geist Regular', name: 'Geist Regular',
data: Buffer.from(GeistRegular), data: Buffer.from(GeistRegular),
weight: 100 weight: 100
}, },
{ {
name: 'Geist Bold', name: 'Geist Bold',
data: Buffer.from(GeistBold), data: Buffer.from(GeistBold),
weight: 700 weight: 700
}
],
height,
width
});
const resvg = new Resvg(svg, {
fitTo: {
mode: 'width',
value: width
} }
}); ],
height,
width
});
const image = resvg.render(); const resvg = new Resvg(svg, {
fitTo: {
mode: 'width',
value: width
}
});
return new Response(image.asPng(), { const image = resvg.render();
headers: {
'content-type': 'image/png' return new Response(image.asPng(), {
} headers: {
}); 'content-type': 'image/png'
} catch (error) { }
console.error('Error generating image:', error); });
return new Response('Internal Server Error', { // } catch (error) {
status: 500, // console.error('Error generating image:', error);
headers: { // return new Response('Internal Server Error', {
'content-type': 'text/plain' // status: 500,
} // headers: {
}); // 'content-type': 'text/plain'
} // }
// });
// }
}; };