mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2025-01-03 00:06:46 +01: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
@ -1,14 +1,11 @@
|
|||||||
<template>
|
<template>
|
||||||
<ui-tooltip v-if="alreadyInLibrary" :text="$strings.LabelAlreadyInYourLibrary" direction="top">
|
<ui-tooltip :text="$strings.LabelAlreadyInYourLibrary" direction="top" class="inline-flex">
|
||||||
<span class="material-symbols ml-1 text-success" style="font-size: 0.8rem">check_circle</span>
|
<span class="material-symbols ml-1 text-sm text-success">check_circle</span>
|
||||||
</ui-tooltip>
|
</ui-tooltip>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
export default {
|
export default {
|
||||||
props: {
|
|
||||||
alreadyInLibrary: Boolean
|
|
||||||
},
|
|
||||||
data() {
|
data() {
|
||||||
return {}
|
return {}
|
||||||
},
|
},
|
||||||
|
@ -22,7 +22,7 @@
|
|||||||
<div class="flex items-center">
|
<div class="flex items-center">
|
||||||
<a :href="podcast.pageUrl" class="text-base md:text-lg text-gray-200 hover:underline" target="_blank" @click.stop>{{ podcast.title }}</a>
|
<a :href="podcast.pageUrl" class="text-base md:text-lg text-gray-200 hover:underline" target="_blank" @click.stop>{{ podcast.title }}</a>
|
||||||
<widgets-explicit-indicator v-if="podcast.explicit" />
|
<widgets-explicit-indicator v-if="podcast.explicit" />
|
||||||
<widgets-already-in-library-indicator :already-in-library="podcast.alreadyInLibrary" />
|
<widgets-already-in-library-indicator v-if="podcast.alreadyInLibrary" />
|
||||||
</div>
|
</div>
|
||||||
<p class="text-sm md:text-base text-gray-300 whitespace-nowrap truncate">{{ $getString('LabelByAuthor', [podcast.artistName]) }}</p>
|
<p class="text-sm md:text-base text-gray-300 whitespace-nowrap truncate">{{ $getString('LabelByAuthor', [podcast.artistName]) }}</p>
|
||||||
<p class="text-xs text-gray-400 leading-5">{{ podcast.genres.join(', ') }}</p>
|
<p class="text-xs text-gray-400 leading-5">{{ podcast.genres.join(', ') }}</p>
|
||||||
@ -211,15 +211,15 @@ export default {
|
|||||||
async fetchExistentPodcastsInYourLibrary() {
|
async fetchExistentPodcastsInYourLibrary() {
|
||||||
this.processing = true
|
this.processing = true
|
||||||
|
|
||||||
const podcasts = await this.$axios.$get(`/api/libraries/${this.currentLibraryId}/items?page=0&minified=1`).catch((error) => {
|
const podcastsResponse = await this.$axios.$get(`/api/libraries/${this.currentLibraryId}/podcast-titles`).catch((error) => {
|
||||||
console.error('Failed to fetch podcasts', error)
|
console.error('Failed to fetch podcasts', error)
|
||||||
return []
|
return []
|
||||||
})
|
})
|
||||||
this.existentPodcasts = podcasts.results.map((p) => {
|
this.existentPodcasts = podcastsResponse.podcasts.map((p) => {
|
||||||
return {
|
return {
|
||||||
title: p.media.metadata.title.toLowerCase(),
|
title: p.title.toLowerCase(),
|
||||||
itunesId: p.media.metadata.itunesId,
|
itunesId: p.itunesId,
|
||||||
id: p.id
|
id: p.libraryItemId
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
this.processing = false
|
this.processing = false
|
||||||
|
@ -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
|
* @param {RequestWithUser} req
|
||||||
|
@ -96,6 +96,7 @@ class ApiRouter {
|
|||||||
this.router.get('/libraries/:id/opml', LibraryController.middleware.bind(this), LibraryController.getOPMLFile.bind(this))
|
this.router.get('/libraries/:id/opml', LibraryController.middleware.bind(this), LibraryController.getOPMLFile.bind(this))
|
||||||
this.router.post('/libraries/order', LibraryController.reorder.bind(this))
|
this.router.post('/libraries/order', LibraryController.reorder.bind(this))
|
||||||
this.router.post('/libraries/:id/remove-metadata', LibraryController.middleware.bind(this), LibraryController.removeAllMetadataFiles.bind(this))
|
this.router.post('/libraries/:id/remove-metadata', LibraryController.middleware.bind(this), LibraryController.removeAllMetadataFiles.bind(this))
|
||||||
|
this.router.get('/libraries/:id/podcast-titles', LibraryController.middleware.bind(this), LibraryController.getPodcastTitles.bind(this))
|
||||||
|
|
||||||
//
|
//
|
||||||
// Item Routes
|
// Item Routes
|
||||||
|
Loading…
Reference in New Issue
Block a user