mirror of
https://github.com/walkxcode/dashboard-icons.git
synced 2025-11-26 22:58:41 +01:00
try cdn fallback
This commit is contained in:
@@ -2,7 +2,6 @@ import { readFile } from "node:fs/promises";
|
||||
import { join } from "node:path";
|
||||
import { ImageResponse } from "next/og";
|
||||
import { getAllIcons } from "@/lib/api";
|
||||
import { BASE_URL } from "@/constants";
|
||||
|
||||
export const revalidate = false;
|
||||
export async function generateStaticParams() {
|
||||
@@ -67,19 +66,21 @@ export default async function Image({
|
||||
.join(" ");
|
||||
|
||||
// Read the icon file from local filesystem
|
||||
let iconData: ArrayBuffer | null = null;
|
||||
let iconData: Buffer | null = null;
|
||||
try {
|
||||
const fetchedIcon = await fetch(`${BASE_URL}/png/${icon}.png`);
|
||||
if (!fetchedIcon.ok) {
|
||||
throw new Error(`Failed to fetch icon ${icon} from CDN`);
|
||||
}
|
||||
iconData = await fetchedIcon.arrayBuffer();
|
||||
const iconPath = join(process.cwd(), `../png/${icon}.png`);
|
||||
console.log(
|
||||
`Generating opengraph image for ${icon} (${index + 1} / ${totalIcons}) from path ${iconPath}`,
|
||||
);
|
||||
iconData = await readFile(iconPath);
|
||||
} catch (_error) {
|
||||
console.error(`Icon ${icon} was not found. Using placeholder instead.`);
|
||||
console.error(`Icon ${icon} was not found locally`);
|
||||
}
|
||||
|
||||
// Convert the image data to a data URL or use placeholder
|
||||
const iconUrl = iconData ? `data:image/png;base64,${Buffer.from(iconData).toString("base64")}` : null;
|
||||
const iconUrl = iconData
|
||||
? `data:image/png;base64,${iconData.toString("base64")}`
|
||||
: null;
|
||||
|
||||
return new ImageResponse(
|
||||
<div
|
||||
|
||||
Reference in New Issue
Block a user