chore(xo-server-audit/_uploadLastHash): simplify conditions

This commit is contained in:
Julien Fontanet 2020-09-17 10:07:32 +02:00
parent 42ee29cb3c
commit 726ba287b1

View File

@ -325,12 +325,12 @@ class AuditXoPlugin {
const chain = await xo.audit.getLastChain()
let lastHash, integrityCheckSuccess
let lastValidHash
if (chain !== null) {
const hashes = chain.hashes
lastHash = hashes[hashes.length - 1]
lastValidHash = hashes[hashes.length - 1]
if (lastHash === lastRecordId) {
if (lastValidHash === lastRecordId) {
return
}
@ -349,16 +349,16 @@ class AuditXoPlugin {
throw error
}
integrityCheckSuccess = false
lastValidHash = undefined
}
}
// generate a valid fingerprint of all stored records in case of a failure integrity check
const { oldest, newest, error } = await this._generateFingerprint({
oldest: integrityCheckSuccess ? lastHash : undefined,
oldest: lastValidHash,
})
if (chain === null || !integrityCheckSuccess || error !== undefined) {
if (lastValidHash === undefined || error !== undefined) {
await xo.audit.startNewChain({ oldest, newest })
} else {
await xo.audit.extendLastChain({ oldest, newest })