mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2025-06-24 17:59:06 +02:00
Add expand library item authors to /items/:id route
This commit is contained in:
parent
e1e6b46456
commit
28d76d21f1
3 changed files with 28 additions and 5 deletions
|
@ -5,8 +5,26 @@ const { ScanResult } = require('../utils/constants')
|
|||
class LibraryItemController {
|
||||
constructor() { }
|
||||
|
||||
// Example expand with authors: api/items/:id?expanded=1&include=authors
|
||||
findOne(req, res) {
|
||||
if (req.query.expanded == 1) return res.json(req.libraryItem.toJSONExpanded())
|
||||
const includeEntities = (req.query.include || '').split(',')
|
||||
if (req.query.expanded == 1) {
|
||||
var item = req.libraryItem.toJSONExpanded()
|
||||
|
||||
if (item.mediaType == 'book') {
|
||||
if (includeEntities.includes('authors')) {
|
||||
item.media.metadata.authors = item.media.metadata.authors.map(au => {
|
||||
var author = this.db.authors.find(_au => _au.id === au.id)
|
||||
if (!author) return null
|
||||
return {
|
||||
...author
|
||||
}
|
||||
}).filter(au => au)
|
||||
}
|
||||
}
|
||||
|
||||
return res.json(item)
|
||||
}
|
||||
res.json(req.libraryItem)
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue