mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2025-07-24 04:44:57 +02: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
3 changed files with 35 additions and 4 deletions
|
@ -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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue