From bf5f2edb158328431b23f66cf69949252f1c0e2b Mon Sep 17 00:00:00 2001 From: celine Date: Thu, 4 Dec 2025 17:00:32 -0500 Subject: [PATCH] add generic pub icon if user did not specify one, adjust styling to be reflected in rendered version --- app/api/pub_icon/route.ts | 32 ++++++++++++++++++++++++++++---- components/AtMentionLink.tsx | 6 +++--- 2 files changed, 31 insertions(+), 7 deletions(-) diff --git a/app/api/pub_icon/route.ts b/app/api/pub_icon/route.ts index 30ccfbb5..16ecfb7d 100644 --- a/app/api/pub_icon/route.ts +++ b/app/api/pub_icon/route.ts @@ -10,8 +10,11 @@ const idResolver = new IdResolver(); 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 @@ export async function GET(req: NextRequest) { } 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 @@ export async function GET(req: NextRequest) { // 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); diff --git a/components/AtMentionLink.tsx b/components/AtMentionLink.tsx index 2df31919..ad7ee4ba 100644 --- a/components/AtMentionLink.tsx +++ b/components/AtMentionLink.tsx @@ -24,10 +24,10 @@ export function AtMentionLink({ isPublication || isDocument ? ( ) : null; -- 2.54.0