use the new api format
Some checks failed
Publish Package / build (push) Failing after 23s

This commit is contained in:
Lee 2024-04-17 16:35:39 +01:00
parent fb8ab8d7aa
commit eb9ab2cd5b
16 changed files with 52 additions and 43 deletions

View File

@ -1,5 +1,18 @@
export const API_ENDPOINT = "https://api.mcutils.xyz";
// Methods
export * from "./lib/mojang";
export * from "./lib/player";
export * from "./lib/server";
// Types
export * from "./types/cache";
export * from "./types/error";
export * from "./types/player/player";
export * from "./types/player/usernameToUuid";
export * from "./types/server/blocked-status";
export * from "./types/server/platform";
export * from "./types/server/platform/bedrock-server";
export * from "./types/server/platform/java-server";
export * from "./types/server/server";
export * from "./types/status";

View File

@ -1,6 +1,6 @@
import { CachedEndpointStatus } from "types/mojang/endpoint-status";
import { API_ENDPOINT } from "..";
import WebRequest from "../common/WebRequest";
import { CachedEndpointStatus } from "../types/cache/cachedEndpointStatus";
const endpointStatusEndpoint = API_ENDPOINT + "/mojang/status";

View File

@ -1,7 +1,5 @@
import { API_ENDPOINT } from "..";
import { API_ENDPOINT, CachedPlayer, CachedUsernameToUuid } from "..";
import WebRequest from "../common/WebRequest";
import { CachedPlayer } from "../types/cache/cachedPlayer";
import { CachedUsernameToUuid } from "../types/cache/cachedUsernameToUuid";
const playerEndpoint = API_ENDPOINT + "/player/{id}";
const playerUsernameToUuidEndpoint = API_ENDPOINT + "/player/uuid/{id}";

View File

@ -1,7 +1,6 @@
import { API_ENDPOINT } from "..";
import { API_ENDPOINT, CachedBedrockMinecraftServer, CachedJavaMinecraftServer } from "..";
import WebRequest from "../common/WebRequest";
import { CachedMinecraftServer } from "../types/cache/cachedMinecraftServer";
import { BlockedStatus } from "../types/server/blockedStatus";
import { BlockedStatus } from "../types/server/blocked-status";
import { ServerPlatform } from "../types/server/platform";
const serverEndpoint = API_ENDPOINT + "/server/{platform}/{hostname}";
@ -16,9 +15,13 @@ const blockedServerEndpoint = API_ENDPOINT + "/server/blocked/{hostname}";
* @param port the port of the server
* @returns the server information, or null if the server does not exist
*/
export function getServer(platform: ServerPlatform, hostname: string, port?: 25565): Promise<CachedMinecraftServer> {
export function getServer(
platform: ServerPlatform,
hostname: string,
port?: 25565
): Promise<CachedJavaMinecraftServer | CachedBedrockMinecraftServer> {
const ip = port ? `${hostname}:${port}` : hostname;
return WebRequest.get<CachedMinecraftServer>(
return WebRequest.get<CachedJavaMinecraftServer | CachedBedrockMinecraftServer>(
serverEndpoint.replace("{platform}", platform).replace("{hostname}", ip)
);
}

View File

@ -1,10 +0,0 @@
import BedrockMinecraftServer from "../server/bedrockServer";
import JavaMinecraftServer from "../server/javaServer";
import { Cache } from "./cache";
export interface CachedMinecraftServer extends Cache {
/**
* The cached server.
*/
server: JavaMinecraftServer | BedrockMinecraftServer;
}

View File

@ -1,8 +0,0 @@
import { Player } from "../player/player";
export interface CachedPlayer extends Cache {
/**
* The cached player.
*/
player: Player;
}

View File

@ -1,3 +0,0 @@
import { UsernameToUuid } from "../player/usernameToUuid";
export interface CachedUsernameToUuid extends Cache, UsernameToUuid {}

View File

@ -0,0 +1,10 @@
import { Status } from "../status";
export interface CachedEndpointStatus extends Cache, EndpointStatus {}
export type EndpointStatus = {
/**
* The cached endpoint status.
*/
endpoints: Record<string, Status>;
};

View File

@ -1,4 +1,6 @@
export type Player = {
export interface CachedPlayer extends Cache, Player {}
type Player = {
/**
* The player's unique id.
*/

View File

@ -1,4 +1,6 @@
export type UsernameToUuid = {
export interface CachedUsernameToUuid extends Cache, UsernameToUuid {}
type UsernameToUuid = {
/**
* The username of the player.
*/

View File

@ -1,4 +1,6 @@
import { MinecraftServer } from "./server";
import { MinecraftServer } from "../server";
export interface CachedBedrockMinecraftServer extends Cache, BedrockMinecraftServer {}
export default interface BedrockMinecraftServer extends MinecraftServer {
/**

View File

@ -1,4 +1,6 @@
import { MinecraftServer } from "./server";
import { MinecraftServer } from "../server";
export interface CachedJavaMinecraftServer extends Cache, JavaMinecraftServer {}
export default interface JavaMinecraftServer extends MinecraftServer {
/**

View File

@ -1,11 +1,4 @@
export interface CachedEndpointStatus extends Cache {
/**
* The cached endpoint status.
*/
endpoints: Record<string, Status>;
}
enum Status {
export enum Status {
/**
* The service is online and operational.
*/

View File

@ -3,7 +3,12 @@
"module": "commonjs",
"target": "ES2020",
"declaration": true,
"outDir": "./dist"
"outDir": "./dist",
"baseUrl": "./src",
"paths": {
"@/*": ["src/*"],
"@types/*": ["src/types/*"]
}
},
"include": ["src/**/*"]
}