mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2025-12-21 03:09:37 +00:00
Add autoplay for next book in series after queue ends
This commit is contained in:
parent
e040396b20
commit
0610cca7b1
3 changed files with 93 additions and 22 deletions
|
|
@ -86,6 +86,30 @@ class SeriesController {
|
|||
res.json(req.series.toOldJSON())
|
||||
}
|
||||
|
||||
/**
|
||||
* GET: /api/series/:id/next-book/:libraryItemId
|
||||
* Get the next book in a series after the given library item
|
||||
*
|
||||
* @param {SeriesControllerRequest} req
|
||||
* @param {Response} res
|
||||
*/
|
||||
async getNextBook(req, res) {
|
||||
const currentLibraryItemId = req.params.libraryItemId
|
||||
const libraryItems = req.libraryItemsInSeries
|
||||
|
||||
const currentBookIndex = libraryItems.findIndex((li) => li.id === currentLibraryItemId)
|
||||
if (currentBookIndex === -1) {
|
||||
return res.status(404).send('Current book not found in series')
|
||||
}
|
||||
|
||||
if (currentBookIndex >= libraryItems.length - 1) {
|
||||
return res.status(404).send('No next book in series')
|
||||
}
|
||||
|
||||
const nextBook = libraryItems[currentBookIndex + 1]
|
||||
res.json(nextBook.toOldJSONExpanded())
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {RequestWithUser} req
|
||||
|
|
|
|||
|
|
@ -222,6 +222,7 @@ class ApiRouter {
|
|||
//
|
||||
this.router.get('/series/:id', SeriesController.middleware.bind(this), SeriesController.findOne.bind(this))
|
||||
this.router.patch('/series/:id', SeriesController.middleware.bind(this), SeriesController.update.bind(this))
|
||||
this.router.get('/series/:id/next-book/:libraryItemId', SeriesController.middleware.bind(this), SeriesController.getNextBook.bind(this))
|
||||
|
||||
//
|
||||
// Playback Session Routes
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue