embed integrity check task in backup API responses
The UI is polling for the taskId, might as well attach it
This commit is contained in:
+19
-5
@@ -42,9 +42,14 @@ function postProcess(result) {
|
||||
}
|
||||
|
||||
function removePrivateFields(backup) {
|
||||
delete backup.integrityCheckTaskId;
|
||||
return backup;
|
||||
}
|
||||
|
||||
async function attachIntegrityTaskInfo(backup) {
|
||||
backup.integrityCheckTask = backup.integrityCheckTaskId ? await tasks.get(String(backup.integrityCheckTaskId)) : null;
|
||||
}
|
||||
|
||||
async function add(data) {
|
||||
assert(data && typeof data === 'object');
|
||||
assert.strictEqual(typeof data.remotePath, 'string');
|
||||
@@ -82,16 +87,19 @@ async function getLatestInTargetByIdentifier(identifier, siteId) {
|
||||
|
||||
const results = await database.query(`SELECT ${BACKUPS_FIELDS} FROM backups WHERE identifier = ? AND state = ? AND siteId = ? LIMIT 1`, [ identifier, BACKUP_STATE_NORMAL, siteId ]);
|
||||
if (!results.length) return null;
|
||||
|
||||
await attachIntegrityTaskInfo(results[0]);
|
||||
return postProcess(results[0]);
|
||||
}
|
||||
|
||||
async function get(id) {
|
||||
assert.strictEqual(typeof id, 'string');
|
||||
|
||||
const result = await database.query(`SELECT ${BACKUPS_FIELDS} FROM backups WHERE id = ? ORDER BY creationTime DESC`, [ id ]);
|
||||
if (result.length === 0) return null;
|
||||
const results = await database.query(`SELECT ${BACKUPS_FIELDS} FROM backups WHERE id = ? ORDER BY creationTime DESC`, [ id ]);
|
||||
if (results.length === 0) return null;
|
||||
|
||||
return postProcess(result[0]);
|
||||
await attachIntegrityTaskInfo(results[0]);
|
||||
return postProcess(results[0]);
|
||||
}
|
||||
|
||||
function validateLabel(label) {
|
||||
@@ -145,7 +153,10 @@ async function listByTypePaged(type, siteId, page, perPage) {
|
||||
|
||||
const results = await database.query(`SELECT ${BACKUPS_FIELDS} FROM backups WHERE siteId=? AND type = ? ORDER BY creationTime DESC LIMIT ?,?`, [ siteId, type, (page-1)*perPage, perPage ]);
|
||||
|
||||
results.forEach(function (result) { postProcess(result); });
|
||||
for (const r of results) {
|
||||
await attachIntegrityTaskInfo(r);
|
||||
postProcess(r);
|
||||
}
|
||||
|
||||
return results;
|
||||
}
|
||||
@@ -158,7 +169,10 @@ async function listByIdentifierAndStatePaged(identifier, state, page, perPage) {
|
||||
|
||||
const results = await database.query(`SELECT ${BACKUPS_FIELDS} FROM backups WHERE identifier = ? AND state = ? ORDER BY creationTime DESC LIMIT ?,?`, [ identifier, state, (page-1)*perPage, perPage ]);
|
||||
|
||||
results.forEach(postProcess);
|
||||
for (const r of results) {
|
||||
await attachIntegrityTaskInfo(r);
|
||||
postProcess(r);
|
||||
}
|
||||
|
||||
return results;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user