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",
|
||||
"clsx": "^2.1.0",
|
||||
"lucide-react": "^0.368.0",
|
||||
"mcutils-library": "^1.1.0",
|
||||
"mcutils-library": "^1.1.1",
|
||||
"next": "14.2.1",
|
||||
"next-themes": "^0.3.0",
|
||||
"react": "^18",
|
||||
|
8
pnpm-lock.yaml
generated
8
pnpm-lock.yaml
generated
@ -21,8 +21,8 @@ dependencies:
|
||||
specifier: ^0.368.0
|
||||
version: 0.368.0(react@18.2.0)
|
||||
mcutils-library:
|
||||
specifier: ^1.1.0
|
||||
version: 1.1.0(@babel/core@7.24.4)(@types/node@20.12.7)
|
||||
specifier: ^1.1.1
|
||||
version: 1.1.1(@babel/core@7.24.4)(@types/node@20.12.7)
|
||||
next:
|
||||
specifier: 14.2.1
|
||||
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
|
||||
dev: false
|
||||
|
||||
/mcutils-library@1.1.0(@babel/core@7.24.4)(@types/node@20.12.7):
|
||||
resolution: {integrity: sha512-G3qeRybVMUlfd36+ioqG5YsMgX+zDy3aeLk0qRqkjZ3zXvOgZ1OhjOFP7lEUcsMQ5nmcgwCCBqzk/UpAGiiDXg==}
|
||||
/mcutils-library@1.1.1(@babel/core@7.24.4)(@types/node@20.12.7):
|
||||
resolution: {integrity: sha512-OxZfC5KbqIYWcWJK+bikaCD9peCM3acgFP0e3OLLb+STU2czyaLMIt2sQ3yrqoS81emfKpaScQ5qK4nSTBGI1Q==}
|
||||
dependencies:
|
||||
axios: 1.6.8
|
||||
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 { Card } from "@/components/ui/card";
|
||||
import { getPlayer } from "mcutils-library";
|
||||
import { Player } from "mcutils-library/dist/types/player/player";
|
||||
import { Metadata } from "next";
|
||||
|
||||
export const metadata: Metadata = {
|
||||
title: "Lookup Player",
|
||||
type Params = {
|
||||
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> {
|
||||
try {
|
||||
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) {
|
||||
const player = await getData(params.id);
|
||||
|
||||
|
@ -1,3 +1,4 @@
|
||||
import { embedFallback } from "@/common/embed-fallback";
|
||||
import { capitalizeFirstLetter } from "@/common/string-utils";
|
||||
import { LookupServer } from "@/components/lookup-server";
|
||||
import { NotFound } from "@/components/not-found";
|
||||
@ -18,15 +19,15 @@ type Params = {
|
||||
export async function generateMetadata({ params: { platform, hostname } }: Params): Promise<Metadata> {
|
||||
const server = await getData(platform, hostname);
|
||||
if (!server) {
|
||||
return {
|
||||
title: "Unknown Server",
|
||||
};
|
||||
return embedFallback({ title: "Unknown Server", description: "Server not found" });
|
||||
}
|
||||
|
||||
const { hostname: serverHostname, players } = server;
|
||||
let favicon = null;
|
||||
|
||||
let favicon = null; // Server favicon
|
||||
|
||||
if (platform === ServerPlatform.Java) {
|
||||
// Java specific
|
||||
const javaServer = server as JavaMinecraftServer;
|
||||
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…
x
Reference in New Issue
Block a user