mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2025-08-04 02:05:06 +02:00
Fix use first accessible library depending on display order, default library id checked on server when authenticating
This commit is contained in:
parent
0dd219f303
commit
08e1782253
7 changed files with 22 additions and 24 deletions
|
@ -120,7 +120,7 @@ class Auth {
|
|||
if (password) {
|
||||
return res.status(401).send('Invalid root password (hint: there is none)')
|
||||
} else {
|
||||
return res.json({ user: user.toJSONForBrowser() })
|
||||
return res.json({ user: user.toJSONForBrowser(), userDefaultLibraryId: user.getDefaultLibraryId(this.db.libraries) })
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -128,7 +128,8 @@ class Auth {
|
|||
var compare = await bcrypt.compare(password, user.pash)
|
||||
if (compare) {
|
||||
res.json({
|
||||
user: user.toJSONForBrowser()
|
||||
user: user.toJSONForBrowser(),
|
||||
userDefaultLibraryId: user.getDefaultLibraryId(this.db.libraries)
|
||||
})
|
||||
} else {
|
||||
Logger.debug(`[Auth] Failed login attempt ${req.rateLimit.current} of ${req.rateLimit.limit}`)
|
||||
|
|
|
@ -146,6 +146,7 @@ class Db {
|
|||
})
|
||||
var p3 = this.librariesDb.select(() => true).then((results) => {
|
||||
this.libraries = results.data.map(l => new Library(l))
|
||||
this.libraries.sort((a, b) => a.displayOrder - b.displayOrder)
|
||||
Logger.info(`[DB] ${this.libraries.length} Libraries Loaded`)
|
||||
})
|
||||
var p4 = this.settingsDb.select(() => true).then((results) => {
|
||||
|
|
|
@ -381,9 +381,10 @@ class LibraryController {
|
|||
}
|
||||
|
||||
if (hasUpdates) {
|
||||
Logger.info(`[LibraryController] Updated library display orders`)
|
||||
this.db.libraries.sort((a, b) => a.displayOrder - b.displayOrder)
|
||||
Logger.debug(`[LibraryController] Updated library display orders`)
|
||||
} else {
|
||||
Logger.info(`[LibraryController] Library orders were up to date`)
|
||||
Logger.debug(`[LibraryController] Library orders were up to date`)
|
||||
}
|
||||
|
||||
var libraries = this.db.libraries.map(lib => lib.toJSON())
|
||||
|
|
|
@ -168,7 +168,7 @@ class MiscController {
|
|||
Logger.error('Invalid user in authorize')
|
||||
return res.sendStatus(401)
|
||||
}
|
||||
res.json({ user: req.user })
|
||||
res.json({ user: req.user, userDefaultLibraryId: req.user.getDefaultLibraryId(this.db.libraries) })
|
||||
}
|
||||
|
||||
getAllTags(req, res) {
|
||||
|
|
|
@ -223,6 +223,13 @@ class User {
|
|||
return hasUpdates
|
||||
}
|
||||
|
||||
getDefaultLibraryId(libraries) {
|
||||
// Libraries should already be in ascending display order, find first accessible
|
||||
var firstAccessibleLibrary = libraries.find(lib => this.checkCanAccessLibrary(lib.id))
|
||||
if (!firstAccessibleLibrary) return null
|
||||
return firstAccessibleLibrary.id
|
||||
}
|
||||
|
||||
getMostRecentItemProgress(libraryItems) {
|
||||
if (!this.mediaProgress.length) return null
|
||||
var lip = this.mediaProgress.map(lip => lip.toJSON())
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue