mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2025-01-08 00:08:14 +01:00
Fix:Updating author name to update author name on each library item
This commit is contained in:
parent
f00b120e96
commit
69fcb103e4
@ -20,10 +20,26 @@ class AuthorController {
|
||||
}
|
||||
}
|
||||
|
||||
var authorNameUpdate = payload.name !== undefined && payload.name !== req.author.name
|
||||
|
||||
var hasUpdated = req.author.update(payload)
|
||||
if (hasUpdated) {
|
||||
if (authorNameUpdate) { // Update author name on all books
|
||||
var itemsWithAuthor = this.db.libraryItems.filter(li => li.mediaType === 'book' && li.media.metadata.hasAuthor(req.author.id))
|
||||
itemsWithAuthor.forEach(libraryItem => {
|
||||
libraryItem.media.metadata.updateAuthor(req.author)
|
||||
})
|
||||
if (itemsWithAuthor.length) {
|
||||
await this.db.updateLibraryItems(itemsWithAuthor)
|
||||
this.emitter('items_updated', itemsWithAuthor.map(li => li.toJSONExpanded()))
|
||||
}
|
||||
}
|
||||
|
||||
await this.db.updateEntity('author', req.author)
|
||||
this.emitter('author_updated', req.author.toJSON())
|
||||
var numBooks = this.db.libraryItems.filter(li => {
|
||||
return li.media.metadata.hasAuthor && li.media.metadata.hasAuthor(req.author.id)
|
||||
}).length
|
||||
this.emitter('author_updated', req.author.toJSONExpanded(numBooks))
|
||||
}
|
||||
res.json({
|
||||
author: req.author.toJSON(),
|
||||
|
@ -140,6 +140,14 @@ class BookMetadata {
|
||||
return hasUpdates
|
||||
}
|
||||
|
||||
// Updates author name
|
||||
updateAuthor(updatedAuthor) {
|
||||
var author = this.authors.find(au => au.id === updatedAuthor.id)
|
||||
if (!author || author.name == updatedAuthor.name) return false
|
||||
author.name = updatedAuthor.name
|
||||
return true
|
||||
}
|
||||
|
||||
setData(scanMediaData = {}) {
|
||||
this.title = scanMediaData.title || null
|
||||
this.subtitle = scanMediaData.subtitle || null
|
||||
|
Loading…
Reference in New Issue
Block a user