/* eslint-disable @next/next/no-img-element */ import { ImageResponse } from "next/og"; import { getPublicTeamExport } from "@/lib/guides/queries"; const anuphanFont = fetch( "https://raw.githubusercontent.com/google/fonts/main/ofl/anuphan/Anuphan%5Bwght%5D.ttf", ) .then((response) => (response.ok ? response.arrayBuffer() : null)) .catch(() => null); function amount(value: number): string { return new Intl.NumberFormat("en-US", { maximumFractionDigits: 0 }).format(value); } export async function GET( _request: Request, context: RouteContext<"/api/teams/[teamId]/image">, ) { const { teamId } = await context.params; const team = await getPublicTeamExport(teamId); if (!team) return new Response("Team not found", { status: 404 }); const total = team.members.reduce( (sum, member) => sum + Number(member.damage), 0, ); const seconds = Number(team.rotationSeconds); const dps = seconds > 0 ? total / seconds : 0; const font = await anuphanFont; return new ImageResponse(
{team.guideName}
{team.title} ยท {seconds.toLocaleString(undefined, { maximumFractionDigits: 2 })}s rotation
Damage Share
{team.members.map((member) => { const damage = Number(member.damage); const percent = total > 0 ? (damage / total) * 100 : 0; return (
{member.character.name}
{amount(damage)}
{percent.toFixed(1)}%
); })}
DPS: {amount(dps)} | DPR: {amount(total)}
{team.combo}
BUZZ SHEET
, { width: 550, height: 776, fonts: font ? [{ name: "Anuphan", data: font, weight: 400, style: "normal" }] : undefined, headers: { "Cache-Control": "no-store", "Content-Disposition": `attachment; filename="buzz-team-${team.id}.png"`, }, }, ); }