mirror of
				https://github.com/advplyr/audiobookshelf.git
				synced 2025-10-27 11:18:14 +01:00 
			
		
		
		
	Add recent series and authors bookshelf rows on home
This commit is contained in:
		
							parent
							
								
									58dfa65660
								
							
						
					
					
						commit
						c0ff28ffff
					
				@ -217,10 +217,34 @@ export default {
 | 
				
			|||||||
        this.libraryItemUpdated(li)
 | 
					        this.libraryItemUpdated(li)
 | 
				
			||||||
      })
 | 
					      })
 | 
				
			||||||
    },
 | 
					    },
 | 
				
			||||||
 | 
					    authorUpdated(author) {
 | 
				
			||||||
 | 
					      this.shelves.forEach((shelf) => {
 | 
				
			||||||
 | 
					        if (shelf.type == 'authors') {
 | 
				
			||||||
 | 
					          shelf.entities = shelf.entities.map((ent) => {
 | 
				
			||||||
 | 
					            if (ent.id === author.id) {
 | 
				
			||||||
 | 
					              return {
 | 
				
			||||||
 | 
					                ...ent,
 | 
				
			||||||
 | 
					                ...author
 | 
				
			||||||
 | 
					              }
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					            return ent
 | 
				
			||||||
 | 
					          })
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					      })
 | 
				
			||||||
 | 
					    },
 | 
				
			||||||
 | 
					    authorRemoved(author) {
 | 
				
			||||||
 | 
					      this.shelves.forEach((shelf) => {
 | 
				
			||||||
 | 
					        if (shelf.type == 'authors') {
 | 
				
			||||||
 | 
					          shelf.entities = shelf.entities.filter((ent) => ent.id != author.id)
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					      })
 | 
				
			||||||
 | 
					    },
 | 
				
			||||||
    initListeners() {
 | 
					    initListeners() {
 | 
				
			||||||
      this.$store.commit('user/addSettingsListener', { id: 'bookshelf', meth: this.settingsUpdated })
 | 
					      this.$store.commit('user/addSettingsListener', { id: 'bookshelf', meth: this.settingsUpdated })
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      if (this.$root.socket) {
 | 
					      if (this.$root.socket) {
 | 
				
			||||||
 | 
					        this.$root.socket.on('author_updated', this.authorUpdated)
 | 
				
			||||||
 | 
					        this.$root.socket.on('author_removed', this.authorRemoved)
 | 
				
			||||||
        this.$root.socket.on('item_updated', this.libraryItemUpdated)
 | 
					        this.$root.socket.on('item_updated', this.libraryItemUpdated)
 | 
				
			||||||
        this.$root.socket.on('item_added', this.libraryItemAdded)
 | 
					        this.$root.socket.on('item_added', this.libraryItemAdded)
 | 
				
			||||||
        this.$root.socket.on('item_removed', this.libraryItemRemoved)
 | 
					        this.$root.socket.on('item_removed', this.libraryItemRemoved)
 | 
				
			||||||
@ -234,6 +258,8 @@ export default {
 | 
				
			|||||||
      this.$store.commit('user/removeSettingsListener', 'bookshelf')
 | 
					      this.$store.commit('user/removeSettingsListener', 'bookshelf')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      if (this.$root.socket) {
 | 
					      if (this.$root.socket) {
 | 
				
			||||||
 | 
					        this.$root.socket.off('author_updated', this.authorUpdated)
 | 
				
			||||||
 | 
					        this.$root.socket.off('author_removed', this.authorRemoved)
 | 
				
			||||||
        this.$root.socket.off('item_updated', this.libraryItemUpdated)
 | 
					        this.$root.socket.off('item_updated', this.libraryItemUpdated)
 | 
				
			||||||
        this.$root.socket.off('item_added', this.libraryItemAdded)
 | 
					        this.$root.socket.off('item_added', this.libraryItemAdded)
 | 
				
			||||||
        this.$root.socket.off('item_removed', this.libraryItemRemoved)
 | 
					        this.$root.socket.off('item_removed', this.libraryItemRemoved)
 | 
				
			||||||
 | 
				
			|||||||
@ -224,24 +224,6 @@ class LibraryController {
 | 
				
			|||||||
    res.json(payload)
 | 
					    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
 | 
					  // api/libraries/:id/collections
 | 
				
			||||||
  async getCollectionsForLibrary(req, res) {
 | 
					  async getCollectionsForLibrary(req, res) {
 | 
				
			||||||
    var libraryItems = req.libraryItems
 | 
					    var libraryItems = req.libraryItems
 | 
				
			||||||
@ -282,7 +264,6 @@ class LibraryController {
 | 
				
			|||||||
    var minified = req.query.minified === '1'
 | 
					    var minified = req.query.minified === '1'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    var itemsWithUserProgress = libraryHelpers.getItemsWithUserProgress(req.user, libraryItems)
 | 
					    var itemsWithUserProgress = libraryHelpers.getItemsWithUserProgress(req.user, libraryItems)
 | 
				
			||||||
 | 
					 | 
				
			||||||
    var categories = [
 | 
					    var categories = [
 | 
				
			||||||
      {
 | 
					      {
 | 
				
			||||||
        id: 'continue-listening',
 | 
					        id: 'continue-listening',
 | 
				
			||||||
@ -306,6 +287,56 @@ class LibraryController {
 | 
				
			|||||||
      return cats.entities.length
 | 
					      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)
 | 
					    res.json(categories)
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -125,6 +125,11 @@ class BookMetadata {
 | 
				
			|||||||
  hasNarrator(narratorName) {
 | 
					  hasNarrator(narratorName) {
 | 
				
			||||||
    return this.narrators.includes(narratorName)
 | 
					    return this.narrators.includes(narratorName)
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					  getSeriesSequence(seriesId) {
 | 
				
			||||||
 | 
					    var series = this.series.find(se => se.id == seriesId)
 | 
				
			||||||
 | 
					    if (!series) return null
 | 
				
			||||||
 | 
					    return series.sequence || ''
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  update(payload) {
 | 
					  update(payload) {
 | 
				
			||||||
    var json = this.toJSON()
 | 
					    var json = this.toJSON()
 | 
				
			||||||
 | 
				
			|||||||
@ -59,7 +59,6 @@ class ApiRouter {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    this.router.get('/libraries/:id/items', LibraryController.middleware.bind(this), LibraryController.getLibraryItems.bind(this))
 | 
					    this.router.get('/libraries/:id/items', LibraryController.middleware.bind(this), LibraryController.getLibraryItems.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/series/:series', LibraryController.middleware.bind(this), LibraryController.getSeriesForLibrary.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', LibraryController.middleware.bind(this), LibraryController.getLibraryUserPersonalized.bind(this))
 | 
					    this.router.get('/libraries/:id/personalized', LibraryController.middleware.bind(this), LibraryController.getLibraryUserPersonalized.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))
 | 
				
			||||||
 | 
				
			|||||||
@ -98,8 +98,8 @@ module.exports = {
 | 
				
			|||||||
  getSeriesFromBooks(books, minified = false) {
 | 
					  getSeriesFromBooks(books, minified = false) {
 | 
				
			||||||
    var _series = {}
 | 
					    var _series = {}
 | 
				
			||||||
    books.forEach((libraryItem) => {
 | 
					    books.forEach((libraryItem) => {
 | 
				
			||||||
      if (libraryItem.media.metadata.series && libraryItem.media.metadata.series.length) {
 | 
					      var bookSeries = libraryItem.media.metadata.series || []
 | 
				
			||||||
        libraryItem.media.metadata.series.forEach((series) => {
 | 
					      bookSeries.forEach((series) => {
 | 
				
			||||||
        var abJson = minified ? libraryItem.toJSONMinified() : libraryItem.toJSONExpanded()
 | 
					        var abJson = minified ? libraryItem.toJSONMinified() : libraryItem.toJSONExpanded()
 | 
				
			||||||
        abJson.sequence = series.sequence
 | 
					        abJson.sequence = series.sequence
 | 
				
			||||||
        if (!_series[series.id]) {
 | 
					        if (!_series[series.id]) {
 | 
				
			||||||
@ -113,7 +113,6 @@ module.exports = {
 | 
				
			|||||||
          _series[series.id].books.push(abJson)
 | 
					          _series[series.id].books.push(abJson)
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
      })
 | 
					      })
 | 
				
			||||||
      }
 | 
					 | 
				
			||||||
    })
 | 
					    })
 | 
				
			||||||
    return Object.values(_series).map((series) => {
 | 
					    return Object.values(_series).map((series) => {
 | 
				
			||||||
      series.books = naturalSort(series.books).asc(li => li.sequence)
 | 
					      series.books = naturalSort(series.books).asc(li => li.sequence)
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user