UNPKG

@squarecloud/api

Version:
1 lines 2.45 kB
{"version":3,"sources":["../../src/structures/backup.ts"],"sourcesContent":["import type { APIApplicationBackup } from \"@squarecloud/api-types/v2\";\n\nimport type { BaseApplication } from \"./application/base\";\n\n/**\n * Represents an application backup (snapshot)\n */\nexport class Backup {\n\t/** Size of the backup in bytes. */\n\tpublic size: number;\n\n\t/** Date of the last modification of the backup. */\n\tpublic modifiedAt: Date;\n\n\t/** Date of the last modification of the backup in millisseconds. */\n\tpublic modifiedTimestamp: number;\n\n\t/** AWS access key for the backup. */\n\tpublic readonly key: string;\n\n\t/** The URL for downloading this backup */\n\tpublic readonly url: string;\n\n\t/**\n\t * Represents an application backup (snapshot)\n\t *\n\t * @constructor\n\t * @param application - The application from which you fetched the backups\n\t * @param data - The data from this backup\n\t */\n\tconstructor(\n\t\tpublic readonly application: BaseApplication,\n\t\tdata: APIApplicationBackup,\n\t) {\n\t\tconst { name, size, modified, key } = data;\n\t\tconst { userId } = application.client.api;\n\n\t\tthis.size = size;\n\t\tthis.modifiedAt = new Date(modified);\n\t\tthis.modifiedTimestamp = this.modifiedAt.getTime();\n\t\tthis.key = key;\n\t\tthis.url = `https://snapshots.squarecloud.app/applications/${userId}/${name}.zip?${key}`;\n\t}\n\n\t/**\n\t * Downloads this backup\n\t * @returns The downloaded backup bufer\n\t */\n\tasync download(): Promise<Buffer> {\n\t\tconst res = await fetch(this.url)\n\t\t\t.then((res) => res.arrayBuffer())\n\t\t\t.catch(() => undefined);\n\n\t\tif (!res) {\n\t\t\tthrow new Error(\"BACKUP_DOWNLOAD_FAILED\");\n\t\t}\n\n\t\treturn Buffer.from(res);\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAOO,IAAM,SAAN,MAAa;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAuBnB,YACiB,aAChB,MACC;AAFe;AAtBjB;AAAA,wBAAO;AAGP;AAAA,wBAAO;AAGP;AAAA,wBAAO;AAGP;AAAA,wBAAgB;AAGhB;AAAA,wBAAgB;AAaf,UAAM,EAAE,MAAM,MAAM,UAAU,IAAI,IAAI;AACtC,UAAM,EAAE,OAAO,IAAI,YAAY,OAAO;AAEtC,SAAK,OAAO;AACZ,SAAK,aAAa,IAAI,KAAK,QAAQ;AACnC,SAAK,oBAAoB,KAAK,WAAW,QAAQ;AACjD,SAAK,MAAM;AACX,SAAK,MAAM,kDAAkD,MAAM,IAAI,IAAI,QAAQ,GAAG;AAAA,EACvF;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,MAAM,WAA4B;AACjC,UAAM,MAAM,MAAM,MAAM,KAAK,GAAG,EAC9B,KAAK,CAACA,SAAQA,KAAI,YAAY,CAAC,EAC/B,MAAM,MAAM,MAAS;AAEvB,QAAI,CAAC,KAAK;AACT,YAAM,IAAI,MAAM,wBAAwB;AAAA,IACzC;AAEA,WAAO,OAAO,KAAK,GAAG;AAAA,EACvB;AACD;","names":["res"]}