Add route to download app backups

This commit is contained in:
Johannes Zellner
2022-11-03 22:13:57 +01:00
parent ad3e593f01
commit c4c90cfaf9
3 changed files with 35 additions and 0 deletions

View File

@@ -56,6 +56,7 @@ exports = module.exports = {
backup,
listBackups,
updateBackup,
getBackupDownloadStream,
getTask,
getLogPaths,
@@ -175,9 +176,11 @@ const appstore = require('./appstore.js'),
shell = require('./shell.js'),
spawn = require('child_process').spawn,
split = require('split'),
storage = require('./storage.js'),
superagent = require('superagent'),
system = require('./system.js'),
tasks = require('./tasks.js'),
tgz = require('./backupformat/tgz.js'),
TransformStream = require('stream').Transform,
users = require('./users.js'),
util = require('util'),
@@ -2617,6 +2620,25 @@ async function updateBackup(app, backupId, data) {
await backups.update(backupId, data);
}
async function getBackupDownloadStream(app, backupId) {
assert.strictEqual(typeof app, 'object');
assert.strictEqual(typeof backupId, 'string');
const backup = await backups.get(backupId);
if (!backup) throw new BoxError(BoxError.NOT_FOUND, 'Backup not found');
if (backup.identifier !== app.id) throw new BoxError(BoxError.NOT_FOUND, 'Backup not found'); // some other app's backup
if (backup.format !== 'tgz') throw new BoxError(BoxError.BAD_STATE, 'only tgz backups can be downloaded');
const backupConfig = await settings.getBackupConfig();
return new Promise((resolve, reject) => {
storage.api(backupConfig.provider).download(backupConfig, tgz.getBackupFilePath(backupConfig, backup.remotePath), function (error, sourceStream) {
if (error) return reject(error);
resolve(sourceStream);
});
});
}
async function restoreInstalledApps(options, auditSource) {
assert.strictEqual(typeof options, 'object');
assert.strictEqual(typeof auditSource, 'object');