mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2026-07-07 18:01:42 +00:00
Add initial Author name normalization and calculated column updates
This commit is contained in:
parent
aacdcc47ec
commit
bf76128203
2 changed files with 77 additions and 23 deletions
|
|
@ -247,15 +247,11 @@ class Scanner {
|
|||
}
|
||||
const authorIdsRemoved = []
|
||||
for (const authorName of matchData.author) {
|
||||
const existingAuthor = libraryItem.media.authors.find((a) => a.name.toLowerCase() === authorName.toLowerCase())
|
||||
const existingAuthor = libraryItem.media.authors.find((a) => Database.authorModel.isAuthorNameMatch(a.name, authorName))
|
||||
if (!existingAuthor) {
|
||||
let author = await Database.authorModel.getByNameAndLibrary(authorName, libraryItem.libraryId)
|
||||
if (!author) {
|
||||
author = await Database.authorModel.create({
|
||||
name: authorName,
|
||||
lastFirst: Database.authorModel.getLastFirst(authorName),
|
||||
libraryId: libraryItem.libraryId
|
||||
})
|
||||
const { author, created: isCreated } = await Database.authorModel.findOrCreateByNameAndLibrary(authorName, libraryItem.libraryId)
|
||||
if (!author) continue
|
||||
if (isCreated) {
|
||||
SocketAuthority.emitter('author_added', author.toOldJSON())
|
||||
// Update filter data
|
||||
Database.addAuthorToFilterData(libraryItem.libraryId, author.name, author.id)
|
||||
|
|
@ -271,7 +267,7 @@ class Scanner {
|
|||
hasAuthorUpdates = true
|
||||
})
|
||||
}
|
||||
const authorsRemoved = libraryItem.media.authors.filter((a) => !matchData.author.find((ma) => ma.toLowerCase() === a.name.toLowerCase()))
|
||||
const authorsRemoved = libraryItem.media.authors.filter((a) => !matchData.author.find((ma) => Database.authorModel.isAuthorNameMatch(ma, a.name)))
|
||||
if (authorsRemoved.length) {
|
||||
for (const author of authorsRemoved) {
|
||||
await Database.bookAuthorModel.destroy({ where: { authorId: author.id, bookId: libraryItem.media.id } })
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue