remove box backups from the database
This commit is contained in:
@@ -3,7 +3,8 @@
|
|||||||
exports = module.exports = {
|
exports = module.exports = {
|
||||||
BackupsError: BackupsError,
|
BackupsError: BackupsError,
|
||||||
|
|
||||||
getAllPaged: getAllPaged,
|
getPaged: getPaged,
|
||||||
|
getByAppIdPaged: getByAppIdPaged,
|
||||||
|
|
||||||
getBackupUrl: getBackupUrl,
|
getBackupUrl: getBackupUrl,
|
||||||
getAppBackupUrl: getAppBackupUrl,
|
getAppBackupUrl: getAppBackupUrl,
|
||||||
@@ -53,19 +54,28 @@ function api(provider) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function getAllPaged(page, perPage, callback) {
|
function getPaged(page, perPage, callback) {
|
||||||
assert.strictEqual(typeof page, 'number');
|
assert(typeof page === 'number' && page > 0);
|
||||||
assert.strictEqual(typeof perPage, 'number');
|
assert(typeof perPage === 'number' && perPage > 0);
|
||||||
assert.strictEqual(typeof callback, 'function');
|
assert.strictEqual(typeof callback, 'function');
|
||||||
|
|
||||||
settings.getBackupConfig(function (error, backupConfig) {
|
backupdb.getPaged(page, perPage, function (error, results) {
|
||||||
if (error) return callback(new BackupsError(BackupsError.INTERNAL_ERROR, error));
|
if (error) return callback(new BackupsError(BackupsError.INTERNAL_ERROR, error));
|
||||||
|
|
||||||
api(backupConfig.provider).getAllPaged(backupConfig, page, perPage, function (error, backups) {
|
callback(null, results);
|
||||||
if (error) return callback(new BackupsError(BackupsError.EXTERNAL_ERROR, error));
|
|
||||||
|
|
||||||
return callback(null, backups); // [ { creationTime, restoreKey } ] sorted by time (latest first
|
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function getByAppIdPaged(page, perPage, appId, callback) {
|
||||||
|
assert(typeof page === 'number' && page > 0);
|
||||||
|
assert(typeof perPage === 'number' && perPage > 0);
|
||||||
|
assert.strictEqual(typeof appId, 'string');
|
||||||
|
assert.strictEqual(typeof callback, 'function');
|
||||||
|
|
||||||
|
backupdb.getByAppIdPaged(page, perPage, appId, function (error, results) {
|
||||||
|
if (error) return callback(new BackupsError(BackupsError.INTERNAL_ERROR, error));
|
||||||
|
|
||||||
|
callback(null, results);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -11,12 +11,17 @@ var backups = require('../backups.js'),
|
|||||||
BackupsError = require('../backups.js').BackupsError,
|
BackupsError = require('../backups.js').BackupsError,
|
||||||
cloudron = require('../cloudron.js'),
|
cloudron = require('../cloudron.js'),
|
||||||
CloudronError = require('../cloudron.js').CloudronError,
|
CloudronError = require('../cloudron.js').CloudronError,
|
||||||
debug = require('debug')('box:routes/backups'),
|
|
||||||
HttpError = require('connect-lastmile').HttpError,
|
HttpError = require('connect-lastmile').HttpError,
|
||||||
HttpSuccess = require('connect-lastmile').HttpSuccess;
|
HttpSuccess = require('connect-lastmile').HttpSuccess;
|
||||||
|
|
||||||
function get(req, res, next) {
|
function get(req, res, next) {
|
||||||
backups.getAllPaged(1, 5, function (error, result) {
|
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'));
|
||||||
|
|
||||||
|
backups.getPaged(page, perPage, function (error, result) {
|
||||||
if (error && error.reason === BackupsError.EXTERNAL_ERROR) return next(new HttpError(503, error.message));
|
if (error && error.reason === BackupsError.EXTERNAL_ERROR) return next(new HttpError(503, error.message));
|
||||||
if (error) return next(new HttpError(500, error));
|
if (error) return next(new HttpError(500, error));
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user