mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2026-12-01 04:34:07 +01:00
Fix collection add crash when the book is already in the collection
This commit is contained in:
1 parent
83dce682e8
commit
e9ff70e522
2 files changed
+85
-6
No files matched your search
@@ -247,12 +247,17 @@ class CollectionController {
|
||||
return res.status(400).send('Book already in collection')
|
||||
}
|
||||
|
||||
// Create collectionBook record
|
||||
await Database.collectionBookModel.create({
|
||||
collectionId: req.collection.id,
|
||||
bookId: libraryItem.mediaId,
|
||||
order: collectionBooks.length + 1
|
||||
})
|
||||
// Create collectionBook record. A second add can pass the check above and hit the unique pair.
|
||||
try {
|
||||
await Database.collectionBookModel.create({
|
||||
collectionId: req.collection.id,
|
||||
bookId: libraryItem.mediaId,
|
||||
order: collectionBooks.length + 1
|
||||
})
|
||||
} catch (error) {
|
||||
if (error.name !== 'SequelizeUniqueConstraintError') throw error
|
||||
return res.status(400).send('Book already in collection')
|
||||
}
|
||||
const jsonExpanded = await req.collection.getOldJsonExpanded(req.user)
|
||||
if (jsonExpanded) SocketAuthority.clientEmitter(req.user.id, 'collection_updated', jsonExpanded)
|
||||
res.json(jsonExpanded)
|
||||
|
||||
Reference in new issue
Block a user