mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2025-08-15 09:42:25 +02:00
Fix: daily log rewrite, Add: purge user audiobook data for audiobooks that no longer exist
This commit is contained in:
@ -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)
|
||||
|
Reference in New Issue
Block a user