import type { Metadata } from "next"; import { notFound } from "next/navigation"; import { ContentCard, EmptyState, OnlineBadge, StatBlock } from "@/components/public/ui"; import { auth } from "@/lib/auth"; import { avatarImageUrl } from "@/lib/format"; import { prisma } from "@/lib/prisma"; import { siteSettings } from "@/lib/services/site-settings"; import { postGuestbook } from "@/actions/guestbook"; export const dynamic = "force-dynamic"; export async function generateMetadata({ params, }: { params: Promise<{ username: string }>; }): Promise { const { username } = await params; const user = await prisma.user .findUnique({ where: { username }, select: { username: true, motto: true } }) .catch(() => null); if (!user) return { title: "Profile" }; return { title: user.username, description: user.motto || `${user.username}'s profile` }; } // Canonical Habbo badge image CDN. Badge codes (e.g. "ADM") map to a .gif here. const BADGE_IMG_BASE = "https://images.habbo.com/c_images/album1584"; function formatTimestamp(ts: number | null | undefined): string { if (!ts) return ""; return new Date(ts * 1000).toISOString().slice(0, 10); } function formatDate(d: Date | null | undefined): string { return d ? d.toISOString().slice(0, 10) : ""; } export default async function ProfilePage({ params, }: { params: Promise<{ username: string }>; }) { const { username } = await params; const [user, imagerBase, session] = await Promise.all([ prisma.user.findUnique({ where: { username }, select: { id: true, username: true, motto: true, look: true, rank: true, credits: true, online: true, accountCreated: true, }, }), siteSettings.get("habbo_imaging_url", "https://www.habbo.com/habbo-imaging/avatarimage"), auth(), ]); if (!user) notFound(); const avatar = avatarImageUrl(imagerBase ?? "", user.look, { size: "l" }); const registered = new Date(user.accountCreated * 1000).toISOString().slice(0, 10); const isLoggedIn = Boolean(session?.user?.id); // Profile sub-sections. Each query is isolated so a DB hiccup degrades that // single section to empty rather than 500-ing the whole profile. const badges = await prisma.usersBadges .findMany({ where: { userId: user.id }, orderBy: { slotId: "asc" }, }) .catch(() => []); const photos = await prisma.cameraWeb .findMany({ where: { userId: user.id }, orderBy: { timestamp: "desc" }, take: 6, }) .catch(() => []); const guestbook = await prisma.websiteUserGuestbooks .findMany({ where: { profileId: user.id }, orderBy: { createdAt: "desc" }, take: 30, }) .catch(() => []); // Resolve author usernames/looks for the guestbook entries in one query. const authorIds = Array.from(new Set(guestbook.map((g) => g.userId))); const authors = authorIds.length ? await prisma.user .findMany({ where: { id: { in: authorIds } }, select: { id: true, username: true, look: true }, }) .catch(() => []) : []; const authorById = new Map(authors.map((a) => [a.id, a])); return (
{/* ── Profile header ───────────────────────────────────── */}
{/* eslint-disable-next-line @next/next/no-img-element */} {`${user.username}

{user.username}

{user.motto || No motto}

{/* ── Badges ───────────────────────────────────────────── */} {badges.length === 0 ? ( No badges yet. ) : (
{badges.map((b) => ( /* eslint-disable-next-line @next/next/no-img-element */ {b.badgeCode} ))}
)}
{/* ── Photos ───────────────────────────────────────────── */} {photos.length === 0 ? ( No photos yet. ) : (
{photos.map((p) => (
{/* eslint-disable-next-line @next/next/no-img-element */} {`Photo

{formatTimestamp(p.timestamp)}

))}
)}
{/* ── Guestbook ────────────────────────────────────────── */} {isLoggedIn ? (
{/* Profile owner id drives the write target; the author is taken from the session inside the action, never from this form. */}