From bf5f2edb158328431b23f66cf69949252f1c0e2b Mon Sep 17 00:00:00 2001 From: celine Date: Thu, 04 Dec 2025 22:00:32 +0000 Subject: [PATCH] add generic pub icon if user did not specify one, adjust styling to be --- components/AtMentionLink.tsx | 6 +++--- app/api/pub_icon/route.ts | 32 ++++++++++++++++++++++++++++---- 2 file(s) changed, 31 insertion(s)(+), 7 deletion(s)(-) diff --git a/components/AtMentionLink.tsx b/components/AtMentionLink.tsx --- a/components/AtMentionLink.tsx +++ b/components/AtMentionLink.tsx @@ -24,10 +24,10 @@ isPublication || isDocument ? ( ) : null; diff --git a/app/api/pub_icon/route.ts b/app/api/pub_icon/route.ts --- a/app/api/pub_icon/route.ts +++ b/app/api/pub_icon/route.ts @@ -10,8 +10,11 @@ export const runtime = "nodejs"; export async function GET(req: NextRequest) { + const searchParams = req.nextUrl.searchParams; + const bgColor = searchParams.get("bg") || "#0000E1"; + const fgColor = searchParams.get("fg") || "#FFFFFF"; + try { - const searchParams = req.nextUrl.searchParams; const at_uri = searchParams.get("at_uri"); if (!at_uri) { @@ -43,7 +46,8 @@ } publicationUri = docInPub.publication; - publicationRecord = docInPub.publications.record as PubLeafletPublication.Record; + publicationRecord = docInPub.publications + .record as PubLeafletPublication.Record; } else if (uri.collection === "pub.leaflet.publication") { // Query the publications table directly const { data: publication } = await supabaseServerClient @@ -65,14 +69,34 @@ // Check if the publication has an icon if (!publicationRecord?.icon) { - return new NextResponse(null, { status: 404 }); + // Generate a placeholder with the first letter of the publication name + const firstLetter = (publicationRecord?.name || "?") + .slice(0, 1) + .toUpperCase(); + + // Create a simple SVG placeholder with theme colors + const svg = ` + + ${firstLetter} +`; + + return new NextResponse(svg, { + headers: { + "Content-Type": "image/svg+xml", + "Cache-Control": + "public, max-age=3600, s-maxage=3600, stale-while-revalidate=2592000", + "CDN-Cache-Control": "s-maxage=3600, stale-while-revalidate=2592000", + }, + }); } // Parse the publication URI to get the DID const pubUri = new AtUri(publicationUri); // Get the CID from the icon blob - const cid = (publicationRecord.icon.ref as unknown as { $link: string })["$link"]; + const cid = (publicationRecord.icon.ref as unknown as { $link: string })[ + "$link" + ]; // Fetch the blob from the PDS const identity = await idResolver.did.resolve(pubUri.host); -- tangled.sh