add server previews
This commit is contained in:
parent
436c9be3e5
commit
321db2fb3d
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "mcutils-library",
|
||||
"version": "1.2.6",
|
||||
"version": "1.3.0",
|
||||
"description": "",
|
||||
"main": "dist/index.js",
|
||||
"types": "dist/index.d.ts",
|
||||
|
@ -5,6 +5,7 @@ import {ServerPlatform} from "../types/server/platform";
|
||||
|
||||
const serverEndpoint = API_ENDPOINT + "/server/{platform}/{hostname}";
|
||||
const serverIconEndpoint = API_ENDPOINT + "/server/icon/{hostname}";
|
||||
const serverPreviewEndpoint = API_ENDPOINT + "/server/{platform}/preview/{hostname}";
|
||||
const blockedServerEndpoint = API_ENDPOINT + "/server/blocked/{hostname}";
|
||||
|
||||
/**
|
||||
@ -38,6 +39,19 @@ export async function getServerIcon(hostname: string, port?: 25565): Promise<Buf
|
||||
return WebRequest.get<Buffer>(serverIconEndpoint.replace("{hostname}", ip));
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the preview of a Minecraft server's MOTD.
|
||||
*
|
||||
* @param platform the platform of the server
|
||||
* @param hostname the hostname of the server
|
||||
* @param port the port of the server
|
||||
* @returns the server icon, or null if the server does not have an icon
|
||||
*/
|
||||
export async function getServerPreview(platform: ServerPlatform, hostname: string, port?: 25565): Promise<Buffer> {
|
||||
const ip = port ? `${hostname}:${port}` : hostname;
|
||||
return WebRequest.get<Buffer>(serverPreviewEndpoint.replace("{platform}", platform).replace("{hostname}", ip));
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the Mojang blocked status of a Minecraft server.
|
||||
*
|
||||
|
@ -24,6 +24,7 @@ test("ensureGetPlayerSkinPartSuccess", async () => {
|
||||
// Test each skin part
|
||||
for (const part in skinParts) {
|
||||
const partBuffer = await getPlayerSkinPart(part, player.uniqueId);
|
||||
|
||||
expect(partBuffer).toBeDefined();
|
||||
expect(partBuffer.byteLength).toBeGreaterThan(0);
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
import {getBlockedStatus, getServer, getServerIcon, ServerPlatform} from "../dist";
|
||||
import {getBlockedStatus, getServer, getServerIcon, getServerPreview, ServerPlatform} from "../dist";
|
||||
|
||||
test("ensureGetServerLookupSuccess", async () => {
|
||||
const server = await getServer(ServerPlatform.Java, "mc.hypixel.net");
|
||||
@ -9,6 +9,7 @@ test("ensureGetServerLookupSuccess", async () => {
|
||||
|
||||
test("ensureGetServerIconSuccess", async () => {
|
||||
const icon = await getServerIcon("mc.hypixel.net");
|
||||
|
||||
expect(icon).toBeDefined();
|
||||
expect(icon.byteLength).toBeGreaterThan(0); // The server has an icon
|
||||
});
|
||||
@ -19,3 +20,10 @@ test("ensureGetServerBlockedStatusSuccess", async () => {
|
||||
|
||||
expect(blocked).toBe(false); // The server is not blocked
|
||||
});
|
||||
|
||||
test("ensureGetServerPreviewSuccess", async () => {
|
||||
const preview = await getServerPreview(ServerPlatform.Java, "mc.hypixel.net");
|
||||
|
||||
expect(preview).toBeDefined();
|
||||
expect(preview.byteLength).toBeGreaterThan(0); // The server has a preview
|
||||
});
|
Loading…
x
Reference in New Issue
Block a user