Remove media progress for podcast episodes when episode is removed

This commit is contained in:
advplyr 2023-08-06 14:18:51 -05:00
parent 1372c24535
commit 56e3449db6
2 changed files with 48 additions and 17 deletions

View file

@ -263,7 +263,7 @@ class PodcastController {
// Remove episode from Podcast and library file
const episodeRemoved = libraryItem.media.removeEpisode(episodeId)
if (episodeRemoved && episodeRemoved.audioFile) {
if (episodeRemoved?.audioFile) {
libraryItem.removeLibraryFile(episodeRemoved.audioFile.ino)
}
@ -283,6 +283,16 @@ class PodcastController {
}
}
// Remove media progress for this episode
const mediaProgressRemoved = await Database.models.mediaProgress.destroy({
where: {
mediaItemId: episode.id
}
})
if (mediaProgressRemoved) {
Logger.info(`[PodcastController] Removed ${mediaProgressRemoved} media progress for episode ${episode.id}`)
}
await Database.updateLibraryItem(libraryItem)
SocketAuthority.emitter('item_updated', libraryItem.toJSONExpanded())
res.json(libraryItem.toJSON())