add unknown server and unknown player and impl player embed
All checks were successful
Deploy App / docker (ubuntu-latest) (push) Successful in 1m12s
All checks were successful
Deploy App / docker (ubuntu-latest) (push) Successful in 1m12s
This commit is contained in:
parent
59acc3a7db
commit
b33ed9378b
@ -14,7 +14,7 @@
|
|||||||
"class-variance-authority": "^0.7.0",
|
"class-variance-authority": "^0.7.0",
|
||||||
"clsx": "^2.1.0",
|
"clsx": "^2.1.0",
|
||||||
"lucide-react": "^0.368.0",
|
"lucide-react": "^0.368.0",
|
||||||
"mcutils-library": "^1.1.0",
|
"mcutils-library": "^1.1.1",
|
||||||
"next": "14.2.1",
|
"next": "14.2.1",
|
||||||
"next-themes": "^0.3.0",
|
"next-themes": "^0.3.0",
|
||||||
"react": "^18",
|
"react": "^18",
|
||||||
|
8
pnpm-lock.yaml
generated
8
pnpm-lock.yaml
generated
@ -21,8 +21,8 @@ dependencies:
|
|||||||
specifier: ^0.368.0
|
specifier: ^0.368.0
|
||||||
version: 0.368.0(react@18.2.0)
|
version: 0.368.0(react@18.2.0)
|
||||||
mcutils-library:
|
mcutils-library:
|
||||||
specifier: ^1.1.0
|
specifier: ^1.1.1
|
||||||
version: 1.1.0(@babel/core@7.24.4)(@types/node@20.12.7)
|
version: 1.1.1(@babel/core@7.24.4)(@types/node@20.12.7)
|
||||||
next:
|
next:
|
||||||
specifier: 14.2.1
|
specifier: 14.2.1
|
||||||
version: 14.2.1(@babel/core@7.24.4)(react-dom@18.2.0)(react@18.2.0)
|
version: 14.2.1(@babel/core@7.24.4)(react-dom@18.2.0)(react@18.2.0)
|
||||||
@ -3516,8 +3516,8 @@ packages:
|
|||||||
tmpl: 1.0.5
|
tmpl: 1.0.5
|
||||||
dev: false
|
dev: false
|
||||||
|
|
||||||
/mcutils-library@1.1.0(@babel/core@7.24.4)(@types/node@20.12.7):
|
/mcutils-library@1.1.1(@babel/core@7.24.4)(@types/node@20.12.7):
|
||||||
resolution: {integrity: sha512-G3qeRybVMUlfd36+ioqG5YsMgX+zDy3aeLk0qRqkjZ3zXvOgZ1OhjOFP7lEUcsMQ5nmcgwCCBqzk/UpAGiiDXg==}
|
resolution: {integrity: sha512-OxZfC5KbqIYWcWJK+bikaCD9peCM3acgFP0e3OLLb+STU2czyaLMIt2sQ3yrqoS81emfKpaScQ5qK4nSTBGI1Q==}
|
||||||
dependencies:
|
dependencies:
|
||||||
axios: 1.6.8
|
axios: 1.6.8
|
||||||
jest: 29.7.0(@types/node@20.12.7)(ts-node@10.9.2)
|
jest: 29.7.0(@types/node@20.12.7)(ts-node@10.9.2)
|
||||||
|
@ -1,13 +1,46 @@
|
|||||||
|
import { embedFallback } from "@/common/embed-fallback";
|
||||||
import { NotFound } from "@/components/not-found";
|
import { NotFound } from "@/components/not-found";
|
||||||
import { Card } from "@/components/ui/card";
|
import { Card } from "@/components/ui/card";
|
||||||
import { getPlayer } from "mcutils-library";
|
import { getPlayer } from "mcutils-library";
|
||||||
import { Player } from "mcutils-library/dist/types/player/player";
|
import { Player } from "mcutils-library/dist/types/player/player";
|
||||||
import { Metadata } from "next";
|
import { Metadata } from "next";
|
||||||
|
|
||||||
export const metadata: Metadata = {
|
type Params = {
|
||||||
title: "Lookup Player",
|
params: {
|
||||||
|
id: string;
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export async function generateMetadata({ params: { id } }: Params): Promise<Metadata> {
|
||||||
|
const player = await getData(id);
|
||||||
|
if (!player) {
|
||||||
|
return embedFallback({ title: "Unknown Player", description: "Player not found" });
|
||||||
|
}
|
||||||
|
|
||||||
|
const { username, uniqueId, skin } = player;
|
||||||
|
const headPartUrl = skin.parts.head;
|
||||||
|
|
||||||
|
const description = `
|
||||||
|
Username: ${username}
|
||||||
|
UUID: ${uniqueId}`;
|
||||||
|
|
||||||
|
return {
|
||||||
|
title: `${username}`,
|
||||||
|
openGraph: {
|
||||||
|
title: `${username}`,
|
||||||
|
description: description,
|
||||||
|
images: [
|
||||||
|
{
|
||||||
|
url: headPartUrl,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
twitter: {
|
||||||
|
card: "summary",
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
async function getData(id: string): Promise<Player | null> {
|
async function getData(id: string): Promise<Player | null> {
|
||||||
try {
|
try {
|
||||||
const cachedPlayer = await getPlayer(id);
|
const cachedPlayer = await getPlayer(id);
|
||||||
@ -17,12 +50,6 @@ async function getData(id: string): Promise<Player | null> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
type Params = {
|
|
||||||
params: {
|
|
||||||
id: string;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
export default async function Page({ params }: Params) {
|
export default async function Page({ params }: Params) {
|
||||||
const player = await getData(params.id);
|
const player = await getData(params.id);
|
||||||
|
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
import { embedFallback } from "@/common/embed-fallback";
|
||||||
import { capitalizeFirstLetter } from "@/common/string-utils";
|
import { capitalizeFirstLetter } from "@/common/string-utils";
|
||||||
import { LookupServer } from "@/components/lookup-server";
|
import { LookupServer } from "@/components/lookup-server";
|
||||||
import { NotFound } from "@/components/not-found";
|
import { NotFound } from "@/components/not-found";
|
||||||
@ -18,15 +19,15 @@ type Params = {
|
|||||||
export async function generateMetadata({ params: { platform, hostname } }: Params): Promise<Metadata> {
|
export async function generateMetadata({ params: { platform, hostname } }: Params): Promise<Metadata> {
|
||||||
const server = await getData(platform, hostname);
|
const server = await getData(platform, hostname);
|
||||||
if (!server) {
|
if (!server) {
|
||||||
return {
|
return embedFallback({ title: "Unknown Server", description: "Server not found" });
|
||||||
title: "Unknown Server",
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const { hostname: serverHostname, players } = server;
|
const { hostname: serverHostname, players } = server;
|
||||||
let favicon = null;
|
|
||||||
|
let favicon = null; // Server favicon
|
||||||
|
|
||||||
if (platform === ServerPlatform.Java) {
|
if (platform === ServerPlatform.Java) {
|
||||||
|
// Java specific
|
||||||
const javaServer = server as JavaMinecraftServer;
|
const javaServer = server as JavaMinecraftServer;
|
||||||
favicon = javaServer.favicon && javaServer.favicon.url;
|
favicon = javaServer.favicon && javaServer.favicon.url;
|
||||||
}
|
}
|
||||||
|
23
src/common/embed-fallback.ts
Normal file
23
src/common/embed-fallback.ts
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
import { Metadata } from "next";
|
||||||
|
|
||||||
|
type Fallback = {
|
||||||
|
title: string;
|
||||||
|
description: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generates metadata for a fallback embed.
|
||||||
|
*
|
||||||
|
* @param title the title of the embed
|
||||||
|
* @param description the description of the embed
|
||||||
|
* @returns the metadata for the embed
|
||||||
|
*/
|
||||||
|
export function embedFallback({ title, description }: Fallback): Metadata {
|
||||||
|
return {
|
||||||
|
title: `${title}`,
|
||||||
|
openGraph: {
|
||||||
|
title: `${title}`,
|
||||||
|
description: description,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user