import { ImageResponse } from "@vercel/og"; import { scoresaberService } from "@ssr/common/service/impl/scoresaber"; import React from "react"; import { formatNumberWithCommas, formatPp } from "@ssr/common/utils/number-utils"; import { getDifficultyFromScoreSaberDifficulty } from "website/src/common/scoresaber-utils"; export class ImageService { /** * Generates the OpenGraph image for the player * * @param id the player's id */ public static async generatePlayerImage(id: string) { const player = await scoresaberService.lookupPlayer(id); if (player == undefined) { return undefined; } return new ImageResponse( (
Player's Avatar

{player.name}

{formatPp(player.pp)}pp

#{formatNumberWithCommas(player.rank)}

{/* eslint-disable-next-line @next/next/no-img-element */} Player's Country

#{formatNumberWithCommas(player.countryRank)}

), { width: 1200, height: 630, emoji: "twemoji", } ); } /** * Generates the OpenGraph image for the player * * @param id the player's id */ public static async generateLeaderboardImage(id: string) { const leaderboard = await scoresaberService.lookupLeaderboard(id); if (leaderboard == undefined) { return undefined; } const ranked = leaderboard.stars > 0; return new ImageResponse( (
Player's Avatar

{leaderboard.songName} {leaderboard.songSubName}

{ranked && (

{leaderboard.stars}

)}

{getDifficultyFromScoreSaberDifficulty(leaderboard.difficulty.difficulty)}

Mapped by {leaderboard.levelAuthorName}

), { width: 1200, height: 630, emoji: "twemoji", } ); } }