Fix socket events check user permissions for library items #4199

This commit is contained in:
advplyr 2025-04-12 17:39:51 -05:00
parent 26309019e7
commit bc1b99efd6
10 changed files with 69 additions and 61 deletions

View file

@ -152,10 +152,7 @@ class AuthorController {
for (const libraryItem of libraryItems) {
await libraryItem.saveMetadataFile()
}
SocketAuthority.emitter(
'items_updated',
libraryItems.map((li) => li.toOldJSONExpanded())
)
SocketAuthority.libraryItemsEmitter('items_updated', libraryItems)
}
// Remove old author
@ -210,10 +207,7 @@ class AuthorController {
}
if (libraryItems.length) {
SocketAuthority.emitter(
'items_updated',
libraryItems.map((li) => li.toOldJSONExpanded())
)
SocketAuthority.libraryItemsEmitter('items_updated', libraryItems)
}
} else {
numBooksForAuthor = await Database.bookAuthorModel.getCountForAuthor(req.author.id)

View file

@ -1188,10 +1188,7 @@ class LibraryController {
}
if (itemsUpdated.length) {
SocketAuthority.emitter(
'items_updated',
itemsUpdated.map((li) => li.toOldJSONExpanded())
)
SocketAuthority.libraryItemsEmitter('items_updated', itemsUpdated)
}
res.json({
@ -1232,10 +1229,7 @@ class LibraryController {
}
if (itemsUpdated.length) {
SocketAuthority.emitter(
'items_updated',
itemsUpdated.map((li) => li.toOldJSONExpanded())
)
SocketAuthority.libraryItemsEmitter('items_updated', itemsUpdated)
}
res.json({

View file

@ -253,7 +253,7 @@ class LibraryItemController {
}
Logger.debug(`[LibraryItemController] Updated library item media ${req.libraryItem.media.title}`)
SocketAuthority.emitter('item_updated', req.libraryItem.toOldJSONExpanded())
SocketAuthority.libraryItemEmitter('item_updated', req.libraryItem)
}
res.json({
updated: hasUpdates,
@ -300,7 +300,7 @@ class LibraryItemController {
req.libraryItem.changed('updatedAt', true)
await req.libraryItem.save()
SocketAuthority.emitter('item_updated', req.libraryItem.toOldJSONExpanded())
SocketAuthority.libraryItemEmitter('item_updated', req.libraryItem)
res.json({
success: true,
cover: result.cover
@ -332,7 +332,7 @@ class LibraryItemController {
req.libraryItem.changed('updatedAt', true)
await req.libraryItem.save()
SocketAuthority.emitter('item_updated', req.libraryItem.toOldJSONExpanded())
SocketAuthority.libraryItemEmitter('item_updated', req.libraryItem)
}
res.json({
success: true,
@ -358,7 +358,7 @@ class LibraryItemController {
await CacheManager.purgeCoverCache(req.libraryItem.id)
SocketAuthority.emitter('item_updated', req.libraryItem.toOldJSONExpanded())
SocketAuthority.libraryItemEmitter('item_updated', req.libraryItem)
}
res.sendStatus(200)
@ -485,7 +485,7 @@ class LibraryItemController {
req.libraryItem.media.changed('audioFiles', true)
await req.libraryItem.media.save()
SocketAuthority.emitter('item_updated', req.libraryItem.toOldJSONExpanded())
SocketAuthority.libraryItemEmitter('item_updated', req.libraryItem)
res.json(req.libraryItem.toOldJSON())
}
@ -663,7 +663,7 @@ class LibraryItemController {
await libraryItem.saveMetadataFile()
Logger.debug(`[LibraryItemController] Updated library item media "${libraryItem.media.title}"`)
SocketAuthority.emitter('item_updated', libraryItem.toOldJSONExpanded())
SocketAuthority.libraryItemEmitter('item_updated', libraryItem)
itemsUpdated++
}
}
@ -894,7 +894,7 @@ class LibraryItemController {
await req.libraryItem.saveMetadataFile()
SocketAuthority.emitter('item_updated', req.libraryItem.toOldJSONExpanded())
SocketAuthority.libraryItemEmitter('item_updated', req.libraryItem)
}
res.json({
@ -1005,7 +1005,7 @@ class LibraryItemController {
await req.libraryItem.save()
SocketAuthority.emitter('item_updated', req.libraryItem.toOldJSONExpanded())
SocketAuthority.libraryItemEmitter('item_updated', req.libraryItem)
res.sendStatus(200)
}
@ -1153,7 +1153,7 @@ class LibraryItemController {
await req.libraryItem.save()
SocketAuthority.emitter('item_updated', req.libraryItem.toOldJSONExpanded())
SocketAuthority.libraryItemEmitter('item_updated', req.libraryItem)
res.sendStatus(200)
}

View file

@ -343,7 +343,7 @@ class MiscController {
})
await libraryItem.saveMetadataFile()
SocketAuthority.emitter('item_updated', libraryItem.toOldJSONExpanded())
SocketAuthority.libraryItemEmitter('item_updated', libraryItem)
numItemsUpdated++
}
}
@ -386,7 +386,7 @@ class MiscController {
})
await libraryItem.saveMetadataFile()
SocketAuthority.emitter('item_updated', libraryItem.toOldJSONExpanded())
SocketAuthority.libraryItemEmitter('item_updated', libraryItem)
numItemsUpdated++
}
@ -481,7 +481,7 @@ class MiscController {
})
await libraryItem.saveMetadataFile()
SocketAuthority.emitter('item_updated', libraryItem.toOldJSONExpanded())
SocketAuthority.libraryItemEmitter('item_updated', libraryItem)
numItemsUpdated++
}
}
@ -524,7 +524,7 @@ class MiscController {
})
await libraryItem.saveMetadataFile()
SocketAuthority.emitter('item_updated', libraryItem.toOldJSONExpanded())
SocketAuthority.libraryItemEmitter('item_updated', libraryItem)
numItemsUpdated++
}

View file

@ -161,7 +161,7 @@ class PodcastController {
}
}
SocketAuthority.emitter('item_added', newLibraryItem.toOldJSONExpanded())
SocketAuthority.libraryItemEmitter('item_added', newLibraryItem)
res.json(newLibraryItem.toOldJSONExpanded())
@ -379,7 +379,7 @@ class PodcastController {
const overrideDetails = req.query.override === '1'
const episodesUpdated = await Scanner.quickMatchPodcastEpisodes(req.libraryItem, { overrideDetails })
if (episodesUpdated) {
SocketAuthority.emitter('item_updated', req.libraryItem.toOldJSONExpanded())
SocketAuthority.libraryItemEmitter('item_updated', req.libraryItem)
}
res.json({
@ -418,7 +418,7 @@ class PodcastController {
Logger.info(`[PodcastController] Updated episode "${episode.title}" keys`, episode.changed())
await episode.save()
SocketAuthority.emitter('item_updated', req.libraryItem.toOldJSONExpanded())
SocketAuthority.libraryItemEmitter('item_updated', req.libraryItem)
} else {
Logger.info(`[PodcastController] No changes to episode "${episode.title}"`)
}
@ -504,7 +504,7 @@ class PodcastController {
req.libraryItem.media.numEpisodes = req.libraryItem.media.podcastEpisodes.length
await req.libraryItem.media.save()
SocketAuthority.emitter('item_updated', req.libraryItem.toOldJSONExpanded())
SocketAuthority.libraryItemEmitter('item_updated', req.libraryItem)
res.json(req.libraryItem.toOldJSON())
}