pterowrap
Version:
A node.js wrapper for Pterodactyl API
107 lines (106 loc) • 3.93 kB
JavaScript
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const DatabaseManager_1 = __importDefault(require("../../managers/application/DatabaseManager"));
class Server {
constructor(_client, data) {
this._client = _client;
const attributes = data.attributes;
this.id = attributes.id;
this.external_id = attributes.external_id;
this.uuid = attributes.uuid;
this.identifier = attributes.identifier;
this.name = attributes.name;
this.description = attributes.description;
this.suspended = attributes.suspended;
this.limits = attributes.limits;
this.feature_limits = attributes.feature_limits;
this.user = attributes.user;
this.node = attributes.node;
this.allocation = attributes.allocation;
this.nest = attributes.nest;
this.egg = attributes.egg;
this.container = attributes.container;
this.updated_at = attributes.updated_at;
this.created_at = attributes.created_at;
this.relationships = attributes.relationships ? attributes.relationships : {};
this.raw = attributes;
this.databases = new DatabaseManager_1.default(this._client, this);
}
updateDetails(params) {
return new Promise(async (resolve, reject) => {
try {
resolve(new Server(this._client, await this._client.call({ endpoint: `servers/${this.id}/details`, method: "PATCH", body: params })));
}
catch (e) {
reject(e);
}
});
}
updateBuild(params) {
return new Promise(async (resolve, reject) => {
try {
resolve(new Server(this._client, await this._client.call({ endpoint: `servers/${this.id}/build`, method: "PATCH", body: params })));
}
catch (e) {
reject(e);
}
});
}
updateStartup(params) {
return new Promise(async (resolve, reject) => {
try {
resolve(new Server(this._client, await this._client.call({ endpoint: `servers/${this.id}/startup`, method: "PATCH", body: params })));
}
catch (e) {
reject(e);
}
});
}
suspend() {
return new Promise(async (resolve, reject) => {
try {
resolve(await this._client.call({ endpoint: `servers/${this.id}/suspend`, method: "POST" }));
}
catch (e) {
reject(e);
}
});
}
unsuspend() {
return new Promise(async (resolve, reject) => {
try {
resolve(await this._client.call({ endpoint: `servers/${this.id}/unsuspend`, method: "POST" }));
}
catch (e) {
reject(e);
}
});
}
reinstall() {
return new Promise(async (resolve, reject) => {
try {
resolve(await this._client.call({ endpoint: `servers/${this.id}/reinstall`, method: "POST" }));
}
catch (e) {
reject(e);
}
});
}
delete(force = false) {
return new Promise(async (resolve, reject) => {
try {
if (!force)
resolve(await this._client.call({ endpoint: `servers/${this.id}`, method: "DELETE" }));
else
resolve(await this._client.call({ endpoint: `servers/${this.id}/force`, method: "DELETE" }));
}
catch (e) {
reject(e);
}
});
}
}
exports.default = Server;