feat(xo-server/backupNg.fetchFiles): add format param
This commit is contained in:
committed by
Florent BEAUCHAMP
parent
408fd7ec03
commit
348db876d2
@@ -336,21 +336,21 @@ listFiles.params = {
|
||||
},
|
||||
}
|
||||
|
||||
async function handleFetchFiles(req, res, { remote, disk, partition, paths }) {
|
||||
const zipStream = await this.fetchBackupNgPartitionFiles(remote, disk, partition, paths)
|
||||
async function handleFetchFiles(req, res, { remote, disk, format, partition, paths }) {
|
||||
const stream = await this.fetchBackupNgPartitionFiles(remote, disk, partition, paths, format)
|
||||
|
||||
res.setHeader('content-disposition', 'attachment')
|
||||
res.setHeader('content-type', 'application/octet-stream')
|
||||
return zipStream
|
||||
return stream
|
||||
}
|
||||
|
||||
export async function fetchFiles(params) {
|
||||
const { paths } = params
|
||||
const { format, paths } = params
|
||||
let filename = `restore_${safeDateFormat(new Date())}`
|
||||
if (paths.length === 1) {
|
||||
filename += `_${basename(paths[0])}`
|
||||
}
|
||||
filename += '.zip'
|
||||
filename += '.' + format
|
||||
|
||||
return this.registerHttpRequest(handleFetchFiles, params, {
|
||||
suffix: '/' + encodeURIComponent(filename),
|
||||
@@ -363,6 +363,10 @@ fetchFiles.params = {
|
||||
disk: {
|
||||
type: 'string',
|
||||
},
|
||||
format: {
|
||||
type: 'string',
|
||||
default: 'tgz',
|
||||
},
|
||||
partition: {
|
||||
optional: true,
|
||||
type: 'string',
|
||||
|
||||
@@ -33,7 +33,7 @@ export default class BackupNgFileRestore {
|
||||
})
|
||||
}
|
||||
|
||||
async fetchBackupNgPartitionFiles(remoteId, diskId, partitionId, paths) {
|
||||
async fetchBackupNgPartitionFiles(remoteId, diskId, partitionId, paths, format) {
|
||||
const app = this._app
|
||||
const remote = await app.getRemoteWithCredentials(remoteId)
|
||||
return remote.proxy !== undefined
|
||||
@@ -48,11 +48,14 @@ export default class BackupNgFileRestore {
|
||||
},
|
||||
partition: partitionId,
|
||||
paths,
|
||||
|
||||
// don't send the legacy default format to keep compatibility with old proxies
|
||||
format: format === 'zip' ? undefined : format,
|
||||
},
|
||||
{ assertType: 'stream' }
|
||||
)
|
||||
: Disposable.use(app.getBackupsRemoteAdapter(remote), adapter =>
|
||||
adapter.fetchPartitionFiles(diskId, partitionId, paths)
|
||||
adapter.fetchPartitionFiles(diskId, partitionId, paths, format)
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user