UNPKG

jspteroapi

Version:

A pterodactyl v1 api using undici

82 lines (81 loc) 3.45 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.databaseMethods = void 0; const Functions_1 = require("../../modules/Functions"); class databaseMethods { client; constructor(client) { this.client = client; } /** * @param serverId - ID of the server to get (In the settings tab of server/in link) * @param options - Include information about relationships * @returns Returns array of servers databases (Database[]) * @example * ```ts * const res = await client.getAllDatabases('c2f5a3b6') // res = Database[] * ``` * @example * ```ts * client.getAllDatabases('c2f5a3b6').then((res) => console.log(res)) // res = Database[] * ``` */ getAllDatabases = async (serverId, options) => { return this.client.request('GET', null, 'data', `/api/client/servers/${serverId}/databases${(0, Functions_1.makeOptions)({ includes: { ...options } })}`); }; /** * @param serverId - ID of the server to get (In the settings tab of server/in link) * @param databaseName - Database name * @param connectionsAllowedFrom - Connections allowed from * @param options - Include information about relationships * @returns Returns new database information (DatabaseAttributes) * @example * ```ts * const res = await client.createDatabase('c2f5a3b6', 'Information') // res = DatabaseAttributes * ``` * @example * ```ts * client.createDatabase('c2f5a3b6', 'info').then((res) => console.log(res)) // res = DatabaseAttributes * ``` */ createDatabase = async (serverId, databaseName, connectionsAllowedFrom = '%', options) => { return this.client.request('POST', { database: databaseName, remote: connectionsAllowedFrom }, 'attributes', `/api/client/servers/${serverId}/databases${(0, Functions_1.makeOptions)({ includes: { ...options } })}`); }; /** * @param serverId - ID of the server to get (In the settings tab of server/in link) * @param databaseId - Database id * @returns If successful returns Sucesfully deleted! * @example * ```ts * const res = await client.deleteDatabase('c2f5a3b6', 's5_info') // res = Sucesfully deleted! * ``` * @example * ```ts * client.deleteDatabase('c2f5a3b6', 's3_good').then((res) => console.log(res)) // res = Sucesfully deleted! * ``` */ deleteDatabase = (serverId, databaseId) => { return this.client.request('DELETE', null, 'Sucesfully deleted!', `/api/client/servers/${serverId}/databases/${databaseId}`); }; /** * @param serverId - ID of the server to get (In the settings tab of server/in link) * @param databaseId - Database id * @returns Returns database information + Relationships(password) * @example * ```ts * const res = await client.rotateDatabasePass('c2f5a3b6', 's5_info') // res = DatabaseAttributesRelationship * ``` * @example * ```ts * client.rotateDatabasePass('c2f5a3b6', 's3_good').then((res) => console.log(res)) // res = DatabaseAttributesRelationship * ``` */ rotateDatabasePass = async (serverId, databaseId) => { return this.client.request('POST', null, 'attributes', `/api/client/servers/${serverId}/databases/${databaseId}/rotate-password`); }; } exports.databaseMethods = databaseMethods;