mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2025-01-17 00:08:55 +01:00
Update media item shares to close when changing shares on same device
This commit is contained in:
parent
dd1d2b7c92
commit
43217657d7
@ -42,19 +42,14 @@ class ShareController {
|
|||||||
const playbackSession = ShareManager.findPlaybackSessionBySessionId(req.cookies.share_session_id)
|
const playbackSession = ShareManager.findPlaybackSessionBySessionId(req.cookies.share_session_id)
|
||||||
|
|
||||||
if (playbackSession) {
|
if (playbackSession) {
|
||||||
const playbackSessionMediaItemShare = ShareManager.findByMediaItemId(playbackSession.mediaItemId)
|
if (mediaItemShare.id === playbackSession.mediaItemShareId) {
|
||||||
if (!playbackSessionMediaItemShare) {
|
|
||||||
Logger.error(`[ShareController] Share playback session ${req.cookies.share_session_id} media item share not found with id ${playbackSession.mediaItemId}`)
|
|
||||||
return res.sendStatus(500)
|
|
||||||
}
|
|
||||||
if (playbackSessionMediaItemShare.slug === slug) {
|
|
||||||
Logger.debug(`[ShareController] Found share playback session ${req.cookies.share_session_id}`)
|
Logger.debug(`[ShareController] Found share playback session ${req.cookies.share_session_id}`)
|
||||||
mediaItemShare.playbackSession = playbackSession.toJSONForClient()
|
mediaItemShare.playbackSession = playbackSession.toJSONForClient()
|
||||||
return res.json(mediaItemShare)
|
return res.json(mediaItemShare)
|
||||||
} else {
|
} else {
|
||||||
// TODO: Close old session and use same session id
|
// Changed media item share - close other session
|
||||||
Logger.info(`[ShareController] Share playback session found with id ${req.cookies.share_session_id} but media item share slug ${playbackSessionMediaItemShare.slug} does not match requested slug ${slug}`)
|
Logger.debug(`[ShareController] Other playback session is already open for share session. Closing session "${playbackSession.displayTitle}"`)
|
||||||
res.clearCookie('share_session_id')
|
ShareManager.closeSharePlaybackSession(playbackSession)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Logger.info(`[ShareController] Share playback session not found with id ${req.cookies.share_session_id}`)
|
Logger.info(`[ShareController] Share playback session not found with id ${req.cookies.share_session_id}`)
|
||||||
|
@ -25,10 +25,19 @@ class ShareManager {
|
|||||||
* @param {import('../objects/PlaybackSession')} playbackSession
|
* @param {import('../objects/PlaybackSession')} playbackSession
|
||||||
*/
|
*/
|
||||||
addOpenSharePlaybackSession(playbackSession) {
|
addOpenSharePlaybackSession(playbackSession) {
|
||||||
Logger.info(`[ShareManager] Adding new open share playback session ${playbackSession.shareSessionId}`)
|
Logger.info(`[ShareManager] Adding new open share playback session "${playbackSession.displayTitle}"`)
|
||||||
this.openSharePlaybackSessions.push(playbackSession)
|
this.openSharePlaybackSessions.push(playbackSession)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param {import('../objects/PlaybackSession')} playbackSession
|
||||||
|
*/
|
||||||
|
closeSharePlaybackSession(playbackSession) {
|
||||||
|
Logger.info(`[ShareManager] Closing share playback session "${playbackSession.displayTitle}"`)
|
||||||
|
this.openSharePlaybackSessions = this.openSharePlaybackSessions.filter((s) => s.id !== playbackSession.id)
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Find an open media item share by media item ID
|
* Find an open media item share by media item ID
|
||||||
* @param {string} mediaItemId
|
* @param {string} mediaItemId
|
||||||
|
@ -568,7 +568,6 @@ class LibraryItem extends Model {
|
|||||||
oldLibraryItem.numEpisodesIncomplete = li.numEpisodesIncomplete
|
oldLibraryItem.numEpisodesIncomplete = li.numEpisodesIncomplete
|
||||||
}
|
}
|
||||||
if (li.mediaType === 'book' && options.include?.includes?.('share')) {
|
if (li.mediaType === 'book' && options.include?.includes?.('share')) {
|
||||||
console.log('Lookup share for media item id', li.mediaId)
|
|
||||||
oldLibraryItem.mediaItemShare = ShareManager.findByMediaItemId(li.mediaId)
|
oldLibraryItem.mediaItemShare = ShareManager.findByMediaItemId(li.mediaId)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user