mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2025-06-23 09:19:15 +02:00
Add:Library route quick match all books
This commit is contained in:
parent
088969e1fe
commit
c953c3dee0
4 changed files with 87 additions and 52 deletions
|
@ -334,7 +334,7 @@ class LibraryController {
|
|||
async reorder(req, res) {
|
||||
if (!req.user.isRoot) {
|
||||
Logger.error('[ApiController] ReorderLibraries invalid user', req.user)
|
||||
return res.sendStatus(401)
|
||||
return res.sendStatus(403)
|
||||
}
|
||||
|
||||
var orderdata = req.body
|
||||
|
@ -470,6 +470,35 @@ class LibraryController {
|
|||
res.json(Object.values(authors))
|
||||
}
|
||||
|
||||
async matchBooks(req, res) {
|
||||
if (!req.user.isRoot) {
|
||||
Logger.error(`[LibraryController] Non-root user attempted to match library books`, req.user)
|
||||
return res.sendStatus(403)
|
||||
}
|
||||
res.sendStatus(200)
|
||||
|
||||
const provider = req.library.provider || 'google'
|
||||
var audiobooksInLibrary = this.db.audiobooks.filter(ab => ab.libraryId === req.library.id)
|
||||
const resultPayload = {
|
||||
library: library.toJSON(),
|
||||
total: audiobooksInLibrary.length,
|
||||
updated: 0
|
||||
}
|
||||
|
||||
for (let i = 0; i < audiobooksInLibrary.length; i++) {
|
||||
var audiobook = audiobooksInLibrary[i]
|
||||
Logger.debug(`[LibraryController] matchBooks quick matching "${audiobook.title}" (${i + 1} of ${audiobooksInLibrary.length})`)
|
||||
var result = await this.quickMatchBook(audiobook, { provider })
|
||||
if (result.warning) {
|
||||
Logger.warn(`[LibraryController] matchBooks warning ${result.warning} for audiobook "${audiobook.title}"`)
|
||||
} else if (result.updated) {
|
||||
resultPayload.updated++
|
||||
}
|
||||
}
|
||||
|
||||
this.clientEmitter(req.usr.id, 'library-match-results', resultPayload)
|
||||
}
|
||||
|
||||
middleware(req, res, next) {
|
||||
var librariesAccessible = req.user.librariesAccessible || []
|
||||
if (librariesAccessible && librariesAccessible.length && !librariesAccessible.includes(req.params.id)) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue