mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2026-07-10 19:31:39 +00:00
Merge branch 'refs/heads/master' into mf/rssInboundManager
This commit is contained in:
commit
50ea58aea2
193 changed files with 11020 additions and 1005 deletions
|
|
@ -22,6 +22,16 @@ class ApiCacheManager {
|
|||
this.cache.clear()
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset hooks and clear cache. Used when applying backups
|
||||
*/
|
||||
reset() {
|
||||
Logger.info(`[ApiCacheManager] Resetting cache`)
|
||||
|
||||
this.init()
|
||||
this.cache.clear()
|
||||
}
|
||||
|
||||
get middleware() {
|
||||
return (req, res, next) => {
|
||||
const key = { user: req.user.username, url: req.url }
|
||||
|
|
|
|||
|
|
@ -146,23 +146,73 @@ class BackupManager {
|
|||
}
|
||||
}
|
||||
|
||||
async requestApplyBackup(backup, res) {
|
||||
/**
|
||||
*
|
||||
* @param {import('./ApiCacheManager')} apiCacheManager
|
||||
* @param {Backup} backup
|
||||
* @param {import('express').Response} res
|
||||
*/
|
||||
async requestApplyBackup(apiCacheManager, backup, res) {
|
||||
Logger.info(`[BackupManager] Applying backup at "${backup.fullPath}"`)
|
||||
|
||||
const zip = new StreamZip.async({ file: backup.fullPath })
|
||||
|
||||
const entries = await zip.entries()
|
||||
|
||||
// Ensure backup has an absdatabase.sqlite file
|
||||
if (!Object.keys(entries).includes('absdatabase.sqlite')) {
|
||||
Logger.error(`[BackupManager] Cannot apply old backup ${backup.fullPath}`)
|
||||
await zip.close()
|
||||
return res.status(500).send('Invalid backup file. Does not include absdatabase.sqlite. This might be from an older Audiobookshelf server.')
|
||||
}
|
||||
|
||||
await Database.disconnect()
|
||||
|
||||
await zip.extract('absdatabase.sqlite', global.ConfigPath)
|
||||
const dbPath = Path.join(global.ConfigPath, 'absdatabase.sqlite')
|
||||
const tempDbPath = Path.join(global.ConfigPath, 'absdatabase-temp.sqlite')
|
||||
|
||||
// Extract backup sqlite file to temporary path
|
||||
await zip.extract('absdatabase.sqlite', tempDbPath)
|
||||
Logger.info(`[BackupManager] Extracted backup sqlite db to temp path ${tempDbPath}`)
|
||||
|
||||
// Verify extract - Abandon backup if sqlite file did not extract
|
||||
if (!await fs.pathExists(tempDbPath)) {
|
||||
Logger.error(`[BackupManager] Sqlite file not found after extract - abandon backup apply and reconnect db`)
|
||||
await zip.close()
|
||||
await Database.reconnect()
|
||||
return res.status(500).send('Failed to extract sqlite db from backup')
|
||||
}
|
||||
|
||||
// Attempt to remove existing db file
|
||||
try {
|
||||
await fs.remove(dbPath)
|
||||
} catch (error) {
|
||||
// Abandon backup and remove extracted sqlite file if unable to remove existing db file
|
||||
Logger.error(`[BackupManager] Unable to overwrite existing db file - abandon backup apply and reconnect db`, error)
|
||||
await fs.remove(tempDbPath)
|
||||
await zip.close()
|
||||
await Database.reconnect()
|
||||
return res.status(500).send(`Failed to overwrite sqlite db: ${error?.message || 'Unknown Error'}`)
|
||||
}
|
||||
|
||||
// Rename temp db
|
||||
await fs.move(tempDbPath, dbPath)
|
||||
Logger.info(`[BackupManager] Saved backup sqlite file at "${dbPath}"`)
|
||||
|
||||
// Extract /metadata/items and /metadata/authors folders
|
||||
await zip.extract('metadata-items/', this.ItemsMetadataPath)
|
||||
await zip.extract('metadata-authors/', this.AuthorsMetadataPath)
|
||||
await zip.close()
|
||||
|
||||
// Reconnect db
|
||||
await Database.reconnect()
|
||||
|
||||
// Reset api cache, set hooks again
|
||||
await apiCacheManager.reset()
|
||||
|
||||
res.sendStatus(200)
|
||||
|
||||
// Triggers browser refresh for all clients
|
||||
SocketAuthority.emitter('backup_applied')
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -11,8 +11,8 @@ const fileUtils = require('../utils/fileUtils')
|
|||
class BinaryManager {
|
||||
|
||||
defaultRequiredBinaries = [
|
||||
{ name: 'ffmpeg', envVariable: 'FFMPEG_PATH', validVersions: ['5.1', '6'] },
|
||||
{ name: 'ffprobe', envVariable: 'FFPROBE_PATH', validVersions: ['5.1', '6'] }
|
||||
{ name: 'ffmpeg', envVariable: 'FFMPEG_PATH', validVersions: ['5.1'] },
|
||||
{ name: 'ffprobe', envVariable: 'FFPROBE_PATH', validVersions: ['5.1'] }
|
||||
]
|
||||
|
||||
constructor(requiredBinaries = this.defaultRequiredBinaries) {
|
||||
|
|
@ -24,7 +24,14 @@ class BinaryManager {
|
|||
}
|
||||
|
||||
async init() {
|
||||
// Optional skip binaries check
|
||||
if (process.env.SKIP_BINARIES_CHECK === '1') {
|
||||
Logger.info('[BinaryManager] Skipping check for binaries')
|
||||
return
|
||||
}
|
||||
|
||||
if (this.initialized) return
|
||||
|
||||
const missingBinaries = await this.findRequiredBinaries()
|
||||
if (missingBinaries.length == 0) return
|
||||
await this.removeOldBinaries(missingBinaries)
|
||||
|
|
@ -135,7 +142,7 @@ class BinaryManager {
|
|||
if (!binaries.length) return
|
||||
Logger.info(`[BinaryManager] Installing binaries: ${binaries.join(', ')}`)
|
||||
let destination = await fileUtils.isWritable(this.mainInstallPath) ? this.mainInstallPath : this.altInstallPath
|
||||
await ffbinaries.downloadBinaries(binaries, { destination, version: '6.1', force: true })
|
||||
await ffbinaries.downloadBinaries(binaries, { destination, version: '5.1', force: true })
|
||||
Logger.info(`[BinaryManager] Binaries installed to ${destination}`)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -144,8 +144,13 @@ class PlaybackSessionManager {
|
|||
session.currentTime = sessionJson.currentTime
|
||||
session.timeListening = sessionJson.timeListening
|
||||
session.updatedAt = sessionJson.updatedAt
|
||||
session.date = date.format(new Date(), 'YYYY-MM-DD')
|
||||
session.dayOfWeek = date.format(new Date(), 'dddd')
|
||||
|
||||
let jsDate = new Date(sessionJson.updatedAt)
|
||||
if (isNaN(jsDate)) {
|
||||
jsDate = new Date()
|
||||
}
|
||||
session.date = date.format(jsDate, 'YYYY-MM-DD')
|
||||
session.dayOfWeek = date.format(jsDate, 'dddd')
|
||||
|
||||
Logger.debug(`[PlaybackSessionManager] Updated session for "${session.displayTitle}" (${session.id})`)
|
||||
await Database.updatePlaybackSession(session)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue