jspteroapi
Version:
A pterodactyl v1 api using undici
135 lines (134 loc) • 5.34 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.backupMethods = void 0;
const Functions_1 = require("../../modules/Functions");
class backupMethods {
client;
constructor(client) {
this.client = client;
}
/**
* @internal
*/
getBackups = async (serverId) => {
return this.client.request('GET', null, '', `/api/client/servers/${serverId}/backups`);
};
/**
* @param serverId - ID of the server to get (In the settings tab of server/in link)
* @returns An array of backups
* @example
* ```ts
* const res = await client.getAllBackups('7e74354d') // res = Backup[]
* ```
* @example
* ```ts
* client.getAllBackups('7e74354d').then((res) => console.log(res)) // res = Backup[]
* ```
*/
getAllBackups = async (serverId) => {
return await (0, Functions_1.paginate)(this.getBackups.bind(this, serverId), {});
};
/**
* @param serverId - ID of the server to get (In the settings tab of server/in link)
* @param name - Name of the backup
* @param ignored - Ignored files / folders
* @returns Backup information
* @example
* ```ts
* const res = await client.createBackup('7e74354d') // res = BackupAttributes
* ```
* @example
* ```ts
* client.createBackup('7e74354d', 'RandomBackup').then((res) => console.log(res)) // res = BackupAttributes
* ```
*/
createBackup = async (serverId, name = '', ignored = [], isLocked = false) => {
return this.client.request('POST', {
name: name,
ignored: ignored.join(' '),
is_locked: isLocked
}, 'attributes', `/api/client/servers/${serverId}/backups`);
};
/**
* @param serverId - ID of the server to get (In the settings tab of server/in link)
* @param backupId - ID of the backup to get
* @returns Backup information
* @example
* ```ts
* const res = await client.getBackupInfo('7e74354d', '3a4e4b2a') // res = BackupAttributes
* ```
* @example
* ```ts
* client.getBackupInfo('7e74354d', '3a4e4b2a').then((res) => console.log(res)) // res = BackupAttributes
* ```
*/
getBackupInfo = async (serverId, backupId) => {
return this.client.request('GET', null, 'attributes', `/api/client/servers/${serverId}/backups/${backupId}`);
};
/**
* @param serverId - ID of the server to get (In the settings tab of server/in link)
* @param backupId - ID of the backup to toggle lock of
* @returns Backup information
* @example
* ```ts
* const res = await client.toggleLockBackup('7e74354d', '3a4e4b2a') // res = BackupAttributes
* ```
* @example
* ```ts
* client.toggleLockBackup('7e74354d', '3a4e4b2a').then((res) => console.log(res)) // res = BackupAttributes
* ```
*/
toggleLockBackup = async (serverId, backupId) => {
return this.client.request('POST', null, 'attributes', `/api/client/servers/${serverId}/backups/${backupId}/lock`);
};
/**
* @param serverId - ID of the server to get (In the settings tab of server/in link)
* @param backupId - ID of the backup to restore
* @param truncate - Whether to remove all files before restoring backup
* @returns Sucessfully restored backup
* @example
* ```ts
* const res = await client.restoreBackup('7e74354d', '3a4e4b2a') // res = Sucessfully restored backup
* ```
* @example
* ```ts
* client.restoreBackup('7e74354d', '3a4e4b2a').then((res) => console.log(res)) // res = Sucessfully restored backup
* ```
*/
restoreBackup = async (serverId, backupId, truncate = false) => {
return this.client.request('POST', { truncate }, 'Sucessfully restored backup', `/api/client/servers/${serverId}/backups/${backupId}/restore`);
};
/**
* @param serverId - ID of the server to get (In the settings tab of server/in link)
* @param backupId - ID of the backup to get
* @returns Returns backup download url
* @example
* ```ts
* const res = await client.getBackupDownloadLink('7e74354d', '3a4e4b2a') // res = url (string)
* ```
* @example
* ```ts
* client.getBackupDownloadLink('7e74354d', '3a4e4b2a').then((res) => console.log(res)) // res = url (string)
* ```
*/
getBackupDownloadLink = async (serverId, backupId) => {
return this.client.request('GET', null, 'attributes.url', `/api/client/servers/${serverId}/backups/${backupId}/download`);
};
/**
* @param serverId - ID of the server to get (In the settings tab of server/in link)
* @param backupId - ID of the backup to delete
* @returns Backup information
* @example
* ```ts
* const res = await client.deleteBackup('7e74354d', '3a4e4b2a') // res = Backup successfully deleted!
* ```
* @example
* ```ts
* client.deleteBackup('7e74354d', '3a4e4b2a').then((res) => console.log(res)) // res = Backup successfully deleted!
* ```
*/
deleteBackup = async (serverId, backupId) => {
return this.client.request('DELETE', null, 'Backup successfully deleted!', `/api/client/servers/${serverId}/backups/${backupId}`);
};
}
exports.backupMethods = backupMethods;