2015-07-20 00:09:47 -07:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
|
|
exports = module.exports = {
|
2018-11-17 19:53:15 -08:00
|
|
|
list: list,
|
2019-04-13 18:09:04 -07:00
|
|
|
startBackup: startBackup,
|
2020-07-28 17:18:47 +02:00
|
|
|
cleanup: cleanup,
|
|
|
|
|
check: check
|
2015-07-20 00:09:47 -07:00
|
|
|
};
|
|
|
|
|
|
2019-03-25 15:07:06 -07:00
|
|
|
let auditSource = require('../auditsource.js'),
|
2017-05-30 14:09:55 -07:00
|
|
|
backups = require('../backups.js'),
|
2019-10-22 20:36:20 -07:00
|
|
|
BoxError = require('../boxerror.js'),
|
2015-07-20 00:09:47 -07:00
|
|
|
HttpError = require('connect-lastmile').HttpError,
|
2018-12-09 03:20:00 -08:00
|
|
|
HttpSuccess = require('connect-lastmile').HttpSuccess;
|
2015-07-20 00:09:47 -07:00
|
|
|
|
2018-11-17 19:53:15 -08:00
|
|
|
function list(req, res, next) {
|
2016-03-08 08:52:20 -08:00
|
|
|
var page = typeof req.query.page !== 'undefined' ? parseInt(req.query.page) : 1;
|
|
|
|
|
if (!page || page < 0) return next(new HttpError(400, 'page query param has to be a postive number'));
|
|
|
|
|
|
|
|
|
|
var perPage = typeof req.query.per_page !== 'undefined'? parseInt(req.query.per_page) : 25;
|
|
|
|
|
if (!perPage || perPage < 0) return next(new HttpError(400, 'per_page query param has to be a postive number'));
|
|
|
|
|
|
2020-06-14 12:19:51 -07:00
|
|
|
backups.getByIdentifierAndStatePaged(backups.BACKUP_IDENTIFIER_BOX, backups.BACKUP_STATE_NORMAL, page, perPage, function (error, result) {
|
2019-10-24 18:05:14 -07:00
|
|
|
if (error) return next(BoxError.toHttpError(error));
|
2015-07-20 00:09:47 -07:00
|
|
|
|
|
|
|
|
next(new HttpSuccess(200, { backups: result }));
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2018-11-17 19:53:15 -08:00
|
|
|
function startBackup(req, res, next) {
|
2019-03-25 15:07:06 -07:00
|
|
|
backups.startBackupTask(auditSource.fromRequest(req), function (error, taskId) {
|
2019-10-24 18:05:14 -07:00
|
|
|
if (error) return next(BoxError.toHttpError(error));
|
2018-11-17 19:53:15 -08:00
|
|
|
|
2018-12-08 18:50:06 -08:00
|
|
|
next(new HttpSuccess(202, { taskId }));
|
2018-11-17 19:53:15 -08:00
|
|
|
});
|
|
|
|
|
}
|
2019-04-13 18:09:04 -07:00
|
|
|
|
|
|
|
|
function cleanup(req, res, next) {
|
|
|
|
|
backups.startCleanupTask(auditSource.fromRequest(req), function (error, taskId) {
|
2019-10-24 18:05:14 -07:00
|
|
|
if (error) return next(BoxError.toHttpError(error));
|
2019-04-13 18:09:04 -07:00
|
|
|
|
|
|
|
|
next(new HttpSuccess(202, { taskId }));
|
|
|
|
|
});
|
|
|
|
|
}
|
2020-07-28 17:18:47 +02:00
|
|
|
|
|
|
|
|
function check(req, res, next) {
|
|
|
|
|
backups.checkConfiguration(function (error, message) {
|
|
|
|
|
if (error) return next(BoxError.toHttpError(error));
|
|
|
|
|
|
|
|
|
|
next(new HttpSuccess(200, { ok: !message, message: message }));
|
|
|
|
|
});
|
|
|
|
|
}
|