mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2026-05-19 09:51:39 +00:00
Update backup load & upload to remove tempfile on failed backups, validate details filesize & close zip
This commit is contained in:
parent
24cab79c66
commit
39adefb632
1 changed files with 38 additions and 1 deletions
|
|
@ -126,13 +126,31 @@ class BackupManager {
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
// Not a valid zip file
|
// Not a valid zip file
|
||||||
Logger.error('[BackupManager] Failed to read backup file - backup might not be a valid .zip file', tempPath, error)
|
Logger.error('[BackupManager] Failed to read backup file - backup might not be a valid .zip file', tempPath, error)
|
||||||
|
await zip.close().catch(() => {})
|
||||||
|
await fs.remove(tempPath).catch((err) => Logger.error(`[BackupManager] Failed to remove rejected backup file "${tempPath}"`, err))
|
||||||
return res.status(400).send('Failed to read backup file - backup might not be a valid .zip file')
|
return res.status(400).send('Failed to read backup file - backup might not be a valid .zip file')
|
||||||
}
|
}
|
||||||
if (!Object.keys(entries).includes('absdatabase.sqlite')) {
|
if (!entries['absdatabase.sqlite']) {
|
||||||
Logger.error(`[BackupManager] Invalid backup with no absdatabase.sqlite file - might be a backup created on an old Audiobookshelf server.`)
|
Logger.error(`[BackupManager] Invalid backup with no absdatabase.sqlite file - might be a backup created on an old Audiobookshelf server.`)
|
||||||
|
await zip.close().catch(() => {})
|
||||||
|
await fs.remove(tempPath).catch((err) => Logger.error(`[BackupManager] Failed to remove rejected backup file "${tempPath}"`, err))
|
||||||
return res.status(500).send('Invalid backup with no absdatabase.sqlite file - might be a backup created on an old Audiobookshelf server.')
|
return res.status(500).send('Invalid backup with no absdatabase.sqlite file - might be a backup created on an old Audiobookshelf server.')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const detailsEntry = entries['details']
|
||||||
|
if (!detailsEntry) {
|
||||||
|
Logger.error('[BackupManager] Invalid backup - missing details entry')
|
||||||
|
await zip.close().catch(() => {})
|
||||||
|
await fs.remove(tempPath).catch((err) => Logger.error(`[BackupManager] Failed to remove rejected backup file "${tempPath}"`, err))
|
||||||
|
return res.status(400).send('Invalid backup file - missing details entry')
|
||||||
|
}
|
||||||
|
if (detailsEntry.size > 1024 * 1024) {
|
||||||
|
Logger.error(`[BackupManager] Backup details entry too large: ${detailsEntry.size} bytes`)
|
||||||
|
await zip.close().catch(() => {})
|
||||||
|
await fs.remove(tempPath).catch((err) => Logger.error(`[BackupManager] Failed to remove rejected backup file "${tempPath}"`, err))
|
||||||
|
return res.status(400).send('Invalid backup file - details entry too large')
|
||||||
|
}
|
||||||
|
|
||||||
const data = await zip.entryData('details')
|
const data = await zip.entryData('details')
|
||||||
const details = data.toString('utf8').split('\n')
|
const details = data.toString('utf8').split('\n')
|
||||||
|
|
||||||
|
|
@ -140,9 +158,13 @@ class BackupManager {
|
||||||
|
|
||||||
if (!backup.serverVersion) {
|
if (!backup.serverVersion) {
|
||||||
Logger.error(`[BackupManager] Invalid backup with no server version - might be a backup created before version 2.0.0`)
|
Logger.error(`[BackupManager] Invalid backup with no server version - might be a backup created before version 2.0.0`)
|
||||||
|
await zip.close().catch(() => {})
|
||||||
|
await fs.remove(tempPath).catch((err) => Logger.error(`[BackupManager] Failed to remove rejected backup file "${tempPath}"`, err))
|
||||||
return res.status(500).send('Invalid backup. Might be a backup created before version 2.0.0.')
|
return res.status(500).send('Invalid backup. Might be a backup created before version 2.0.0.')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
await zip.close().catch(() => {})
|
||||||
|
|
||||||
backup.fileSize = await getFileSize(backup.fullPath)
|
backup.fileSize = await getFileSize(backup.fullPath)
|
||||||
|
|
||||||
const existingBackupIndex = this.backups.findIndex((b) => b.id === backup.id)
|
const existingBackupIndex = this.backups.findIndex((b) => b.id === backup.id)
|
||||||
|
|
@ -257,9 +279,24 @@ class BackupManager {
|
||||||
let data = null
|
let data = null
|
||||||
try {
|
try {
|
||||||
zip = new StreamZip.async({ file: fullFilePath })
|
zip = new StreamZip.async({ file: fullFilePath })
|
||||||
|
const entries = await zip.entries()
|
||||||
|
|
||||||
|
const detailsEntry = entries['details']
|
||||||
|
if (!detailsEntry) {
|
||||||
|
Logger.error(`[BackupManager] Backup "${fullFilePath}" missing details entry - skipping`)
|
||||||
|
await zip.close().catch(() => {})
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if (detailsEntry.size > 1024 * 1024) {
|
||||||
|
Logger.error(`[BackupManager] Backup "${fullFilePath}" details entry too large (${detailsEntry.size} bytes) - skipping`)
|
||||||
|
await zip.close().catch(() => {})
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
data = await zip.entryData('details')
|
data = await zip.entryData('details')
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
Logger.error(`[BackupManager] Failed to unzip backup "${fullFilePath}"`, error)
|
Logger.error(`[BackupManager] Failed to unzip backup "${fullFilePath}"`, error)
|
||||||
|
if (zip) await zip.close().catch(() => {})
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue