Compare commits
4 Commits
1277644bcb
...
3b9cf6f818
Author | SHA1 | Date | |
---|---|---|---|
3b9cf6f818 | |||
cacf1dc4cc | |||
a51528616d | |||
9f1ce626df |
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "restfulmc-lib",
|
"name": "restfulmc-lib",
|
||||||
"version": "1.0.2",
|
"version": "1.0.3",
|
||||||
"author": "Braydon (Rainnny) <braydonrainnny@gmail.com>",
|
"author": "Braydon (Rainnny) <braydonrainnny@gmail.com>",
|
||||||
"description": "A simple, yet useful RESTful API for Minecraft utilizing Springboot.",
|
"description": "A simple, yet useful RESTful API for Minecraft utilizing Springboot.",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
|
6
JS-SDK/src/index.d.ts
vendored
6
JS-SDK/src/index.d.ts
vendored
@ -1,6 +0,0 @@
|
|||||||
export * from "./types/generic";
|
|
||||||
export * from "./types/mojang";
|
|
||||||
export * from "./types/player";
|
|
||||||
export * from "./types/server/bedrock-server";
|
|
||||||
export * from "./types/server/java-server";
|
|
||||||
export * from "./types/server/server";
|
|
@ -1 +1,7 @@
|
|||||||
export * from "@/lib/restfulmc";
|
export * from "@/lib/restfulmc";
|
||||||
|
export * from "@/types/error";
|
||||||
|
export * from "@/types/mojang";
|
||||||
|
export * from "@/types/player";
|
||||||
|
export * from "@/types/server/bedrock-server";
|
||||||
|
export * from "@/types/server/java-server";
|
||||||
|
export * from "@/types/server/server";
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
|
import { WebRequest } from "@/lib/webRequest";
|
||||||
import { MojangServerStatus } from "@/types/mojang";
|
import { MojangServerStatus } from "@/types/mojang";
|
||||||
import { CachedPlayer, SkinPart } from "@/types/player";
|
import { CachedPlayer, SkinPart } from "@/types/player";
|
||||||
import { CachedBedrockMinecraftServer } from "@/types/server/bedrock-server";
|
import { CachedBedrockMinecraftServer } from "@/types/server/bedrock-server";
|
||||||
import { CachedJavaMinecraftServer } from "@/types/server/java-server";
|
import { CachedJavaMinecraftServer } from "@/types/server/java-server";
|
||||||
import { WebRequest } from "@/lib/webRequest";
|
|
||||||
import { ServerPlatform } from "@/types/server/server";
|
import { ServerPlatform } from "@/types/server/server";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -61,9 +61,11 @@ export const getMinecraftServer = (
|
|||||||
* @returns the promised blocked status
|
* @returns the promised blocked status
|
||||||
*/
|
*/
|
||||||
export const isMojangBlocked = (hostname: string): Promise<boolean> =>
|
export const isMojangBlocked = (hostname: string): Promise<boolean> =>
|
||||||
new WebRequest(`/server/blocked/${hostname}`).execute<{
|
new WebRequest(`/server/blocked/${hostname}`)
|
||||||
blocked: boolean;
|
.execute<{
|
||||||
}>().then((res) => res.blocked);
|
blocked: boolean;
|
||||||
|
}>()
|
||||||
|
.then((res) => res.blocked);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the icon of the Java Minecraft
|
* Get the icon of the Java Minecraft
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { ErrorResponse } from "@/types/generic";
|
import { RestfulMCAPIError } from "@/types/error";
|
||||||
|
|
||||||
const API_ENDPOINT = "https://mc.rainnny.club"; // The API endpoint to use
|
const API_ENDPOINT = "https://mc.rainnny.club"; // The API endpoint to use
|
||||||
|
|
||||||
@ -36,7 +36,7 @@ export class WebRequest {
|
|||||||
if (response.ok) {
|
if (response.ok) {
|
||||||
resolve(json as T);
|
resolve(json as T);
|
||||||
} else {
|
} else {
|
||||||
reject(json as ErrorResponse); // The request failed
|
reject(json as RestfulMCAPIError); // The request failed
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Fallback to an array buffer
|
// Fallback to an array buffer
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
/**
|
/**
|
||||||
* A response representing an error.
|
* A response representing an error.
|
||||||
*/
|
*/
|
||||||
export type ErrorResponse = {
|
export type RestfulMCAPIError = {
|
||||||
/**
|
/**
|
||||||
* The status of this error.
|
* The status of this error.
|
||||||
*/
|
*/
|
@ -1,5 +1,5 @@
|
|||||||
import { getPlayer, getSkinPart } from "@/index";
|
import { getPlayer, getSkinPart } from "@/index";
|
||||||
import { ErrorResponse } from "@/types/generic";
|
import { RestfulMCAPIError } from "@/types/error";
|
||||||
import { CachedPlayer, SkinPart } from "@/types/player";
|
import { CachedPlayer, SkinPart } from "@/types/player";
|
||||||
import { expect, test } from "bun:test";
|
import { expect, test } from "bun:test";
|
||||||
|
|
||||||
@ -20,7 +20,7 @@ test("ensurePlayerNotFound", async () => {
|
|||||||
try {
|
try {
|
||||||
await getPlayer("SDFSDFSDFSDFDDDG"); // Fetch the unknown player
|
await getPlayer("SDFSDFSDFSDFDDDG"); // Fetch the unknown player
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
expect((err as ErrorResponse).code).toBe(404);
|
expect((err as RestfulMCAPIError).code).toBe(404);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -32,7 +32,7 @@ test("ensureUsernameIsInvalid", async () => {
|
|||||||
try {
|
try {
|
||||||
await getPlayer("A"); // Fetch the invalid player
|
await getPlayer("A"); // Fetch the invalid player
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
expect((err as ErrorResponse).code).toBe(400);
|
expect((err as RestfulMCAPIError).code).toBe(400);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -3,7 +3,7 @@ import {
|
|||||||
getMinecraftServer,
|
getMinecraftServer,
|
||||||
isMojangBlocked,
|
isMojangBlocked,
|
||||||
} from "@/index";
|
} from "@/index";
|
||||||
import { ErrorResponse } from "@/types/generic";
|
import { RestfulMCAPIError } from "@/types/error";
|
||||||
import { CachedBedrockMinecraftServer } from "@/types/server/bedrock-server";
|
import { CachedBedrockMinecraftServer } from "@/types/server/bedrock-server";
|
||||||
import { CachedJavaMinecraftServer } from "@/types/server/java-server";
|
import { CachedJavaMinecraftServer } from "@/types/server/java-server";
|
||||||
import { ServerPlatform } from "@/types/server/server";
|
import { ServerPlatform } from "@/types/server/server";
|
||||||
@ -41,7 +41,7 @@ test("ensureUnknownHostname", async () => {
|
|||||||
try {
|
try {
|
||||||
await getMinecraftServer(ServerPlatform.JAVA, "invalid"); // Fetch the unknown server
|
await getMinecraftServer(ServerPlatform.JAVA, "invalid"); // Fetch the unknown server
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
expect((err as ErrorResponse).code).toBe(400);
|
expect((err as RestfulMCAPIError).code).toBe(400);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -53,7 +53,7 @@ test("ensureUnknownPort", async () => {
|
|||||||
try {
|
try {
|
||||||
await getMinecraftServer(ServerPlatform.JAVA, "hypixel.net:A"); // Fetch the invalid server
|
await getMinecraftServer(ServerPlatform.JAVA, "hypixel.net:A"); // Fetch the invalid server
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
expect((err as ErrorResponse).code).toBe(400);
|
expect((err as RestfulMCAPIError).code).toBe(400);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user