From 587682e6619c6d56687126e0cf87fc3202e4aeb5 Mon Sep 17 00:00:00 2001 From: Thomas Camlong Date: Fri, 21 Nov 2025 14:41:44 +0100 Subject: [PATCH] fix: try to reduce cloud bill --- web/next.config.ts | 9 +- .../app/community/[icon]/opengraph-image.tsx | 360 ------------------ web/src/app/community/[icon]/page.tsx | 1 + web/src/app/icons/[icon]/opengraph-image.tsx | 67 +++- web/src/components/submission-details.tsx | 314 +++++++++------ 5 files changed, 248 insertions(+), 503 deletions(-) delete mode 100644 web/src/app/community/[icon]/opengraph-image.tsx diff --git a/web/next.config.ts b/web/next.config.ts index 0774fb81..5454588f 100644 --- a/web/next.config.ts +++ b/web/next.config.ts @@ -3,14 +3,7 @@ import type { NextConfig } from "next"; const nextConfig: NextConfig = { cacheComponents: false, images: { - remotePatterns: [ - new URL( - "https://pb.dashboardicons.com/**", - ), - new URL( - "https://cdn.jsdelivr.net/gh/homarr-labs/dashboard-icons/**", - ), - ], + unoptimized: true, }, }; diff --git a/web/src/app/community/[icon]/opengraph-image.tsx b/web/src/app/community/[icon]/opengraph-image.tsx deleted file mode 100644 index 94f17d72..00000000 --- a/web/src/app/community/[icon]/opengraph-image.tsx +++ /dev/null @@ -1,360 +0,0 @@ -import { permanentRedirect, redirect } from "next/navigation" -import { ImageResponse } from "next/og" -import { getCommunityGalleryRecord, getCommunitySubmissionByName, getCommunitySubmissions } from "@/lib/community" - -export const dynamic = "force-dynamic"; - -export const size = { - width: 1200, - height: 630, -} - -export const alt = "Community Icon Open Graph Image"; -export const contentType = "image/png"; - -export default async function Image({ params }: { params: Promise<{ icon: string }> }) { - const { icon } = await params - - if (!icon) { - return new ImageResponse( -
- Icon not found -
, - { ...size }, - ) - } - - const iconData = await getCommunitySubmissionByName(icon) - - if (!iconData) { - return new ImageResponse( -
- Icon not found -
, - { ...size }, - ) - } - - const record = await getCommunityGalleryRecord(icon) - if (record?.status === "added_to_collection") { - permanentRedirect(`/icons/${icon}/opengraph-image`) - } - - const status = record?.status || "pending" - const allIcons = await getCommunitySubmissions() - const totalIcons = allIcons.length - const index = allIcons.findIndex((i) => i.name === icon) - - const formattedIconName = icon - .split("-") - .map((word) => word.charAt(0).toUpperCase() + word.slice(1)) - .join(" ") - - const getStatusDisplayName = (status: string) => { - switch (status) { - case "pending": - return "Awaiting Review" - case "approved": - return "Approved" - case "rejected": - return "Rejected" - case "added_to_collection": - return "Added to Collection" - default: - return "Awaiting Review" - } - } - - const statusColors: Record = { - approved: { - bg: "#dbeafe", - text: "#1e40af", - border: "#93c5fd", - }, - pending: { - bg: "#fef3c7", - text: "#92400e", - border: "#fde68a", - }, - rejected: { - bg: "#fee2e2", - text: "#991b1b", - border: "#fca5a5", - }, - } - - const statusConfig = statusColors[status] || statusColors.pending - const statusLabel = getStatusDisplayName(status) - - const mainIconUrl = typeof iconData.data.base === "string" && iconData.data.base.startsWith("http") ? iconData.data.base : null - - let iconDataBuffer: Buffer | null = null - if (mainIconUrl) { - try { - const response = await fetch(mainIconUrl) - if (response.ok) { - const arrayBuffer = await response.arrayBuffer() - iconDataBuffer = Buffer.from(arrayBuffer) - } - } catch (error) { - console.error(`Failed to fetch icon image for ${icon}:`, error) - } - } - - const iconUrl = iconDataBuffer - ? `data:image/png;base64,${iconDataBuffer.toString("base64")}` - : `https://placehold.co/600x400?text=${formattedIconName}`; - - return new ImageResponse( -
- {/* Status Badge */} -
- {statusLabel} -
-
-
- -
-
-
- {formattedIconName} -
- -
-
- Download {formattedIconName} icon (Community) -
- -
- Amongst {totalIcons} other community-submitted icons -
- -
-
- COMMUNITY -
-
-
-
- -
-
-
- dashboardicons.com -
-
-
, - { - ...size, - }, - ); -} diff --git a/web/src/app/community/[icon]/page.tsx b/web/src/app/community/[icon]/page.tsx index 246225fe..0b388171 100644 --- a/web/src/app/community/[icon]/page.tsx +++ b/web/src/app/community/[icon]/page.tsx @@ -165,6 +165,7 @@ export default async function CommunityIconPage({ params }: { params: Promise<{ <>