mirror of
				https://github.com/advplyr/audiobookshelf.git
				synced 2025-11-04 03:17:00 -05:00 
			
		
		
		
	Fix dup author addition logic
This commit is contained in:
		
							parent
							
								
									d8b9f08e5a
								
							
						
					
					
						commit
						e6735e042e
					
				@ -312,17 +312,18 @@ class LibraryItem extends Model {
 | 
				
			|||||||
        const existingAuthors = libraryItemExpanded.media.authors || []
 | 
					        const existingAuthors = libraryItemExpanded.media.authors || []
 | 
				
			||||||
        const existingSeriesAll = libraryItemExpanded.media.series || []
 | 
					        const existingSeriesAll = libraryItemExpanded.media.series || []
 | 
				
			||||||
        const updatedAuthors = oldLibraryItem.media.metadata.authors || []
 | 
					        const updatedAuthors = oldLibraryItem.media.metadata.authors || []
 | 
				
			||||||
 | 
					        const uniqueUpdatedAuthors = updatedAuthors.filter((au, idx) => updatedAuthors.findIndex(a => a.id === au.id) === idx)
 | 
				
			||||||
        const updatedSeriesAll = oldLibraryItem.media.metadata.series || []
 | 
					        const updatedSeriesAll = oldLibraryItem.media.metadata.series || []
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        for (const existingAuthor of existingAuthors) {
 | 
					        for (const existingAuthor of existingAuthors) {
 | 
				
			||||||
          // Author was removed from Book
 | 
					          // Author was removed from Book
 | 
				
			||||||
          if (!updatedAuthors.some(au => au.id === existingAuthor.id)) {
 | 
					          if (!uniqueUpdatedAuthors.some(au => au.id === existingAuthor.id)) {
 | 
				
			||||||
            Logger.debug(`[LibraryItem] "${libraryItemExpanded.media.title}" author "${existingAuthor.name}" was removed`)
 | 
					            Logger.debug(`[LibraryItem] "${libraryItemExpanded.media.title}" author "${existingAuthor.name}" was removed`)
 | 
				
			||||||
            await this.sequelize.models.bookAuthor.removeByIds(existingAuthor.id, libraryItemExpanded.media.id)
 | 
					            await this.sequelize.models.bookAuthor.removeByIds(existingAuthor.id, libraryItemExpanded.media.id)
 | 
				
			||||||
            hasUpdates = true
 | 
					            hasUpdates = true
 | 
				
			||||||
          }
 | 
					          }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        for (const updatedAuthor of updatedAuthors) {
 | 
					        for (const updatedAuthor of uniqueUpdatedAuthors) {
 | 
				
			||||||
          // Author was added
 | 
					          // Author was added
 | 
				
			||||||
          if (!existingAuthors.some(au => au.id === updatedAuthor.id)) {
 | 
					          if (!existingAuthors.some(au => au.id === updatedAuthor.id)) {
 | 
				
			||||||
            Logger.debug(`[LibraryItem] "${libraryItemExpanded.media.title}" author "${updatedAuthor.name}" was added`)
 | 
					            Logger.debug(`[LibraryItem] "${libraryItemExpanded.media.title}" author "${updatedAuthor.name}" was added`)
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user