diff --git a/server/Db.js b/server/Db.js index 11b2b0b1..b8626e35 100644 --- a/server/Db.js +++ b/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) { diff --git a/server/Server.js b/server/Server.js index c8afc7d9..165246ad 100644 --- a/server/Server.js +++ b/server/Server.js @@ -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) diff --git a/server/objects/DailyLog.js b/server/objects/DailyLog.js index 17fd03c8..042dc3f1 100644 --- a/server/objects/DailyLog.js +++ b/server/objects/DailyLog.js @@ -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