pterowrap
Version:
A node.js wrapper for Pterodactyl API
113 lines (112 loc) • 4.75 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/client/server/DatabaseManager"));
const BackupManager_1 = __importDefault(require("../../managers/client/server/BackupManager"));
const FileManager_1 = __importDefault(require("../../managers/client/server/FileManager"));
const NetworkManager_1 = __importDefault(require("../../managers/client/server/NetworkManager"));
const ScheduleManager_1 = __importDefault(require("../../managers/client/server/ScheduleManager"));
const SubuserManager_1 = __importDefault(require("../../managers/client/server/SubuserManager"));
const VariableManager_1 = __importDefault(require("../../managers/client/server/VariableManager"));
class Server {
constructor(_client, data) {
this._client = _client;
const attributes = data.attributes;
this.server_owner = attributes.server_owner;
this.identifier = attributes.identifier;
this.internal_id = attributes.internal_id;
this.uuid = attributes.uuid;
this.name = attributes.name;
this.description = attributes.description;
this.node = attributes.node;
this.sftp_details = attributes.sftp_details;
this.invocation = attributes.invocation;
this.is_suspended = attributes.is_suspended;
this.is_installing = attributes.is_installing;
this.is_transferring = attributes.is_transferring;
this.limits = attributes.limits;
this.feature_limits = attributes.feature_limits;
this.relationships = attributes.relationships ? attributes.relationships : {};
this.raw = attributes;
this.databases = new DatabaseManager_1.default(this._client, this);
this.files = new FileManager_1.default(this._client, this);
this.schedules = new ScheduleManager_1.default(this._client, this);
this.networks = new NetworkManager_1.default(this._client, this);
this.subusers = new SubuserManager_1.default(this._client, this);
this.backups = new BackupManager_1.default(this._client, this);
this.variables = new VariableManager_1.default(this._client, this);
}
retrieveWebsocketCredentials() {
return new Promise(async (resolve, reject) => {
try {
resolve((await this._client.call({ endpoint: `servers/${this.identifier}/websocket` })).data);
}
catch (e) {
reject(e);
}
});
}
retireveResourceUsage() {
return new Promise(async (resolve, reject) => {
try {
resolve((await this._client.call({ endpoint: `servers/${this.identifier}/resources` })).attributes);
}
catch (e) {
reject(e);
}
});
}
retrieveStartupData() {
return new Promise(async (resolve, reject) => {
try {
resolve((await this._client.call({ endpoint: `servers/${this.identifier}/startup` })).meta);
}
catch (e) {
reject(e);
}
});
}
sendCommand(command) {
return new Promise(async (resolve, reject) => {
try {
resolve(await this._client.call({ endpoint: `servers/${this.identifier}/command`, method: "POST", body: { command } }));
}
catch (e) {
reject(e);
}
});
}
sendPowerSignal(signal) {
return new Promise(async (resolve, reject) => {
try {
resolve(await this._client.call({ endpoint: `servers/${this.identifier}/power`, method: "POST", body: { signal } }));
}
catch (e) {
reject(e);
}
});
}
rename(name) {
return new Promise(async (resolve, reject) => {
try {
resolve(await this._client.call({ endpoint: `servers/${this.identifier}/settings/rename`, method: "POST", body: { name } }));
}
catch (e) {
reject(e);
}
});
}
reinstall() {
return new Promise(async (resolve, reject) => {
try {
resolve(await this._client.call({ endpoint: `servers/${this.identifier}/settings/reinstall`, method: "POST" }));
}
catch (e) {
reject(e);
}
});
}
}
exports.default = Server;