mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2025-01-17 03:19:40 +01:00
Remove old home page personalized API route
This commit is contained in:
parent
ceb163570f
commit
b19442e440
@ -201,7 +201,6 @@ class LibraryController {
|
|||||||
libraryItems = naturalSort(libraryItems).by(sortArray)
|
libraryItems = naturalSort(libraryItems).by(sortArray)
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Potentially implement collapse series again
|
|
||||||
if (payload.collapseseries) {
|
if (payload.collapseseries) {
|
||||||
libraryItems = libraryHelpers.collapseBookSeries(libraryItems)
|
libraryItems = libraryHelpers.collapseBookSeries(libraryItems)
|
||||||
payload.total = libraryItems.length
|
payload.total = libraryItems.length
|
||||||
@ -319,102 +318,6 @@ class LibraryController {
|
|||||||
res.json(categories)
|
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
|
// PATCH: Change the order of libraries
|
||||||
async reorder(req, res) {
|
async reorder(req, res) {
|
||||||
if (!req.user.isRoot) {
|
if (!req.user.isRoot) {
|
||||||
|
@ -61,7 +61,6 @@ class ApiRouter {
|
|||||||
this.router.delete('/libraries/:id/issues', LibraryController.middleware.bind(this), LibraryController.removeLibraryItemsWithIssues.bind(this))
|
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/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/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/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/filterdata', LibraryController.middleware.bind(this), LibraryController.getLibraryFilterData.bind(this))
|
||||||
this.router.get('/libraries/:id/search', LibraryController.middleware.bind(this), LibraryController.search.bind(this))
|
this.router.get('/libraries/:id/search', LibraryController.middleware.bind(this), LibraryController.search.bind(this))
|
||||||
|
@ -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) {
|
getBooksNextInSeries(seriesWithUserAb, limit, minified = false) {
|
||||||
var incompleteSeires = seriesWithUserAb.filter((series) => series.books.some((book) => !book.userAudiobook || (!book.userAudiobook.isRead && book.userAudiobook.progress == 0)))
|
var incompleteSeires = seriesWithUserAb.filter((series) => series.books.some((book) => !book.userAudiobook || (!book.userAudiobook.isRead && book.userAudiobook.progress == 0)))
|
||||||
var booksNextInSeries = []
|
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)
|
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) {
|
getGenresWithCount(libraryItems) {
|
||||||
var genresMap = {}
|
var genresMap = {}
|
||||||
libraryItems.forEach((li) => {
|
libraryItems.forEach((li) => {
|
||||||
@ -354,7 +237,6 @@ module.exports = {
|
|||||||
buildPersonalizedShelves(user, libraryItems, mediaType, allSeries, allAuthors, maxEntitiesPerShelf = 10) {
|
buildPersonalizedShelves(user, libraryItems, mediaType, allSeries, allAuthors, maxEntitiesPerShelf = 10) {
|
||||||
const isPodcastLibrary = mediaType === 'podcast'
|
const isPodcastLibrary = mediaType === 'podcast'
|
||||||
|
|
||||||
|
|
||||||
const shelves = [
|
const shelves = [
|
||||||
{
|
{
|
||||||
id: 'continue-listening',
|
id: 'continue-listening',
|
||||||
|
Loading…
Reference in New Issue
Block a user