From b19442e4409665a591d940fec0b41acf22c054ad Mon Sep 17 00:00:00 2001 From: advplyr Date: Sat, 30 Apr 2022 11:36:05 -0500 Subject: [PATCH] Remove old home page personalized API route --- server/controllers/LibraryController.js | 97 ------------------- server/routers/ApiRouter.js | 1 - server/utils/libraryHelpers.js | 118 ------------------------ 3 files changed, 216 deletions(-) diff --git a/server/controllers/LibraryController.js b/server/controllers/LibraryController.js index 3a23ba21..2548f5a8 100644 --- a/server/controllers/LibraryController.js +++ b/server/controllers/LibraryController.js @@ -201,7 +201,6 @@ class LibraryController { libraryItems = naturalSort(libraryItems).by(sortArray) } - // TODO: Potentially implement collapse series again if (payload.collapseseries) { libraryItems = libraryHelpers.collapseBookSeries(libraryItems) payload.total = libraryItems.length @@ -319,102 +318,6 @@ class LibraryController { res.json(categories) } - // TODO: Remove old personalized function with all its helper functions - // old personalized function looped through the library items many times - // api/libraries/:id/personalized-old - async getLibraryUserPersonalized(req, res) { - var mediaType = req.library.mediaType - var isPodcastLibrary = mediaType == 'podcast' - var libraryItems = req.libraryItems - var limitPerShelf = req.query.limit && !isNaN(req.query.limit) ? Number(req.query.limit) : 12 - var minified = req.query.minified == '1' - - var itemsWithUserProgress = libraryHelpers.getMediaProgressWithItems(req.user, libraryItems) - var categories = [ - { - id: 'continue-listening', - label: 'Continue Listening', - type: isPodcastLibrary ? 'episode' : req.library.mediaType, - entities: libraryHelpers.getItemsMostRecentlyListened(itemsWithUserProgress, limitPerShelf, minified) - }, - { - id: 'recently-added', - label: 'Recently Added', - type: req.library.mediaType, - entities: libraryHelpers.getItemsMostRecentlyAdded(libraryItems, limitPerShelf, minified) - }, - { - id: 'listen-again', - label: 'Listen Again', - type: isPodcastLibrary ? 'episode' : req.library.mediaType, - entities: libraryHelpers.getItemsMostRecentlyFinished(itemsWithUserProgress, limitPerShelf, minified) - } - ].filter(cats => { // Remove categories with no items - return cats.entities.length - }) - - // New Series section - // TODO: optimize and move to libraryHelpers - if (!isPodcastLibrary) { - var series = this.db.series.map(se => { - var books = libraryItems.filter(li => li.media.metadata.hasSeries(se.id)) - if (!books.length) return null - books = books.map(b => { - var json = b.toJSONMinified() - json.sequence = b.media.metadata.getSeriesSequence(se.id) - return json - }) - books = naturalSort(books).asc(b => b.sequence) - return { - id: se.id, - name: se.name, - type: 'series', - addedAt: se.addedAt, - books - } - }).filter(se => se).sort((a, b) => a.addedAt - b.addedAt).slice(0, 5) - - if (series.length) { - categories.push({ - id: 'recent-series', - label: 'Recent Series', - type: 'series', - entities: series - }) - } - - var authors = this.db.authors.map(author => { - var books = libraryItems.filter(li => li.media.metadata.hasAuthor(author.id)) - if (!books.length) return null - // books = books.map(b => b.toJSONMinified()) - return { - ...author.toJSON(), - numBooks: books.length - } - }).filter(au => au).sort((a, b) => a.addedAt - b.addedAt).slice(0, 10) - if (authors.length) { - categories.push({ - id: 'newest-authors', - label: 'Newest Authors', - type: 'authors', - entities: authors - }) - } - } else { - var episodesRecentlyAdded = libraryHelpers.getEpisodesRecentlyAdded(libraryItems, limitPerShelf, minified) - if (episodesRecentlyAdded.length) { - categories.splice(1, 0, { - id: 'episodes-recently-added', - label: 'Newest Episodes', - type: 'episode', - entities: episodesRecentlyAdded - }) - } - } - - res.json(categories) - } - // PATCH: Change the order of libraries async reorder(req, res) { if (!req.user.isRoot) { diff --git a/server/routers/ApiRouter.js b/server/routers/ApiRouter.js index ad29a3bd..e322a476 100644 --- a/server/routers/ApiRouter.js +++ b/server/routers/ApiRouter.js @@ -61,7 +61,6 @@ class ApiRouter { this.router.delete('/libraries/:id/issues', LibraryController.middleware.bind(this), LibraryController.removeLibraryItemsWithIssues.bind(this)) this.router.get('/libraries/:id/series', LibraryController.middleware.bind(this), LibraryController.getAllSeriesForLibrary.bind(this)) this.router.get('/libraries/:id/collections', LibraryController.middleware.bind(this), LibraryController.getCollectionsForLibrary.bind(this)) - this.router.get('/libraries/:id/personalized-old', LibraryController.middleware.bind(this), LibraryController.getLibraryUserPersonalized.bind(this)) this.router.get('/libraries/:id/personalized', LibraryController.middleware.bind(this), LibraryController.getLibraryUserPersonalizedOptimal.bind(this)) this.router.get('/libraries/:id/filterdata', LibraryController.middleware.bind(this), LibraryController.getLibraryFilterData.bind(this)) this.router.get('/libraries/:id/search', LibraryController.middleware.bind(this), LibraryController.search.bind(this)) diff --git a/server/utils/libraryHelpers.js b/server/utils/libraryHelpers.js index 2860e086..67db7cda 100644 --- a/server/utils/libraryHelpers.js +++ b/server/utils/libraryHelpers.js @@ -136,80 +136,6 @@ module.exports = { }) }, - getSeriesWithProgressFromBooks(user, books) { - return [] - // var _series = {} - // books.forEach((audiobook) => { - // if (audiobook.book.series) { - // var bookWithUserAb = { userAudiobook: user.getMediaProgress(audiobook.id), book: audiobook } - // if (!_series[audiobook.book.series]) { - // _series[audiobook.book.series] = { - // id: audiobook.book.series, - // name: audiobook.book.series, - // type: 'series', - // books: [bookWithUserAb] - // } - // } else { - // _series[audiobook.book.series].books.push(bookWithUserAb) - // } - // } - // }) - // return Object.values(_series).map((series) => { - // series.books = naturalSort(series.books).asc(ab => ab.book.book.volumeNumber) - // return series - // }).filter((series) => series.books.some((book) => book.userAudiobook && book.userAudiobook.isRead)) - }, - - sortSeriesBooks(books, seriesId, minified = false) { - return naturalSort(books).asc(li => { - if (!li.media.metadata.series) return null - var series = li.media.metadata.series.find(se => se.id === seriesId) - if (!series) return null - return series.sequence - }).map(li => { - if (minified) return li.toJSONMinified() - return li.toJSONExpanded() - }) - }, - - getMediaProgressWithItems(user, libraryItems) { - var mediaProgress = [] - libraryItems.forEach(li => { - var itemProgress = user.getAllMediaProgressForLibraryItem(li.id).map(mp => { - var episode = null - if (mp.episodeId) { - episode = li.media.getEpisode(mp.episodeId) - if (!episode) { - // Episode not found for library item - return null - } - } - return { - userProgress: mp.toJSON(), - libraryItem: li, - episode - } - }).filter(mp => !!mp) - - mediaProgress = mediaProgress.concat(itemProgress) - }) - return mediaProgress - }, - - getItemsMostRecentlyListened(itemsWithUserProgress, limit, minified = false) { - var itemsInProgress = itemsWithUserProgress.filter((data) => data.userProgress && data.userProgress.progress > 0 && !data.userProgress.isFinished) - itemsInProgress.sort((a, b) => { - return b.userProgress.lastUpdate - a.userProgress.lastUpdate - }) - return itemsInProgress.map(b => { - var libjson = minified ? b.libraryItem.toJSONMinified() : b.libraryItem.toJSONExpanded() - if (b.episode) { - libjson.recentEpisode = b.episode - } - return libjson - }).slice(0, limit) - }, - getBooksNextInSeries(seriesWithUserAb, limit, minified = false) { var incompleteSeires = seriesWithUserAb.filter((series) => series.books.some((book) => !book.userAudiobook || (!book.userAudiobook.isRead && book.userAudiobook.progress == 0))) var booksNextInSeries = [] @@ -222,49 +148,6 @@ module.exports = { return booksNextInSeries.sort((a, b) => { return b.DateLastReadSeries - a.DateLastReadSeries }).map(b => minified ? b.book.toJSONMinified() : b.book.toJSONExpanded()).slice(0, limit) }, - getItemsMostRecentlyFinished(itemsWithUserProgress, limit, minified = false) { - var itemsFinished = itemsWithUserProgress.filter((data) => data.userProgress && data.userProgress.isFinished) - itemsFinished.sort((a, b) => { - return b.userProgress.finishedAt - a.userProgress.finishedAt - }) - return itemsFinished.map(i => { - var libjson = minified ? i.libraryItem.toJSONMinified() : i.libraryItem.toJSONExpanded() - if (i.episode) { - libjson.recentEpisode = i.episode - } - return libjson - }).slice(0, limit) - }, - - getItemsMostRecentlyAdded(libraryItems, limit, minified = false) { - var itemsSortedByAddedAt = sort(libraryItems).desc(li => li.addedAt) - return itemsSortedByAddedAt.map(b => minified ? b.toJSONMinified() : b.toJSONExpanded()).slice(0, limit) - }, - - getEpisodesRecentlyAdded(libraryItems, limit, minified = false) { - var libraryItemsWithEpisode = [] - libraryItems.forEach((li) => { - if (li.mediaType !== 'podcast' || !li.media.hasMediaEntities) return - var libjson = minified ? li.toJSONMinified() : li.toJSONExpanded() - var episodes = sort(li.media.episodes || []).desc(ep => ep.addedAt) - episodes.forEach((ep) => { - var lie = { ...libjson } - lie.recentEpisode = ep - libraryItemsWithEpisode.push(lie) - }) - }) - libraryItemsWithEpisode = sort(libraryItemsWithEpisode).desc(lie => lie.recentEpisode.addedAt) - return libraryItemsWithEpisode.slice(0, limit) - }, - - getSeriesMostRecentlyAdded(series, limit) { - var seriesSortedByAddedAt = sort(series).desc(_series => { - var booksSortedByMostRecent = sort(_series.books).desc(b => b.addedAt) - return booksSortedByMostRecent[0].addedAt - }) - return seriesSortedByAddedAt.slice(0, limit) - }, - getGenresWithCount(libraryItems) { var genresMap = {} libraryItems.forEach((li) => { @@ -354,7 +237,6 @@ module.exports = { buildPersonalizedShelves(user, libraryItems, mediaType, allSeries, allAuthors, maxEntitiesPerShelf = 10) { const isPodcastLibrary = mediaType === 'podcast' - const shelves = [ { id: 'continue-listening',