mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2026-11-13 12:23:34 +01:00
Update collection controller to only emit collection socket events to the user making the request
This commit is contained in:
1 parent
f57ca09f6e
commit
49c0ef6c07
1 file changed
+21
-22
@@ -96,12 +96,8 @@ class CollectionController {
|
|||||||
return res.status(500).send('Failed to create collection')
|
return res.status(500).send('Failed to create collection')
|
||||||
}
|
}
|
||||||
|
|
||||||
// Load books expanded
|
const jsonExpanded = await newCollection.getOldJsonExpanded(req.user)
|
||||||
newCollection.books = await newCollection.getBooksExpandedWithLibraryItem()
|
if (jsonExpanded) SocketAuthority.clientEmitter(req.user.id, 'collection_added', jsonExpanded)
|
||||||
|
|
||||||
// Note: The old collection model stores expanded libraryItems in the books property
|
|
||||||
const jsonExpanded = newCollection.toOldJSONExpanded()
|
|
||||||
SocketAuthority.emitter('collection_added', jsonExpanded)
|
|
||||||
res.json(jsonExpanded)
|
res.json(jsonExpanded)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -196,9 +192,9 @@ class CollectionController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const jsonExpanded = await req.collection.getOldJsonExpanded()
|
const jsonExpanded = await req.collection.getOldJsonExpanded(req.user)
|
||||||
if (wasUpdated) {
|
if (wasUpdated && jsonExpanded) {
|
||||||
SocketAuthority.emitter('collection_updated', jsonExpanded)
|
SocketAuthority.clientEmitter(req.user.id, 'collection_updated', jsonExpanded)
|
||||||
}
|
}
|
||||||
res.json(jsonExpanded)
|
res.json(jsonExpanded)
|
||||||
}
|
}
|
||||||
@@ -212,14 +208,17 @@ class CollectionController {
|
|||||||
* @param {Response} res
|
* @param {Response} res
|
||||||
*/
|
*/
|
||||||
async delete(req, res) {
|
async delete(req, res) {
|
||||||
const jsonExpanded = await req.collection.getOldJsonExpanded()
|
const jsonExpanded = await req.collection.getOldJsonExpanded(req.user)
|
||||||
|
|
||||||
// Close rss feed - remove from db and emit socket event
|
// Close rss feed - remove from db and emit socket event
|
||||||
await RssFeedManager.closeFeedForEntityId(req.collection.id)
|
await RssFeedManager.closeFeedForEntityId(req.collection.id)
|
||||||
|
|
||||||
|
if (jsonExpanded) {
|
||||||
|
SocketAuthority.clientEmitter(req.user.id, 'collection_removed', jsonExpanded)
|
||||||
|
}
|
||||||
|
|
||||||
await req.collection.destroy()
|
await req.collection.destroy()
|
||||||
|
|
||||||
SocketAuthority.emitter('collection_removed', jsonExpanded)
|
|
||||||
res.sendStatus(200)
|
res.sendStatus(200)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -254,8 +253,8 @@ class CollectionController {
|
|||||||
bookId: libraryItem.mediaId,
|
bookId: libraryItem.mediaId,
|
||||||
order: collectionBooks.length + 1
|
order: collectionBooks.length + 1
|
||||||
})
|
})
|
||||||
const jsonExpanded = await req.collection.getOldJsonExpanded()
|
const jsonExpanded = await req.collection.getOldJsonExpanded(req.user)
|
||||||
SocketAuthority.emitter('collection_updated', jsonExpanded)
|
if (jsonExpanded) SocketAuthority.clientEmitter(req.user.id, 'collection_updated', jsonExpanded)
|
||||||
res.json(jsonExpanded)
|
res.json(jsonExpanded)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -299,10 +298,10 @@ class CollectionController {
|
|||||||
order++
|
order++
|
||||||
}
|
}
|
||||||
|
|
||||||
jsonExpanded = await req.collection.getOldJsonExpanded()
|
jsonExpanded = await req.collection.getOldJsonExpanded(req.user)
|
||||||
SocketAuthority.emitter('collection_updated', jsonExpanded)
|
if (jsonExpanded) SocketAuthority.clientEmitter(req.user.id, 'collection_updated', jsonExpanded)
|
||||||
} else {
|
} else {
|
||||||
jsonExpanded = await req.collection.getOldJsonExpanded()
|
jsonExpanded = await req.collection.getOldJsonExpanded(req.user)
|
||||||
}
|
}
|
||||||
res.json(jsonExpanded)
|
res.json(jsonExpanded)
|
||||||
}
|
}
|
||||||
@@ -361,10 +360,10 @@ class CollectionController {
|
|||||||
if (hasUpdated) {
|
if (hasUpdated) {
|
||||||
await Database.collectionBookModel.bulkCreate(collectionBooksToAdd)
|
await Database.collectionBookModel.bulkCreate(collectionBooksToAdd)
|
||||||
|
|
||||||
jsonExpanded = await req.collection.getOldJsonExpanded()
|
jsonExpanded = await req.collection.getOldJsonExpanded(req.user)
|
||||||
SocketAuthority.emitter('collection_updated', jsonExpanded)
|
if (jsonExpanded) SocketAuthority.clientEmitter(req.user.id, 'collection_updated', jsonExpanded)
|
||||||
} else {
|
} else {
|
||||||
jsonExpanded = await req.collection.getOldJsonExpanded()
|
jsonExpanded = await req.collection.getOldJsonExpanded(req.user)
|
||||||
}
|
}
|
||||||
res.json(jsonExpanded)
|
res.json(jsonExpanded)
|
||||||
}
|
}
|
||||||
@@ -417,9 +416,9 @@ class CollectionController {
|
|||||||
order++
|
order++
|
||||||
}
|
}
|
||||||
|
|
||||||
let jsonExpanded = await req.collection.getOldJsonExpanded()
|
let jsonExpanded = await req.collection.getOldJsonExpanded(req.user)
|
||||||
if (hasUpdated) {
|
if (hasUpdated && jsonExpanded) {
|
||||||
SocketAuthority.emitter('collection_updated', jsonExpanded)
|
SocketAuthority.clientEmitter(req.user.id, 'collection_updated', jsonExpanded)
|
||||||
}
|
}
|
||||||
res.json(jsonExpanded)
|
res.json(jsonExpanded)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user