mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2026-03-01 05:29:41 +00:00
feat: add total duration and progress to series
This commit is contained in:
parent
b01facc034
commit
00f9940712
3 changed files with 48 additions and 1 deletions
|
|
@ -789,10 +789,15 @@ class LibraryController {
|
|||
const seriesJson = series.toOldJSON()
|
||||
if (include.includes('progress')) {
|
||||
const libraryItemsFinished = libraryItemsInSeries.filter((li) => !!req.user.getMediaProgress(li.media.id)?.isFinished)
|
||||
const totalListened = libraryItemsInSeries.reduce((acc, li) => {
|
||||
const p = req.user.getMediaProgress(li.media.id)
|
||||
return acc + (p?.isFinished ? (li.media.duration || 0) : (p?.currentTime || 0))
|
||||
}, 0)
|
||||
seriesJson.progress = {
|
||||
libraryItemIds: libraryItemsInSeries.map((li) => li.id),
|
||||
libraryItemIdsFinished: libraryItemsFinished.map((li) => li.id),
|
||||
isFinished: libraryItemsFinished.length >= libraryItemsInSeries.length
|
||||
isFinished: libraryItemsFinished.length >= libraryItemsInSeries.length,
|
||||
totalDurationListened: totalListened
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -801,6 +806,9 @@ class LibraryController {
|
|||
seriesJson.rssFeed = feedObj?.toOldJSONMinified() || null
|
||||
}
|
||||
|
||||
// populate total duration (same unit as libraryItem.duration)
|
||||
seriesJson.totalDuration = await Database.seriesModel.getTotalDurationById(series.id)
|
||||
|
||||
res.json(seriesJson)
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue