mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2025-02-01 00:18:14 +01:00
Update get library item api endpoint to remove unnecessary authors include query param
This commit is contained in:
parent
1b1bdea3c8
commit
7567e91878
@ -160,7 +160,7 @@ export default {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Include episode downloads for podcasts
|
// Include episode downloads for podcasts
|
||||||
var item = await app.$axios.$get(`/api/items/${params.id}?expanded=1&include=authors,downloads,rssfeed`).catch((error) => {
|
var item = await app.$axios.$get(`/api/items/${params.id}?expanded=1&include=downloads,rssfeed`).catch((error) => {
|
||||||
console.error('Failed', error)
|
console.error('Failed', error)
|
||||||
return false
|
return false
|
||||||
})
|
})
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
|
const sequelize = require('sequelize')
|
||||||
const fs = require('../libs/fsExtra')
|
const fs = require('../libs/fsExtra')
|
||||||
const { createNewSortInstance } = require('../libs/fastSort')
|
const { createNewSortInstance } = require('../libs/fastSort')
|
||||||
|
|
||||||
@ -93,7 +93,18 @@ class AuthorController {
|
|||||||
const authorNameUpdate = payload.name !== undefined && payload.name !== req.author.name
|
const authorNameUpdate = payload.name !== undefined && payload.name !== req.author.name
|
||||||
|
|
||||||
// Check if author name matches another author and merge the authors
|
// Check if author name matches another author and merge the authors
|
||||||
const existingAuthor = authorNameUpdate ? Database.authors.find(au => au.id !== req.author.id && payload.name === au.name) : false
|
let existingAuthor = null
|
||||||
|
if (authorNameUpdate) {
|
||||||
|
const author = await Database.authorModel.findOne({
|
||||||
|
where: {
|
||||||
|
id: {
|
||||||
|
[sequelize.Op.not]: req.author.id
|
||||||
|
},
|
||||||
|
name: payload.name
|
||||||
|
}
|
||||||
|
})
|
||||||
|
existingAuthor = author?.getOldAuthor()
|
||||||
|
}
|
||||||
if (existingAuthor) {
|
if (existingAuthor) {
|
||||||
const bookAuthorsToCreate = []
|
const bookAuthorsToCreate = []
|
||||||
const itemsWithAuthor = await Database.libraryItemModel.getForAuthor(req.author)
|
const itemsWithAuthor = await Database.libraryItemModel.getForAuthor(req.author)
|
||||||
|
@ -12,7 +12,15 @@ const { getAudioMimeTypeFromExtname } = require('../utils/fileUtils')
|
|||||||
class LibraryItemController {
|
class LibraryItemController {
|
||||||
constructor() { }
|
constructor() { }
|
||||||
|
|
||||||
// Example expand with authors: api/items/:id?expanded=1&include=authors
|
/**
|
||||||
|
* GET: /api/items/:id
|
||||||
|
* Optional query params:
|
||||||
|
* ?include=progress,rssfeed,downloads
|
||||||
|
* ?expanded=1
|
||||||
|
*
|
||||||
|
* @param {import('express').Request} req
|
||||||
|
* @param {import('express').Response} res
|
||||||
|
*/
|
||||||
async findOne(req, res) {
|
async findOne(req, res) {
|
||||||
const includeEntities = (req.query.include || '').split(',')
|
const includeEntities = (req.query.include || '').split(',')
|
||||||
if (req.query.expanded == 1) {
|
if (req.query.expanded == 1) {
|
||||||
@ -29,17 +37,7 @@ class LibraryItemController {
|
|||||||
item.rssFeed = feedData?.toJSONMinified() || null
|
item.rssFeed = feedData?.toJSONMinified() || null
|
||||||
}
|
}
|
||||||
|
|
||||||
if (item.mediaType == 'book') {
|
if (item.mediaType === 'podcast' && includeEntities.includes('downloads')) {
|
||||||
if (includeEntities.includes('authors')) {
|
|
||||||
item.media.metadata.authors = item.media.metadata.authors.map(au => {
|
|
||||||
var author = Database.authors.find(_au => _au.id === au.id)
|
|
||||||
if (!author) return null
|
|
||||||
return {
|
|
||||||
...author
|
|
||||||
}
|
|
||||||
}).filter(au => au)
|
|
||||||
}
|
|
||||||
} else if (includeEntities.includes('downloads')) {
|
|
||||||
const downloadsInQueue = this.podcastManager.getEpisodeDownloadsInQueue(req.libraryItem.id)
|
const downloadsInQueue = this.podcastManager.getEpisodeDownloadsInQueue(req.libraryItem.id)
|
||||||
item.episodeDownloadsQueued = downloadsInQueue.map(d => d.toJSONForClient())
|
item.episodeDownloadsQueued = downloadsInQueue.map(d => d.toJSONForClient())
|
||||||
if (this.podcastManager.currentDownload?.libraryItemId === req.libraryItem.id) {
|
if (this.podcastManager.currentDownload?.libraryItemId === req.libraryItem.id) {
|
||||||
|
Loading…
Reference in New Issue
Block a user