Server embeds
All checks were successful
Deploy Frontend / docker (17, 3.8.5) (push) Successful in 1m12s
All checks were successful
Deploy Frontend / docker (17, 3.8.5) (push) Successful in 1m12s
This commit is contained in:
parent
4494bd74ec
commit
a20b8008f4
@ -1,3 +1,4 @@
|
|||||||
|
import Embed from "@/components/embed";
|
||||||
import ServerResult from "@/components/server/server-result";
|
import ServerResult from "@/components/server/server-result";
|
||||||
import ServerSearch from "@/components/server/server-search";
|
import ServerSearch from "@/components/server/server-search";
|
||||||
import { Alert, AlertDescription, AlertTitle } from "@/components/ui/alert";
|
import { Alert, AlertDescription, AlertTitle } from "@/components/ui/alert";
|
||||||
@ -87,6 +88,41 @@ const ServerPage = async ({ params }: PageProps): Promise<ReactElement> => {
|
|||||||
export const generateMetadata = async ({
|
export const generateMetadata = async ({
|
||||||
params,
|
params,
|
||||||
}: PageProps): Promise<Metadata> => {
|
}: PageProps): Promise<Metadata> => {
|
||||||
|
const platform: string | undefined = params.slug?.[0]; // The platform to search for
|
||||||
|
const hostname: string | undefined = params.slug?.[1]; // The hostname of the server to search for
|
||||||
|
|
||||||
|
// Try and get the server to display
|
||||||
|
if (platform && hostname) {
|
||||||
|
try {
|
||||||
|
const serverPlatform: ServerPlatform = platform as ServerPlatform;
|
||||||
|
const server:
|
||||||
|
| CachedJavaMinecraftServer
|
||||||
|
| CachedBedrockMinecraftServer = await getMinecraftServer(
|
||||||
|
serverPlatform,
|
||||||
|
hostname
|
||||||
|
); // Get the server to embed
|
||||||
|
return Embed({
|
||||||
|
title: `${serverPlatform} Server: ${server.hostname}`,
|
||||||
|
description: `There are ${server.players.online}/${server.players.max} playing here!\n\nClick to view data about this server.`,
|
||||||
|
thumbnail: (server as CachedJavaMinecraftServer).favicon?.url,
|
||||||
|
});
|
||||||
|
} catch (err) {
|
||||||
|
const code: number = (err as RestfulMCAPIError).code; // Get the error status code
|
||||||
|
if (code === 400) {
|
||||||
|
return Embed({
|
||||||
|
title: "Invalid Hostname",
|
||||||
|
color: "#EB4034",
|
||||||
|
description: `The hostname ${hostname} is invalid.`,
|
||||||
|
});
|
||||||
|
} else if (code === 404) {
|
||||||
|
return Embed({
|
||||||
|
title: "Server Not Found",
|
||||||
|
color: "#EB4034",
|
||||||
|
description: `The server ${hostname} was not found.`,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
return {};
|
return {};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user