From 8bbfee334c08ece2091e7bcbaa9993d01b538ab3 Mon Sep 17 00:00:00 2001 From: advplyr Date: Sat, 31 Dec 2022 10:33:38 -0600 Subject: [PATCH] Update:Show RSS feed icon on collection card & update API endpoint for fetching collections --- client/components/app/LazyBookshelf.vue | 4 ++-- .../components/cards/LazyCollectionCard.vue | 6 ++++++ client/pages/collection/_id.vue | 4 ++-- server/controllers/LibraryController.js | 21 +++++++++++++------ 4 files changed, 25 insertions(+), 10 deletions(-) diff --git a/client/components/app/LazyBookshelf.vue b/client/components/app/LazyBookshelf.vue index fe3d149c..5e5a25c6 100644 --- a/client/components/app/LazyBookshelf.vue +++ b/client/components/app/LazyBookshelf.vue @@ -318,7 +318,7 @@ export default { const entityPath = this.entityName === 'books' || this.entityName === 'series-books' ? 'items' : this.entityName const sfQueryString = this.currentSFQueryString ? this.currentSFQueryString + '&' : '' - const fullQueryString = `?${sfQueryString}limit=${this.booksPerFetch}&page=${page}&minified=1` + const fullQueryString = `?${sfQueryString}limit=${this.booksPerFetch}&page=${page}&minified=1&include=rssfeed` const payload = await this.$axios.$get(`/api/libraries/${this.currentLibraryId}/${entityPath}${fullQueryString}`).catch((error) => { console.error('failed to fetch books', error) @@ -340,7 +340,7 @@ export default { } for (let i = 0; i < payload.results.length; i++) { - var index = i + startIndex + const index = i + startIndex this.entities[index] = payload.results[i] if (this.entityComponentRefs[index]) { this.entityComponentRefs[index].setEntity(this.entities[index]) diff --git a/client/components/cards/LazyCollectionCard.vue b/client/components/cards/LazyCollectionCard.vue index 407f989b..79189ed1 100644 --- a/client/components/cards/LazyCollectionCard.vue +++ b/client/components/cards/LazyCollectionCard.vue @@ -9,6 +9,9 @@ edit + + rss_feed +

{{ title }}

@@ -72,6 +75,9 @@ export default { }, userCanUpdate() { return this.store.getters['user/getUserCanUpdate'] + }, + rssFeed() { + return this.collection ? this.collection.rssFeed : null } }, methods: { diff --git a/client/pages/collection/_id.vue b/client/pages/collection/_id.vue index 5d69dd80..5e50b674 100644 --- a/client/pages/collection/_id.vue +++ b/client/pages/collection/_id.vue @@ -19,7 +19,7 @@ {{ streaming ? $strings.ButtonPlaying : $strings.ButtonPlay }} - + @@ -124,7 +124,7 @@ export default { action: 'create-playlist' } ] - if (this.userIsAdminOrUp) { + if (this.userIsAdminOrUp || this.rssFeed) { items.push({ text: this.$strings.LabelOpenRSSFeed, action: 'open-rss-feed' diff --git a/server/controllers/LibraryController.js b/server/controllers/LibraryController.js index 5eae1950..f987e060 100644 --- a/server/controllers/LibraryController.js +++ b/server/controllers/LibraryController.js @@ -406,9 +406,11 @@ class LibraryController { // api/libraries/:id/collections async getCollectionsForLibrary(req, res) { - var libraryItems = req.libraryItems + const libraryItems = req.libraryItems - var payload = { + const include = (req.query.include || '').split(',').map(v => v.trim().toLowerCase()).filter(v => !!v) + + const payload = { results: [], total: 0, limit: req.query.limit && !isNaN(req.query.limit) ? Number(req.query.limit) : 0, @@ -416,20 +418,27 @@ class LibraryController { sortBy: req.query.sort, sortDesc: req.query.desc === '1', filterBy: req.query.filter, - minified: req.query.minified === '1' + minified: req.query.minified === '1', + include: include.join(',') } - var collections = this.db.collections.filter(c => c.libraryId === req.library.id).map(c => { - var expanded = c.toJSONExpanded(libraryItems, payload.minified) + let collections = this.db.collections.filter(c => c.libraryId === req.library.id).map(c => { + const expanded = c.toJSONExpanded(libraryItems, payload.minified) + // If all books restricted to user in this collection then hide this collection if (!expanded.books.length && c.books.length) return null + + if (include.includes('rssfeed')) { + expanded.rssFeed = this.rssFeedManager.findFeedForEntityId(c.id) + } + return expanded }).filter(c => !!c) payload.total = collections.length if (payload.limit) { - var startIndex = payload.page * payload.limit + const startIndex = payload.page * payload.limit collections = collections.slice(startIndex, startIndex + payload.limit) }