Skip to content

Commit

Permalink
Update get all libraries endpoint to support include stats for androi…
Browse files Browse the repository at this point in the history
…d auto to detect audio libraries
  • Loading branch information
advplyr committed Jan 11, 2025
1 parent c819afc commit 41daf55
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions server/controllers/LibraryController.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,21 +170,34 @@ class LibraryController {
* GET: /api/libraries
* Get all libraries
*
* ?include=stats to load library stats - used in android auto to filter out libraries with no audio
*
* @param {RequestWithUser} req
* @param {Response} res
*/
async findAll(req, res) {
const libraries = await Database.libraryModel.getAllWithFolders()
let libraries = await Database.libraryModel.getAllWithFolders()

const librariesAccessible = req.user.permissions?.librariesAccessible || []
if (librariesAccessible.length) {
return res.json({
libraries: libraries.filter((lib) => librariesAccessible.includes(lib.id)).map((lib) => lib.toOldJSON())
})
libraries = libraries.filter((lib) => librariesAccessible.includes(lib.id))
}

libraries = libraries.map((lib) => lib.toOldJSON())

const includeArray = (req.query.include || '').split(',')
if (includeArray.includes('stats')) {
for (const library of libraries) {
if (library.mediaType === 'book') {
library.stats = await libraryItemsBookFilters.getBookLibraryStats(library.id)
} else if (library.mediaType === 'podcast') {
library.stats = await libraryItemsPodcastFilters.getPodcastLibraryStats(library.id)
}
}
}

res.json({
libraries: libraries.map((lib) => lib.toOldJSON())
libraries
})
}

Expand Down

0 comments on commit 41daf55

Please sign in to comment.