mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2025-08-04 18:24:46 +02:00
Update get User API endpoint to load media progress from db
This commit is contained in:
parent
1ebe8a6f4c
commit
361732a463
4 changed files with 59 additions and 45 deletions
|
@ -352,34 +352,6 @@ class ApiRouter {
|
|||
//
|
||||
// Helper Methods
|
||||
//
|
||||
userJsonWithItemProgressDetails(user, hideRootToken = false) {
|
||||
const json = user.toJSONForBrowser(hideRootToken)
|
||||
|
||||
json.mediaProgress = json.mediaProgress.map(lip => {
|
||||
const libraryItem = Database.libraryItems.find(li => li.id === lip.libraryItemId)
|
||||
if (!libraryItem) {
|
||||
Logger.warn('[ApiRouter] Library item not found for users progress ' + lip.libraryItemId)
|
||||
lip.media = null
|
||||
} else {
|
||||
if (lip.episodeId) {
|
||||
const episode = libraryItem.mediaType === 'podcast' ? libraryItem.media.getEpisode(lip.episodeId) : null
|
||||
if (!episode) {
|
||||
Logger.warn(`[ApiRouter] Episode ${lip.episodeId} not found for user media progress, podcast: ${libraryItem.media.metadata.title}`)
|
||||
lip.media = null
|
||||
} else {
|
||||
lip.media = libraryItem.media.toJSONExpanded()
|
||||
lip.episode = episode.toJSON()
|
||||
}
|
||||
} else {
|
||||
lip.media = libraryItem.media.toJSONExpanded()
|
||||
}
|
||||
}
|
||||
return lip
|
||||
}).filter(lip => !!lip)
|
||||
|
||||
return json
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove library item and associated entities
|
||||
* @param {string} mediaType
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue