1
0
Fork 0

Add download route to Foxx API

This commit is contained in:
Alan Plum 2016-11-16 18:49:14 +01:00
parent 8c3b824fe5
commit 5978461ffe
No known key found for this signature in database
GPG Key ID: 8ED72A9A323B6EFD
1 changed files with 16 additions and 3 deletions

View File

@ -19,10 +19,10 @@ module.context.registerType('multipart/form-data', require('./multipart'));
module.context.use(router);
const legacyErrors = new Map([
[errors.ERROR_SERVICE_INVALID_NAME.code, errors.ERROR_FOXX_SOURCE_NOT_FOUND.code],
[errors.ERROR_SERVICE_INVALID_NAME.code, errors.ERROR_SERVICE_SOURCE_NOT_FOUND.code],
[errors.ERROR_SERVICE_INVALID_MOUNT.code, errors.ERROR_INVALID_MOUNTPOINT.code],
[errors.ERROR_SERVICE_DOWNLOAD_FAILED.code, errors.ERROR_FOXX_SOURCE_ERROR.code],
[errors.ERROR_SERVICE_UPLOAD_FAILED.code, errors.ERROR_FOXX_SOURCE_ERROR.code]
[errors.ERROR_SERVICE_DOWNLOAD_FAILED.code, errors.ERROR_SERVICE_SOURCE_ERROR.code],
[errors.ERROR_SERVICE_UPLOAD_FAILED.code, errors.ERROR_SERVICE_SOURCE_ERROR.code]
]);
const serviceToJson = (service) => (
@ -362,6 +362,19 @@ scriptsRouter.post('/:name', (req, res) => {
Returns the exports of the script, if any.
`);
instanceRouter.post('/download', (req, res) => {
const service = req.service;
const dir = fs.join(fs.makeAbsolute(service.root), service.path);
const zipPath = fmu.zipDirectory(dir);
const name = service.mount.replace(/^\/|\/$/g, '').replace(/\//g, '_');
res.download(zipPath, `${name}.zip`);
})
.response(200, ['application/zip'], `Zip bundle of the service.`)
.summary(`Download service bundle`)
.description(dd`
Creates and downloads a zip bundle of the service directory.
`);
instanceRouter.post('/tests', (req, res) => {
const service = req.service;
const reporter = req.queryParams.reporter || null;