diff --git a/web/src/app/community/[icon]/page.tsx b/web/src/app/community/[icon]/page.tsx index c86383c1..9a9a5bdf 100644 --- a/web/src/app/community/[icon]/page.tsx +++ b/web/src/app/community/[icon]/page.tsx @@ -2,7 +2,7 @@ import type { Metadata, ResolvingMetadata } from "next" import { notFound, permanentRedirect } from "next/navigation" import { IconDetails } from "@/components/icon-details" import { BASE_URL, WEB_URL } from "@/constants" -import { getAllIcons } from "@/lib/api" +import { getAllIcons, getAuthorData } from "@/lib/api" import { getCommunityGalleryRecord, getCommunitySubmissionByName, getCommunitySubmissions } from "@/lib/community" export const dynamicParams = true @@ -124,14 +124,64 @@ export default async function CommunityIconPage({ params }: { params: Promise<{ const allIcons = await getAllIcons() - const authorData = { - id: 0, - name: iconData.data.update.author.name || "Community", - login: iconData.data.update.author.name || "community", - avatar_url: "", - html_url: "", + const author = iconData.data.update.author as any + const githubId = author?.github_id + const authorMetaLogin = author?.login || author?.name + + let authorData: + | { + id: number | string + name?: string + login: string + avatar_url: string + html_url: string + } + | undefined + + if (githubId && /^\d+$/.test(String(githubId))) { + authorData = await getAuthorData(String(githubId), { login: authorMetaLogin, name: author?.name }) + } else if (authorMetaLogin && authorMetaLogin !== "community" && authorMetaLogin !== "Community") { + // Fallback: resolve by GitHub username if we don't have github_id in the community_gallery view. + // This avoids losing the GitHub link when PB doesn't expose github_id in the view. + try { + const headers: Record = {} + if (process.env.GITHUB_TOKEN) { + headers.Authorization = `Bearer ${process.env.GITHUB_TOKEN}` + } + const res = await fetch(`https://api.github.com/users/${encodeURIComponent(authorMetaLogin)}`, { headers }) + if (res.ok) { + const gh = await res.json() + authorData = { + id: gh?.id ?? 0, + name: gh?.name ?? authorMetaLogin, + login: gh?.login ?? authorMetaLogin, + avatar_url: gh?.avatar_url ?? "", + html_url: gh?.html_url ?? "", + } + } + } catch (err) { + console.log("[CommunityPage] GitHub username fallback failed:", { icon, login: authorMetaLogin, err }) + } } + if (!authorData) { + authorData = { + id: 0, + name: author?.name || "Community", + login: authorMetaLogin || "community", + avatar_url: "", + html_url: "", + } + } + console.log("[CommunityPage] resolved authorData:", { + icon, + id: authorData.id, + login: authorData.login, + html_url: authorData.html_url, + avatar_url: authorData.avatar_url, + }) + console.log(iconData.data) + const mainIconUrl = typeof iconData.data.base === "string" && iconData.data.base.startsWith("http") ? iconData.data.base diff --git a/web/src/lib/community.ts b/web/src/lib/community.ts index 153d71fb..eb732162 100644 --- a/web/src/lib/community.ts +++ b/web/src/lib/community.ts @@ -101,6 +101,8 @@ function transformGalleryToIcon(item: CommunityGallery): any { author: { id: 0, name: item.created_by || "Community", + login: item.created_by || undefined, + github_id: item.created_by_github_id, }, }, colors: colors, @@ -151,6 +153,11 @@ async function fetchCommunitySubmissionByName(name: string): Promise(`name="${name}"`) + console.log("[Community] Record author fields:", { + name, + created_by: record.created_by, + created_by_github_id: record.created_by_github_id, + }) const transformed = transformGalleryToIcon(record) console.log(`[Community] Fetched ${name}, colors:`, transformed.data.colors) return transformed diff --git a/web/src/lib/pb.ts b/web/src/lib/pb.ts index c095ce3e..1eaec554 100644 --- a/web/src/lib/pb.ts +++ b/web/src/lib/pb.ts @@ -47,6 +47,7 @@ export interface CommunityGallery { created_by: string approved_by?: string description?: string + created_by_github_id?: string status: "approved" | "rejected" | "pending" | "added_to_collection" assets: string[] admin_comment?: string diff --git a/web/src/types/icons.ts b/web/src/types/icons.ts index 6d86449b..203808fa 100644 --- a/web/src/types/icons.ts +++ b/web/src/types/icons.ts @@ -1,5 +1,6 @@ export type IconAuthor = { id: number | string + github_id?: string name?: string login?: string }