chore(xo-server/rest-api): match export routes first
This commit is contained in:
@@ -150,6 +150,32 @@ export default class RestApi {
|
||||
)
|
||||
})
|
||||
)
|
||||
|
||||
// should go before routes /:collection/:object because they will match but
|
||||
// will not work due to the extension being included in the object identifer
|
||||
api.get(
|
||||
'/:collection(vdis|vdi-snapshots)/:object.:format(vhd|raw)',
|
||||
wrap(async (req, res) => {
|
||||
const stream = await req.xapiObject.$exportContent({ format: req.params.format })
|
||||
|
||||
stream.headers['content-disposition'] = 'attachment'
|
||||
res.writeHead(stream.statusCode, stream.statusMessage != null ? stream.statusMessage : '', stream.headers)
|
||||
|
||||
await fromCallback(pipeline, stream, res)
|
||||
})
|
||||
)
|
||||
api.get(
|
||||
'/:collection(vms|vm-snapshots|vm-templates)/:object.xva',
|
||||
wrap(async (req, res) => {
|
||||
const stream = await req.xapiObject.$export({ compress: req.query.compress })
|
||||
|
||||
stream.headers['content-disposition'] = 'attachment'
|
||||
res.writeHead(stream.statusCode, stream.statusMessage != null ? stream.statusMessage : '', stream.headers)
|
||||
|
||||
await fromCallback(pipeline, stream, res)
|
||||
})
|
||||
)
|
||||
|
||||
api.get('/:collection/:object', (req, res) => {
|
||||
res.json(req.xoObject)
|
||||
})
|
||||
@@ -196,29 +222,5 @@ export default class RestApi {
|
||||
res.sendStatus(200)
|
||||
})
|
||||
)
|
||||
|
||||
api.get(
|
||||
'/:collection(vdis|vdi-snapshots)/:object.:format(vhd|raw)',
|
||||
wrap(async (req, res) => {
|
||||
const stream = await req.xapiObject.$exportContent({ format: req.params.format })
|
||||
|
||||
stream.headers['content-disposition'] = 'attachment'
|
||||
res.writeHead(stream.statusCode, stream.statusMessage != null ? stream.statusMessage : '', stream.headers)
|
||||
|
||||
await fromCallback(pipeline, stream, res)
|
||||
})
|
||||
)
|
||||
|
||||
api.get(
|
||||
'/:collection(vms|vm-snapshots|vm-templates)/:object.xva',
|
||||
wrap(async (req, res) => {
|
||||
const stream = await req.xapiObject.$export({ compress: req.query.compress })
|
||||
|
||||
stream.headers['content-disposition'] = 'attachment'
|
||||
res.writeHead(stream.statusCode, stream.statusMessage != null ? stream.statusMessage : '', stream.headers)
|
||||
|
||||
await fromCallback(pipeline, stream, res)
|
||||
})
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user