mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2025-02-01 00:18:14 +01:00
Fix:Server crash deleting library that has playback sessions #3634
This commit is contained in:
parent
f850db23fe
commit
d19bb909b3
@ -406,11 +406,6 @@ class Database {
|
||||
return Promise.all(oldBooks.map((oldBook) => this.models.book.saveFromOld(oldBook)))
|
||||
}
|
||||
|
||||
removeLibrary(libraryId) {
|
||||
if (!this.sequelize) return false
|
||||
return this.models.library.removeById(libraryId)
|
||||
}
|
||||
|
||||
createBulkCollectionBooks(collectionBooks) {
|
||||
if (!this.sequelize) return false
|
||||
return this.models.collectionBook.bulkCreate(collectionBooks)
|
||||
|
@ -504,8 +504,21 @@ class LibraryController {
|
||||
await this.handleDeleteLibraryItem(libraryItem.mediaType, libraryItem.id, mediaItemIds)
|
||||
}
|
||||
|
||||
// Set PlaybackSessions libraryId to null
|
||||
const [sessionsUpdated] = await Database.playbackSessionModel.update(
|
||||
{
|
||||
libraryId: null
|
||||
},
|
||||
{
|
||||
where: {
|
||||
libraryId: req.library.id
|
||||
}
|
||||
}
|
||||
)
|
||||
Logger.info(`[LibraryController] Updated ${sessionsUpdated} playback sessions to remove library id`)
|
||||
|
||||
const libraryJson = req.library.toOldJSON()
|
||||
await Database.removeLibrary(req.library.id)
|
||||
await req.library.destroy()
|
||||
|
||||
// Re-order libraries
|
||||
await Database.libraryModel.resetDisplayOrder()
|
||||
|
@ -107,19 +107,6 @@ class Library extends Model {
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Destroy library by id
|
||||
* @param {string} libraryId
|
||||
* @returns
|
||||
*/
|
||||
static removeById(libraryId) {
|
||||
return this.destroy({
|
||||
where: {
|
||||
id: libraryId
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all library ids
|
||||
* @returns {Promise<string[]>} array of library ids
|
||||
|
Loading…
Reference in New Issue
Block a user