add archives api
This commit is contained in:
@@ -10,6 +10,12 @@ exports = module.exports = {
|
||||
list,
|
||||
del,
|
||||
|
||||
archives: {
|
||||
get: archivesGet,
|
||||
list: archivesList,
|
||||
del: archivesDel
|
||||
},
|
||||
|
||||
startBackupTask,
|
||||
|
||||
startCleanupTask,
|
||||
@@ -171,6 +177,34 @@ async function getByTypePaged(type, page, perPage) {
|
||||
return results;
|
||||
}
|
||||
|
||||
async function archivesGet(id) {
|
||||
assert.strictEqual(typeof id, 'string');
|
||||
|
||||
const result = await database.query(`SELECT ${BACKUPS_FIELDS} FROM backups WHERE id = ? AND archive = 1 ORDER BY creationTime DESC`, [ id ]);
|
||||
if (result.length === 0) return null;
|
||||
|
||||
return postProcess(result[0]);
|
||||
}
|
||||
|
||||
async function archivesList(page, perPage) {
|
||||
assert(typeof page === 'number' && page > 0);
|
||||
assert(typeof perPage === 'number' && perPage > 0);
|
||||
|
||||
const results = await database.query(`SELECT ${BACKUPS_FIELDS} FROM backups WHERE archive = 1 ORDER BY creationTime DESC LIMIT ?,?`, [ (page-1)*perPage, perPage ]);
|
||||
|
||||
results.forEach(function (result) { postProcess(result); });
|
||||
|
||||
return results;
|
||||
}
|
||||
|
||||
async function archivesDel(id, auditSource) {
|
||||
assert.strictEqual(typeof id, 'string');
|
||||
assert(auditSource && typeof auditSource === 'object');
|
||||
|
||||
const result = await database.query('UPDATE backups SET archive = 0 WHERE id=?', [ id ]);
|
||||
if (result.affectedRows !== 1) throw new BoxError(BoxError.NOT_FOUND, 'Backup not found in archive');
|
||||
}
|
||||
|
||||
function validateLabel(label) {
|
||||
assert.strictEqual(typeof label, 'string');
|
||||
|
||||
|
||||
Reference in New Issue
Block a user