mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2025-04-20 01:17:45 +02:00
Add:API endpoint to get continue listening items across all libraries for android auto
This commit is contained in:
parent
c5f91ec508
commit
9f200ece99
@ -1,4 +1,5 @@
|
|||||||
const Logger = require('../Logger')
|
const Logger = require('../Logger')
|
||||||
|
const { sort } = require('../libs/fastSort')
|
||||||
const { isObject, toNumber } = require('../utils/index')
|
const { isObject, toNumber } = require('../utils/index')
|
||||||
|
|
||||||
class MeController {
|
class MeController {
|
||||||
@ -240,5 +241,40 @@ class MeController {
|
|||||||
localProgressUpdates: updatedLocalMediaProgress
|
localProgressUpdates: updatedLocalMediaProgress
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GET: api/me/items-in-progress
|
||||||
|
async getAllLibraryItemsInProgress(req, res) {
|
||||||
|
const limit = !isNaN(req.query.limit) ? Number(req.query.limit) || 25 : 25
|
||||||
|
|
||||||
|
var itemsInProgress = []
|
||||||
|
for (const mediaProgress of req.user.mediaProgress) {
|
||||||
|
if (!mediaProgress.isFinished && mediaProgress.progress > 0) {
|
||||||
|
const libraryItem = await this.db.getLibraryItem(mediaProgress.libraryItemId)
|
||||||
|
if (libraryItem) {
|
||||||
|
if (mediaProgress.episodeId && libraryItem.mediaType === 'podcast') {
|
||||||
|
const episode = libraryItem.media.episodes.find(ep => ep.id === mediaProgress.episodeId)
|
||||||
|
if (episode) {
|
||||||
|
const libraryItemWithEpisode = {
|
||||||
|
...libraryItem.toJSONMinified(),
|
||||||
|
recentEpisode: episode.toJSON(),
|
||||||
|
progressLastUpdate: mediaProgress.lastUpdate
|
||||||
|
}
|
||||||
|
itemsInProgress.push(libraryItemWithEpisode)
|
||||||
|
}
|
||||||
|
} else if (!mediaProgress.episodeId) {
|
||||||
|
itemsInProgress.push({
|
||||||
|
...libraryItem.toJSONMinified(),
|
||||||
|
progressLastUpdate: mediaProgress.lastUpdate
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
itemsInProgress = sort(itemsInProgress).desc(li => li.progressLastUpdate).slice(0, limit)
|
||||||
|
res.json({
|
||||||
|
libraryItems: itemsInProgress
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
module.exports = new MeController()
|
module.exports = new MeController()
|
@ -142,6 +142,7 @@ class ApiRouter {
|
|||||||
this.router.patch('/me/password', MeController.updatePassword.bind(this))
|
this.router.patch('/me/password', MeController.updatePassword.bind(this))
|
||||||
this.router.patch('/me/settings', MeController.updateSettings.bind(this))
|
this.router.patch('/me/settings', MeController.updateSettings.bind(this))
|
||||||
this.router.post('/me/sync-local-progress', MeController.syncLocalMediaProgress.bind(this))
|
this.router.post('/me/sync-local-progress', MeController.syncLocalMediaProgress.bind(this))
|
||||||
|
this.router.get('/me/items-in-progress', MeController.getAllLibraryItemsInProgress.bind(this))
|
||||||
|
|
||||||
//
|
//
|
||||||
// Backup Routes
|
// Backup Routes
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
const { sort, createNewSortInstance } = require('../libs/fastSort')
|
const { sort, createNewSortInstance } = require('../libs/fastSort')
|
||||||
const { getTitleIgnorePrefix } = require('../utils/index')
|
const { getTitleIgnorePrefix } = require('../utils/index')
|
||||||
const Logger = require('../Logger')
|
|
||||||
const naturalSort = createNewSortInstance({
|
const naturalSort = createNewSortInstance({
|
||||||
comparer: new Intl.Collator(undefined, { numeric: true, sensitivity: 'base' }).compare
|
comparer: new Intl.Collator(undefined, { numeric: true, sensitivity: 'base' }).compare
|
||||||
})
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user