mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2024-12-20 19:06:06 +01:00
Fix: daily log rewrite, Add: purge user audiobook data for audiobooks that no longer exist
This commit is contained in:
parent
411409d67e
commit
b0ea2f8008
13
server/Db.js
13
server/Db.js
@ -258,9 +258,16 @@ class Db {
|
||||
var orphanOldPath = Path.join(dbdatadir, orphanOld)
|
||||
await fs.unlink(orphanOldPath)
|
||||
console.log('Removed .old file')
|
||||
var lockdirpath = Path.join(dbdatadir, `data.${dbnum}.lock`)
|
||||
await fs.rmdir(lockdirpath)
|
||||
console.log('Removed lock dir')
|
||||
|
||||
// Removing lock dir throws error in proper-lockfile
|
||||
// var lockdirpath = Path.join(dbdatadir, `data.${dbnum}.json.lock`)
|
||||
// var lockdirexists = await fs.pathExists(lockdirpath)
|
||||
// if (lockdirexists) {
|
||||
// await fs.rmdir(lockdirpath)
|
||||
// console.log('Removed lock dir')
|
||||
// } else {
|
||||
// console.log('No lock dir found', lockdirpath)
|
||||
// }
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
|
@ -113,6 +113,7 @@ class Server {
|
||||
await this.db.init()
|
||||
this.auth.init()
|
||||
|
||||
await this.checkUserAudiobookData()
|
||||
await this.purgeMetadata()
|
||||
await this.backupManager.init()
|
||||
await this.logManager.init()
|
||||
@ -359,6 +360,26 @@ class Server {
|
||||
return purged
|
||||
}
|
||||
|
||||
// Check user audiobook data has matching audiobook
|
||||
async checkUserAudiobookData() {
|
||||
for (let i = 0; i < this.db.users.length; i++) {
|
||||
var _user = this.db.users[i]
|
||||
if (_user.audiobooks) {
|
||||
// Find user audiobook data that has no matching audiobook
|
||||
var audiobookIdsToRemove = Object.keys(_user.audiobooks).filter(aid => {
|
||||
return !this.db.audiobooks.find(ab => ab.id === aid)
|
||||
})
|
||||
if (audiobookIdsToRemove.length) {
|
||||
Logger.debug(`[Server] Found ${audiobookIdsToRemove.length} audiobook data to remove from user ${_user.username}`)
|
||||
for (let y = 0; y < audiobookIdsToRemove.length; y++) {
|
||||
_user.deleteAudiobookData(audiobookIdsToRemove[y])
|
||||
}
|
||||
await this.db.updateEntity('user', _user)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async handleUpload(req, res) {
|
||||
if (!req.user.canUpload) {
|
||||
Logger.warn('User attempted to upload without permission', req.user)
|
||||
|
@ -99,7 +99,10 @@ class DailyLog {
|
||||
|
||||
var hasFailures = false
|
||||
|
||||
this.logs = text.split(/\r?\n/).map(t => {
|
||||
var logLines = text.split(/\r?\n/)
|
||||
// remove last log if empty
|
||||
if (logLines.length && !logLines[logLines.length - 1]) logLines = logLines.slice(0, -1)
|
||||
this.logs = logLines.map(t => {
|
||||
if (!t) {
|
||||
hasFailures = true
|
||||
return null
|
||||
|
Loading…
Reference in New Issue
Block a user