mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2026-12-04 22:16:28 +01:00
Do no delete if darabase update fails
This commit is contained in:
1 parent
177b945c60
commit
dc0afcce79
2 files changed
+8
-6
No files matched your search
@@ -799,15 +799,15 @@ class PodcastController {
|
||||
removedEpisodes.push(episode)
|
||||
}
|
||||
|
||||
if (hardDelete) {
|
||||
await removeEpisodeAudioFiles(removedEpisodes)
|
||||
}
|
||||
|
||||
const removedEpisodeIds = removedEpisodes.map((ep) => ep.id)
|
||||
await Database.playlistModel.removeMediaItemsFromPlaylists(removedEpisodeIds)
|
||||
await deleteEpisodesInTransaction(removedEpisodeIds, matchedByLibraryItem)
|
||||
libraryItemsPodcastFilters.clearCountCache('podcastEpisode', 'afterDestroy')
|
||||
|
||||
if (hardDelete) {
|
||||
await removeEpisodeAudioFiles(removedEpisodes)
|
||||
}
|
||||
|
||||
for (const [libraryItem, episodesToRemove] of matchedByLibraryItem) {
|
||||
Logger.info(`[PodcastController] Batch deleted ${episodesToRemove.length} episode(s) from podcast "${libraryItem.media.title}"`)
|
||||
SocketAuthority.libraryItemEmitter('item_updated', libraryItem)
|
||||
|
||||
@@ -793,9 +793,10 @@ describe('PodcastController batch episode endpoints', () => {
|
||||
expect(await Database.podcastEpisodeModel.findByPk(episode3.id)).to.be.null
|
||||
})
|
||||
|
||||
it('returns 500 when deletion fails unexpectedly', async () => {
|
||||
it('returns 500 and does not unlink files when database deletion fails unexpectedly', async () => {
|
||||
user.permissions = { ...user.permissions, delete: true }
|
||||
sinon.stub(Database.playlistModel, 'removeMediaItemsFromPlaylists').resolves()
|
||||
const fsRemoveStub = sinon.stub(fs, 'remove').resolves()
|
||||
const emitStub = sinon.stub(SocketAuthority, 'libraryItemEmitter')
|
||||
sinon.stub(Database.podcastEpisodeModel, 'destroy').rejects(new Error('SQLITE_BUSY'))
|
||||
|
||||
@@ -803,7 +804,7 @@ describe('PodcastController batch episode endpoints', () => {
|
||||
await PodcastController.batchDeleteEpisodes(
|
||||
{
|
||||
user,
|
||||
query: {},
|
||||
query: { hard: '1' },
|
||||
body: { episodes: [{ libraryItemId: podcastItem1.id, episodeId: episode1.id }] }
|
||||
},
|
||||
res
|
||||
@@ -811,6 +812,7 @@ describe('PodcastController batch episode endpoints', () => {
|
||||
|
||||
expect(res.status.calledOnceWith(500)).to.be.true
|
||||
expect(res.send.calledOnceWith('Failed to delete episodes')).to.be.true
|
||||
expect(fsRemoveStub.called).to.be.false
|
||||
expect(emitStub.called).to.be.false
|
||||
})
|
||||
})
|
||||
|
||||
Reference in new issue
Block a user