From 52fea3da68bbdc4a1385db3ccf6c2f9eb04b7a15 Mon Sep 17 00:00:00 2001 From: Liam Date: Mon, 22 Apr 2024 20:15:56 +0100 Subject: [PATCH] use the server preview from the api in the server route for embeds --- package.json | 2 +- pnpm-lock.yaml | 2 +- .../server/[platform]/[[...hostname]]/page.tsx | 12 ++++-------- src/app/common/embed.ts | 13 +++++++++++-- 4 files changed, 17 insertions(+), 12 deletions(-) diff --git a/package.json b/package.json index e462c09..3c8ce64 100644 --- a/package.json +++ b/package.json @@ -33,7 +33,7 @@ "cmdk": "^1.0.0", "fuse.js": "^7.0.0", "lucide-react": "^0.372.0", - "mcutils-library": "^1.2.6", + "mcutils-library": "^1.3.1", "moment": "^2.30.1", "next": "14.2.2", "next-build-id": "^3.0.0", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 0ab81b1..bcaf0e3 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -81,7 +81,7 @@ dependencies: specifier: ^0.372.0 version: 0.372.0(react@18.2.0) mcutils-library: - specifier: ^1.2.6 + specifier: ^1.3.1 version: 1.3.1(@babel/core@7.24.4)(@types/node@20.12.7) moment: specifier: ^2.30.1 diff --git a/src/app/(pages)/server/[platform]/[[...hostname]]/page.tsx b/src/app/(pages)/server/[platform]/[[...hostname]]/page.tsx index 2e06c77..4994e59 100644 --- a/src/app/(pages)/server/[platform]/[[...hostname]]/page.tsx +++ b/src/app/(pages)/server/[platform]/[[...hostname]]/page.tsx @@ -82,18 +82,14 @@ export async function generateMetadata({ params: { platform, hostname } }: Param try { const server = await getServer(platform, hostname); - const { hostname: serverHostname, players } = server; - - const favicon = getFavicon(platform, server); - - let description = `There is ${formatNumber(players.online)}/${formatNumber(players.max)} players connected!\n\n`; - description += "Click to view more information about the server."; + const { hostname: serverHostname } = server; return generateEmbed({ title: `${serverHostname} ${capitalizeFirstLetter(platform)} Server`, embedTitle: `${capitalizeFirstLetter(platform)} Server: ${serverHostname}`, - description: description, - image: favicon, + description: "Click to view more information about the server.", + image: `${config.apiEndpoint}/server/${platform}/preview/${serverHostname}`, + cardType: "summary_large_image", }); } catch (err) { // An error occurred diff --git a/src/app/common/embed.ts b/src/app/common/embed.ts index 77350e4..9fb9267 100644 --- a/src/app/common/embed.ts +++ b/src/app/common/embed.ts @@ -20,6 +20,11 @@ type Embed = { * The image to show as the thumbmail. */ image?: string; + + /** + * The type of the card. + */ + cardType?: "summary" | "summary_large_image"; }; /** @@ -29,13 +34,17 @@ type Embed = { * @param embedTitle the title of the embed * @param description the description of the embed * @param image the image to show as the thumbmail + * @param cardType the type of the card * @returns the metadata for the embed */ -export function generateEmbed({ title, embedTitle, description, image }: Embed): Metadata { +export function generateEmbed({ title, embedTitle, description, image, cardType }: Embed): Metadata { // Fall back to the title if (!embedTitle) { embedTitle = title; } + if (!cardType) { + cardType = "summary"; + } const metadata: Metadata = { title: `${title}`, @@ -44,7 +53,7 @@ export function generateEmbed({ title, embedTitle, description, image }: Embed): description: description, }, twitter: { - card: "summary", + card: cardType, }, };