UNPKG

@squarecloud/api

Version:
49 lines (48 loc) 1.77 kB
var __defProp = Object.defineProperty; var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value; var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value); // src/structures/backup.ts var Backup = class { /** * Represents an application backup (snapshot) * * @constructor * @param application - The application from which you fetched the backups * @param data - The data from this backup */ constructor(application, data) { this.application = application; /** Size of the backup in bytes. */ __publicField(this, "size"); /** Date of the last modification of the backup. */ __publicField(this, "modifiedAt"); /** Date of the last modification of the backup in millisseconds. */ __publicField(this, "modifiedTimestamp"); /** AWS access key for the backup. */ __publicField(this, "key"); /** The URL for downloading this backup */ __publicField(this, "url"); const { name, size, modified, key } = data; const { userId } = application.client.api; this.size = size; this.modifiedAt = new Date(modified); this.modifiedTimestamp = this.modifiedAt.getTime(); this.key = key; this.url = `https://snapshots.squarecloud.app/applications/${userId}/${name}.zip?${key}`; } /** * Downloads this backup * @returns The downloaded backup bufer */ async download() { const res = await fetch(this.url).then((res2) => res2.arrayBuffer()).catch(() => void 0); if (!res) { throw new Error("BACKUP_DOWNLOAD_FAILED"); } return Buffer.from(res); } }; export { Backup }; //# sourceMappingURL=backup.js.map