This commit is contained in:
parent
fb8ab8d7aa
commit
eb9ab2cd5b
13
src/index.ts
13
src/index.ts
@ -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";
|
||||
|
@ -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";
|
||||
|
||||
|
@ -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}";
|
||||
|
@ -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)
|
||||
);
|
||||
}
|
||||
|
10
src/types/cache/cachedMinecraftServer.ts
vendored
10
src/types/cache/cachedMinecraftServer.ts
vendored
@ -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;
|
||||
}
|
8
src/types/cache/cachedPlayer.ts
vendored
8
src/types/cache/cachedPlayer.ts
vendored
@ -1,8 +0,0 @@
|
||||
import { Player } from "../player/player";
|
||||
|
||||
export interface CachedPlayer extends Cache {
|
||||
/**
|
||||
* The cached player.
|
||||
*/
|
||||
player: Player;
|
||||
}
|
3
src/types/cache/cachedUsernameToUuid.ts
vendored
3
src/types/cache/cachedUsernameToUuid.ts
vendored
@ -1,3 +0,0 @@
|
||||
import { UsernameToUuid } from "../player/usernameToUuid";
|
||||
|
||||
export interface CachedUsernameToUuid extends Cache, UsernameToUuid {}
|
10
src/types/mojang/endpoint-status.ts
Normal file
10
src/types/mojang/endpoint-status.ts
Normal 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>;
|
||||
};
|
@ -1,4 +1,6 @@
|
||||
export type Player = {
|
||||
export interface CachedPlayer extends Cache, Player {}
|
||||
|
||||
type Player = {
|
||||
/**
|
||||
* The player's unique id.
|
||||
*/
|
||||
|
@ -1,4 +1,6 @@
|
||||
export type UsernameToUuid = {
|
||||
export interface CachedUsernameToUuid extends Cache, UsernameToUuid {}
|
||||
|
||||
type UsernameToUuid = {
|
||||
/**
|
||||
* The username of the player.
|
||||
*/
|
||||
|
@ -1,4 +1,6 @@
|
||||
import { MinecraftServer } from "./server";
|
||||
import { MinecraftServer } from "../server";
|
||||
|
||||
export interface CachedBedrockMinecraftServer extends Cache, BedrockMinecraftServer {}
|
||||
|
||||
export default interface BedrockMinecraftServer extends MinecraftServer {
|
||||
/**
|
@ -1,4 +1,6 @@
|
||||
import { MinecraftServer } from "./server";
|
||||
import { MinecraftServer } from "../server";
|
||||
|
||||
export interface CachedJavaMinecraftServer extends Cache, JavaMinecraftServer {}
|
||||
|
||||
export default interface JavaMinecraftServer extends MinecraftServer {
|
||||
/**
|
@ -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.
|
||||
*/
|
@ -3,7 +3,12 @@
|
||||
"module": "commonjs",
|
||||
"target": "ES2020",
|
||||
"declaration": true,
|
||||
"outDir": "./dist"
|
||||
"outDir": "./dist",
|
||||
"baseUrl": "./src",
|
||||
"paths": {
|
||||
"@/*": ["src/*"],
|
||||
"@types/*": ["src/types/*"]
|
||||
}
|
||||
},
|
||||
"include": ["src/**/*"]
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user