UNPKG

jspteroapi

Version:

A pterodactyl v1 api using undici

75 lines (74 loc) 2.8 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.allocationMethods = void 0; const Functions_1 = require("../../modules/Functions"); class allocationMethods { application; constructor(application) { this.application = application; } /** * @internal */ getAllocations = async (nodeId, options) => { return this.application.request('GET', null, '', `/api/application/nodes/${nodeId}/allocations${(0, Functions_1.makeOptions)(options)}`); }; /** * @param nodeId - The node id of which you want to get allocations from * @param options - Include information about relationships * @returns Returns information about node * @example * ```ts * const res = await app.getAllAllocations(1) // res = NodeAttributes * ``` * @example * ```ts * app.getAllAllocations(1).then((res) => console.log(res)) // res = NodeAttributes * ``` */ getAllAllocations = async (nodeId, options, filter) => { return await (0, Functions_1.paginate)(this.getAllocations.bind(this, nodeId), { includes: { ...options }, filter }); }; /** * @param nodeId - The node id of which you want to create allocations * @param ports - Ports array to add * @param alias - The alias for this allocation * @param ip - IP for the allocation * @returns If successful returns Successfully created! * @example * ```ts * const res = await app.createAllocation(1, ['25565']) // res = Successfully created! * ``` * @example * ```ts * app.createAllocation(1, ['25565'], 'minecraft').then((res) => console.log(res)) // res = Successfully created! * ``` */ createAllocation = async (nodeId, ports, alias = '', ip = '0.0.0.0') => { return this.application.request('POST', { ip: ip, ports: ports, allocation_alias: alias }, 'Successfully created!', `/api/application/nodes/${nodeId}/allocations`); }; /** * @param nodeId - The node id of which you want to delete allocation * @param allocationId - The id of allocation to delete * @returns If successful returns Successfully deleted! * @example * ```ts * const res = await app.deleteAllocation(1, 5) // res = Successfully deleted! * ``` * @example * ```ts * app.deleteAllocation(1, 8).then((res) => console.log(res)) // res = Successfully deleted! * ``` */ deleteAllocation = async (nodeId, allocationId) => { return this.application.request('DELETE', null, 'Successfully deleted!', `/api/application/nodes/${nodeId}/allocations/${allocationId}`); }; } exports.allocationMethods = allocationMethods;