mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2025-06-23 09:19:15 +02:00
Fix:Server crash on podcast add page, adds API endpoint to get podcast titles #3499
- Instead of loading all podcast library items this page now loads only the needed data
This commit is contained in:
parent
d258b42e01
commit
33eae1e03a
4 changed files with 47 additions and 11 deletions
|
@ -1226,6 +1226,44 @@ class LibraryController {
|
|||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* GET: /api/libraries/:id/podcast-titles
|
||||
*
|
||||
* Get podcast titles with itunesId and libraryItemId for library
|
||||
* Used on the podcast add page in order to check if a podcast is already in the library and redirect to it
|
||||
*
|
||||
* @param {LibraryControllerRequest} req
|
||||
* @param {Response} res
|
||||
*/
|
||||
async getPodcastTitles(req, res) {
|
||||
if (!req.user.isAdminOrUp) {
|
||||
Logger.error(`[LibraryController] Non-admin user "${req.user.username}" attempted to get podcast titles`)
|
||||
return res.sendStatus(403)
|
||||
}
|
||||
|
||||
const podcasts = await Database.podcastModel.findAll({
|
||||
attributes: ['id', 'title', 'itunesId'],
|
||||
include: {
|
||||
model: Database.libraryItemModel,
|
||||
attributes: ['id', 'libraryId'],
|
||||
where: {
|
||||
libraryId: req.library.id
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
res.json({
|
||||
podcasts: podcasts.map((p) => {
|
||||
return {
|
||||
title: p.title,
|
||||
itunesId: p.itunesId,
|
||||
libraryItemId: p.libraryItem.id,
|
||||
libraryId: p.libraryItem.libraryId
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {RequestWithUser} req
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue