UNPKG

jspteroapi

Version:

A pterodactyl v1 api using undici

88 lines (87 loc) 3.55 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.networkMethods = void 0; class networkMethods { client; constructor(client) { this.client = client; } /** * @param serverId - ID of the server to get (In the settings tab of server/in link) * @returns Array of allocations * @example * ```ts * const res = await client.getAllAlocations('c2f5a3b6') // res = Allocation[] * ``` * @example * ```ts * client.getAllAlocations('c2f5a3b6').then((res) => console.log(res)) // res = Allocation[] * ``` */ getAllAlocations = (serverId) => { return this.client.request('GET', null, 'data', `/api/client/servers/${serverId}/network/allocations`); }; /** * @param serverId - ID of the server to get (In the settings tab of server/in link) * @remarks This method is only available if auto-assign is enabled * @example * ```ts * const res = await client.assignAllocation('c2f5a3b6') // res = Allocation * ``` * @example * ```ts * client.assignAllocation('c2f5a3b6').then((res) => console.log(res)) // res = Allocation * ``` */ assignAllocation = (serverId) => { return this.client.request('POST', null, 'attributes', `/api/client/servers/${serverId}/network/allocations`); }; /** * @param serverId - ID of the server to get (In the settings tab of server/in link) * @param allocationId - ID of the allocation to set the note for * @param note - The note you want to set * @example * ```ts * const res = await client.setAllocationNote('c2f5a3b6', 1, "Port for RDP") // res = Allocation * ``` * @example * ```ts * client.setAllocationNote('c2f5a3b6', 1, "Port for RDP").then((res) => console.log(res)) // res = Allocation * ``` */ setAllocationNote = (serverId, allocationId, note) => { return this.client.request('POST', { notes: note }, 'attributes', `/api/client/servers/${serverId}/network/allocations/${allocationId}`); }; /** * @param serverId - ID of the server to get (In the settings tab of server/in link) * @param allocationId - ID of the allocation to make primary * @example * ```ts * const res = await client.setAllocationPrimary('c2f5a3b6', 1) // res = Allocation * ``` * @example * ```ts * client.setAllocationPrimary('c2f5a3b6', 1).then((res) => console.log(res)) // res = Allocation * ``` */ setAllocationPrimary = (serverId, allocationId) => { return this.client.request('POST', null, 'attributes', `/api/client/servers/${serverId}/network/allocations/${allocationId}/primary`); }; /** * @param serverId - ID of the server to get (In the settings tab of server/in link) * @param allocationId - ID of the allocation to delete * @remarks This method is only available if allocation is not primary * @example * ```ts * const res = await client.deleteAllocation('c2f5a3b6', 1) // res = Sucessfully deleted Allocation! * ``` * @example * ```ts * client.deleteAllocation('c2f5a3b6', 1).then((res) => console.log(res)) // res = Sucessfully deleted Allocation! * ``` */ deleteAllocation = (serverId, allocationId) => { return this.client.request('DELETE', null, 'Sucessfully deleted Allocation!', `/api/client/servers/${serverId}/network/allocations/${allocationId}`); }; } exports.networkMethods = networkMethods;