jspteroapi
Version:
A pterodactyl v1 api using undici
103 lines (102 loc) • 3.86 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.serverMethods = void 0;
const Functions_1 = require("../../modules/Functions");
class serverMethods {
client;
constructor(client) {
this.client = client;
}
/**
* @internal
*/
getServers = async (options) => {
return this.client.request('GET', null, '', `/api/client${(0, Functions_1.makeOptions)(options)}`);
};
/**
* @param options - Include information about server relationships
* @param filter - Filter servers by specified field and value
* @returns An Array of servers
* @example
* ```ts
* const res = await client.getAllServers() // res = Server[]
* ```
* @example
* ```ts
* client.getAllServers().then((res) => console.log(res)) // res = Server[]
* ```
*/
getAllServers = async (options, filter, admin = false) => {
return await (0, Functions_1.paginate)(this.getServers.bind(this), {
includes: { ...options },
admin: admin,
filter: filter
});
};
/**
* @param serverId - ID of the server to get (In the settings tab of server/in link)
* @param options - Include information about server relationships
* @returns Server information
* @example
* ```ts
* const res = await client.getServerInfo('c2f5a3b6') // res = ServerAttributes
* ```
* @example
* ```ts
* client.getServerInfo('c2f5a3b6').then((res) => console.log(res)) // res = ServerAttributes
* ```
*/
getServerInfo = async (serverId, options) => {
return this.client.request('GET', null, 'attributes', `/api/client/servers/${serverId}${(0, Functions_1.makeOptions)({
includes: { ...options }
})}`);
};
/**
* @param serverId - ID of the server to get (In the settings tab of server/in link)
* @returns Server resource usage object
* @example
* ```ts
* const res = await client.getServerResources('c2f5a3b6') // res = ServerResources
* ```
* @example
* ```ts
* client.getServerResources('c2f5a3b6').then((res) => console.log(res)) // res = ServerResources
* ```
*/
getServerResources = async (serverId) => {
return this.client.request('GET', null, 'attributes', `/api/client/servers/${serverId}/resources`);
};
/**
* @param serverId - ID of the server to send a command to
* @param command - Command to send
* @returns If successful returns Successfuly sent the command!
* @example
* ```ts
* const res = await client.sendCommand('c2f5a3b6', 'give Linux123123 star') // res = Successfuly sent the command!
* ```
* @example
* ```ts
* client.sendCommand('c2f5a3b6', 'give Linux123123 star').then((res) => console.log(res)) // res = Successfuly sent the command!
* ```
*/
sendCommand = async (serverId, command) => {
return this.client.request('POST', { command: command }, 'Successfuly sent the command!', `/api/client/servers/${serverId}/command`);
};
/**
* @param serverId - ID of the server to send a command to
* @param action - start / stop / restart / kill
* @returns If successful returns Successfuly set power state!
* @example
* ```ts
* const res = await client.setPowerState('c2f5a3b6', 'start') // res = Successfuly set power state!
* ```
* @example
* ```ts
* client.setPowerState('c2f5a3b6', 'kill).then((res) => console.log(res)) // res = Successfuly set power state!
* ```
*/
setPowerState = async (serverId, action) => {
return this.client.request('POST', { signal: action }, 'Successfuly set power state!', `/api/client/servers/${serverId}/power`);
};
}
exports.serverMethods = serverMethods;