mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2025-08-30 22:59:37 +02:00
Lazy bookshelf finalized
This commit is contained in:
parent
5c92aef048
commit
1ef9a689bc
53 changed files with 914 additions and 795 deletions
|
@ -42,7 +42,7 @@ class BookController {
|
|||
if (hasUpdates) {
|
||||
await this.db.updateAudiobook(audiobook)
|
||||
}
|
||||
this.emitter('audiobook_updated', audiobook.toJSONMinified())
|
||||
this.emitter('audiobook_updated', audiobook.toJSONExpanded())
|
||||
res.json(audiobook.toJSON())
|
||||
}
|
||||
|
||||
|
@ -118,7 +118,7 @@ class BookController {
|
|||
Logger.info(`[ApiController] ${audiobooksUpdated} Audiobooks have updates`)
|
||||
for (let i = 0; i < audiobooks.length; i++) {
|
||||
await this.db.updateAudiobook(audiobooks[i])
|
||||
this.emitter('audiobook_updated', audiobooks[i].toJSONMinified())
|
||||
this.emitter('audiobook_updated', audiobooks[i].toJSONExpanded())
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -128,6 +128,16 @@ class BookController {
|
|||
})
|
||||
}
|
||||
|
||||
// POST: api/books/batch/get
|
||||
async batchGet(req, res) {
|
||||
var bookIds = req.body.books || []
|
||||
if (!bookIds.length) {
|
||||
return res.status(403).send('Invalid payload')
|
||||
}
|
||||
var audiobooks = this.db.audiobooks.filter(ab => bookIds.includes(ab.id)).map((ab) => ab.toJSONExpanded())
|
||||
res.json(audiobooks)
|
||||
}
|
||||
|
||||
// PATCH: api/books/:id/tracks
|
||||
async updateTracks(req, res) {
|
||||
if (!req.user.canUpdate) {
|
||||
|
@ -140,7 +150,7 @@ class BookController {
|
|||
Logger.info(`Updating audiobook tracks called ${audiobook.id}`)
|
||||
audiobook.updateAudioTracks(orderedFileData)
|
||||
await this.db.updateAudiobook(audiobook)
|
||||
this.emitter('audiobook_updated', audiobook.toJSONMinified())
|
||||
this.emitter('audiobook_updated', audiobook.toJSONExpanded())
|
||||
res.json(audiobook.toJSON())
|
||||
}
|
||||
|
||||
|
@ -184,7 +194,7 @@ class BookController {
|
|||
}
|
||||
|
||||
await this.db.updateAudiobook(audiobook)
|
||||
this.emitter('audiobook_updated', audiobook.toJSONMinified())
|
||||
this.emitter('audiobook_updated', audiobook.toJSONExpanded())
|
||||
res.json({
|
||||
success: true,
|
||||
cover: result.cover
|
||||
|
@ -205,7 +215,7 @@ class BookController {
|
|||
|
||||
if (updated) {
|
||||
await this.db.updateAudiobook(audiobook)
|
||||
this.emitter('audiobook_updated', audiobook.toJSONMinified())
|
||||
this.emitter('audiobook_updated', audiobook.toJSONExpanded())
|
||||
}
|
||||
|
||||
if (updated) res.status(200).send('Cover updated successfully')
|
||||
|
|
|
@ -35,6 +35,7 @@ class LibraryController {
|
|||
var books = this.db.audiobooks.filter(ab => ab.libraryId === req.library.id)
|
||||
return res.json({
|
||||
filterdata: libraryHelpers.getDistinctFilterData(books),
|
||||
issues: libraryHelpers.getNumIssues(books),
|
||||
library: req.library
|
||||
})
|
||||
}
|
||||
|
@ -85,13 +86,6 @@ class LibraryController {
|
|||
getBooksForLibrary(req, res) {
|
||||
var libraryId = req.library.id
|
||||
var audiobooks = this.db.audiobooks.filter(ab => ab.libraryId === libraryId)
|
||||
// if (req.query.q) {
|
||||
// audiobooks = this.db.audiobooks.filter(ab => {
|
||||
// return ab.libraryId === libraryId && ab.isSearchMatch(req.query.q)
|
||||
// }).map(ab => ab.toJSONMinified())
|
||||
// } else {
|
||||
// audiobooks = this.db.audiobooks.filter(ab => ab.libraryId === libraryId).map(ab => ab.toJSONMinified())
|
||||
// }
|
||||
|
||||
if (req.query.filter) {
|
||||
audiobooks = libraryHelpers.getFiltered(audiobooks, req.query.filter, req.user)
|
||||
|
@ -154,13 +148,11 @@ class LibraryController {
|
|||
audiobooks = audiobooks.slice(startIndex, startIndex + payload.limit)
|
||||
}
|
||||
payload.results = audiobooks.map(ab => ab.toJSONExpanded())
|
||||
console.log('returning books', audiobooks.length)
|
||||
|
||||
res.json(payload)
|
||||
}
|
||||
|
||||
// api/libraries/:id/series
|
||||
async getSeriesForLibrary(req, res) {
|
||||
async getAllSeriesForLibrary(req, res) {
|
||||
var audiobooks = this.db.audiobooks.filter(ab => ab.libraryId === req.library.id)
|
||||
|
||||
var payload = {
|
||||
|
@ -182,11 +174,28 @@ class LibraryController {
|
|||
}
|
||||
|
||||
payload.results = series
|
||||
console.log('returning series', series.length)
|
||||
|
||||
res.json(payload)
|
||||
}
|
||||
|
||||
// GET: api/libraries/:id/series/:series
|
||||
async getSeriesForLibrary(req, res) {
|
||||
var series = libraryHelpers.decode(req.params.series)
|
||||
if (!series) {
|
||||
return res.status(403).send('Invalid series')
|
||||
}
|
||||
var audiobooks = this.db.audiobooks.filter(ab => ab.libraryId === req.library.id && ab.book.series === series)
|
||||
if (!audiobooks.length) {
|
||||
return res.status(404).send('Series not found')
|
||||
}
|
||||
audiobooks = sort(audiobooks).asc(ab => {
|
||||
return ab.book.volumeNumber
|
||||
})
|
||||
res.json({
|
||||
results: audiobooks,
|
||||
total: audiobooks.length
|
||||
})
|
||||
}
|
||||
|
||||
// api/libraries/:id/series
|
||||
async getCollectionsForLibrary(req, res) {
|
||||
var audiobooks = this.db.audiobooks.filter(ab => ab.libraryId === req.library.id)
|
||||
|
@ -210,8 +219,6 @@ class LibraryController {
|
|||
}
|
||||
|
||||
payload.results = collections
|
||||
console.log('returning collections', collections.length)
|
||||
|
||||
res.json(payload)
|
||||
}
|
||||
|
||||
|
@ -300,7 +307,7 @@ class LibraryController {
|
|||
if (!req.query.q) {
|
||||
return res.status(400).send('No query string')
|
||||
}
|
||||
var maxResults = req.query.max || 3
|
||||
var maxResults = req.query.limit && !isNaN(req.query.limit) ? Number(req.query.limit) : 12
|
||||
|
||||
var bookMatches = []
|
||||
var authorMatches = {}
|
||||
|
@ -350,13 +357,30 @@ class LibraryController {
|
|||
})
|
||||
}
|
||||
})
|
||||
|
||||
res.json({
|
||||
var results = {
|
||||
audiobooks: bookMatches.slice(0, maxResults),
|
||||
tags: Object.values(tagMatches).slice(0, maxResults),
|
||||
authors: Object.values(authorMatches).slice(0, maxResults),
|
||||
series: Object.values(seriesMatches).slice(0, maxResults)
|
||||
})
|
||||
}
|
||||
res.json(results)
|
||||
}
|
||||
|
||||
async stats(req, res) {
|
||||
var audiobooksInLibrary = this.db.audiobooks.filter(ab => ab.libraryId === req.library.id)
|
||||
|
||||
var authorsWithCount = libraryHelpers.getAuthorsWithCount(audiobooksInLibrary)
|
||||
var genresWithCount = libraryHelpers.getGenresWithCount(audiobooksInLibrary)
|
||||
var stats = {
|
||||
totalBooks: audiobooksInLibrary.length,
|
||||
totalAuthors: Object.keys(authorsWithCount).length,
|
||||
totalGenres: Object.keys(genresWithCount).length,
|
||||
totalDuration: libraryHelpers.getAudiobooksTotalDuration(audiobooksInLibrary),
|
||||
totalSize: libraryHelpers.getAudiobooksTotalSize(audiobooksInLibrary),
|
||||
authorsWithCount,
|
||||
genresWithCount
|
||||
}
|
||||
res.json(stats)
|
||||
}
|
||||
|
||||
middleware(req, res, next) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue