diff --git a/client/components/cards/AuthorCard.vue b/client/components/cards/AuthorCard.vue index c30e0f0b..b8106ce9 100644 --- a/client/components/cards/AuthorCard.vue +++ b/client/components/cards/AuthorCard.vue @@ -1,11 +1,11 @@ @@ -38,7 +41,8 @@ export default { sizeMultiplier: { type: Number, default: 1 - } + }, + nameBelow: Boolean }, data() { return { diff --git a/client/pages/item/_id/index.vue b/client/pages/item/_id/index.vue index 82531d2e..156d9f02 100644 --- a/client/pages/item/_id/index.vue +++ b/client/pages/item/_id/index.vue @@ -158,10 +158,11 @@ export default { if (!store.state.user.user) { return redirect(`/login?redirect=${route.path}`) } - var item = await app.$axios.$get(`/api/items/${params.id}?expanded=1`).catch((error) => { + var item = await app.$axios.$get(`/api/items/${params.id}?expanded=1&include=authors`).catch((error) => { console.error('Failed', error) return false }) + console.log(item) if (!item) { console.error('No item...', params.id) return redirect('/') diff --git a/server/controllers/LibraryItemController.js b/server/controllers/LibraryItemController.js index 75b02bf9..483a8bbb 100644 --- a/server/controllers/LibraryItemController.js +++ b/server/controllers/LibraryItemController.js @@ -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) }