mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2025-06-23 01:09:26 +02:00
Add recent series and authors bookshelf rows on home
This commit is contained in:
parent
58dfa65660
commit
c0ff28ffff
5 changed files with 95 additions and 35 deletions
|
@ -224,24 +224,6 @@ class LibraryController {
|
|||
res.json(payload)
|
||||
}
|
||||
|
||||
// GET: api/libraries/:id/series/:series
|
||||
async getSeriesForLibrary(req, res) {
|
||||
if (!req.params.series) {
|
||||
return res.status(403).send('Invalid series')
|
||||
}
|
||||
var libraryItems = this.db.libraryItems.filter(li => {
|
||||
return li.libraryId === req.library.id && li.book.series === req.params.series
|
||||
})
|
||||
if (!libraryItems.length) {
|
||||
return res.status(404).send('Series not found')
|
||||
}
|
||||
var sortedBooks = libraryHelpers.sortSeriesBooks(libraryItems, false)
|
||||
res.json({
|
||||
results: sortedBooks,
|
||||
total: libraryItems.length
|
||||
})
|
||||
}
|
||||
|
||||
// api/libraries/:id/collections
|
||||
async getCollectionsForLibrary(req, res) {
|
||||
var libraryItems = req.libraryItems
|
||||
|
@ -282,7 +264,6 @@ class LibraryController {
|
|||
var minified = req.query.minified === '1'
|
||||
|
||||
var itemsWithUserProgress = libraryHelpers.getItemsWithUserProgress(req.user, libraryItems)
|
||||
|
||||
var categories = [
|
||||
{
|
||||
id: 'continue-listening',
|
||||
|
@ -306,6 +287,56 @@ class LibraryController {
|
|||
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
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
res.json(categories)
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue