mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2026-11-13 12:23:34 +01:00
Dedupe book authors before inserting links so a repeated name does not abort the scan
This commit is contained in:
1 parent
f1f57d6595
commit
4072054e00
2 files changed
+6
No files matched your search
@@ -439,6 +439,7 @@ class Book extends Model {
|
||||
*/
|
||||
async updateAuthorsFromRequest(authors, libraryId) {
|
||||
if (!Array.isArray(authors)) return null
|
||||
authors = parseNameString.dedupeNames(authors)
|
||||
|
||||
if (!this.authors) {
|
||||
throw new Error(`[Book] Cannot update authors because authors are not loaded for book ${this.id}`)
|
||||
@@ -466,6 +467,8 @@ class Book extends Model {
|
||||
const authorsAdded = []
|
||||
for (const authorName of newAuthorNames) {
|
||||
const { author, created } = await authorModel.findOrCreateByNameAndLibrary(authorName, libraryId)
|
||||
// findOrCreate matches case-insensitively, so a second spelling can resolve to an author just linked
|
||||
if (this.authors.some((au) => au.id === author.id)) continue
|
||||
await bookAuthorModel.create({ bookId: this.id, authorId: author.id })
|
||||
if (created) {
|
||||
SocketAuthority.emitter('author_added', author.toOldJSON())
|
||||
|
||||
@@ -703,6 +703,9 @@ class BookScanner {
|
||||
bookMetadata.description = htmlSanitizer.sanitize(bookMetadata.description)
|
||||
}
|
||||
|
||||
// One dedupe after every metadata source. A repeated name inserts the same bookAuthor twice and aborts the scan.
|
||||
bookMetadata.authors = parseNameString.dedupeNames(bookMetadata.authors)
|
||||
|
||||
return bookMetadata
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user