Add route to download app backups
This commit is contained in:
22
src/apps.js
22
src/apps.js
@@ -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');
|
||||
|
||||
Reference in New Issue
Block a user