mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2025-08-03 17:54:54 +02:00
Add LibrarySettings and update edit library modal to include settings tab
This commit is contained in:
parent
cbde451120
commit
5a26b01ffb
12 changed files with 356 additions and 162 deletions
|
@ -9,7 +9,7 @@ const UserCollection = require('./objects/UserCollection')
|
|||
const Library = require('./objects/Library')
|
||||
const Author = require('./objects/entities/Author')
|
||||
const Series = require('./objects/entities/Series')
|
||||
const ServerSettings = require('./objects/ServerSettings')
|
||||
const ServerSettings = require('./objects/settings/ServerSettings')
|
||||
const PlaybackSession = require('./objects/PlaybackSession')
|
||||
|
||||
class Db {
|
||||
|
|
|
@ -69,19 +69,19 @@ class FolderWatcher extends EventEmitter {
|
|||
|
||||
initWatcher(libraries) {
|
||||
libraries.forEach((lib) => {
|
||||
if (!lib.disableWatcher) {
|
||||
if (!lib.settings.disableWatcher) {
|
||||
this.buildLibraryWatcher(lib)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
addLibrary(library) {
|
||||
if (this.disabled || library.disableWatcher) return
|
||||
if (this.disabled || library.settings.disableWatcher) return
|
||||
this.buildLibraryWatcher(library)
|
||||
}
|
||||
|
||||
updateLibrary(library) {
|
||||
if (this.disabled || library.disableWatcher) return
|
||||
if (this.disabled || library.settings.disableWatcher) return
|
||||
var libwatcher = this.libraryWatchers.find(lib => lib.id === library.id)
|
||||
if (libwatcher) {
|
||||
libwatcher.name = library.name
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
const Folder = require('./Folder')
|
||||
const LibrarySettings = require('./settings/LibrarySettings')
|
||||
const { getId } = require('../utils/index')
|
||||
|
||||
class Library {
|
||||
|
@ -10,9 +11,9 @@ class Library {
|
|||
this.icon = 'database' // database, podcast, book, audiobook, comic
|
||||
this.mediaType = 'book' // book, podcast
|
||||
this.provider = 'google'
|
||||
this.disableWatcher = false
|
||||
|
||||
this.lastScan = 0
|
||||
this.settings = null
|
||||
|
||||
this.createdAt = null
|
||||
this.lastUpdate = null
|
||||
|
@ -34,7 +35,11 @@ class Library {
|
|||
this.icon = library.icon || 'database'
|
||||
this.mediaType = library.mediaType
|
||||
this.provider = library.provider || 'google'
|
||||
this.disableWatcher = !!library.disableWatcher
|
||||
|
||||
this.settings = new LibrarySettings(library.settings)
|
||||
if (library.settings === undefined) { // LibrarySettings added in v2, migrate settings
|
||||
this.settings.disableWatcher = !!library.disableWatcher
|
||||
}
|
||||
|
||||
this.createdAt = library.createdAt
|
||||
this.lastUpdate = library.lastUpdate
|
||||
|
@ -62,7 +67,7 @@ class Library {
|
|||
icon: this.icon,
|
||||
mediaType: this.mediaType,
|
||||
provider: this.provider,
|
||||
disableWatcher: this.disableWatcher,
|
||||
settings: this.settings.toJSON(),
|
||||
createdAt: this.createdAt,
|
||||
lastUpdate: this.lastUpdate
|
||||
}
|
||||
|
@ -89,7 +94,7 @@ class Library {
|
|||
this.icon = data.icon || 'database'
|
||||
this.mediaType = data.mediaType || 'book'
|
||||
this.provider = data.provider || 'google'
|
||||
this.disableWatcher = !!data.disableWatcher
|
||||
this.settings = new LibrarySettings(data.settings)
|
||||
this.createdAt = Date.now()
|
||||
this.lastUpdate = Date.now()
|
||||
}
|
||||
|
@ -105,10 +110,10 @@ class Library {
|
|||
}
|
||||
})
|
||||
|
||||
if (payload.disableWatcher !== this.disableWatcher) {
|
||||
this.disableWatcher = !!payload.disableWatcher
|
||||
if (payload.settings && this.settings.update(payload.settings)) {
|
||||
hasUpdates = true
|
||||
}
|
||||
|
||||
if (!isNaN(payload.displayOrder) && payload.displayOrder !== this.displayOrder) {
|
||||
this.displayOrder = Number(payload.displayOrder)
|
||||
hasUpdates = true
|
||||
|
|
34
server/objects/settings/LibrarySettings.js
Normal file
34
server/objects/settings/LibrarySettings.js
Normal file
|
@ -0,0 +1,34 @@
|
|||
const { BookCoverAspectRatio } = require('../../utils/constants')
|
||||
const Logger = require('../../Logger')
|
||||
|
||||
class LibrarySettings {
|
||||
constructor(settings) {
|
||||
this.disableWatcher = false
|
||||
|
||||
if (settings) {
|
||||
this.construct(settings)
|
||||
}
|
||||
}
|
||||
|
||||
construct(settings) {
|
||||
this.disableWatcher = !!settings.disableWatcher
|
||||
}
|
||||
|
||||
toJSON() {
|
||||
return {
|
||||
disableWatcher: this.disableWatcher
|
||||
}
|
||||
}
|
||||
|
||||
update(payload) {
|
||||
var hasUpdates = false
|
||||
for (const key in payload) {
|
||||
if (this[key] !== payload[key]) {
|
||||
this[key] = payload[key]
|
||||
hasUpdates = true
|
||||
}
|
||||
}
|
||||
return hasUpdates
|
||||
}
|
||||
}
|
||||
module.exports = LibrarySettings
|
|
@ -1,5 +1,5 @@
|
|||
const { BookCoverAspectRatio, BookshelfView } = require('../utils/constants')
|
||||
const Logger = require('../Logger')
|
||||
const { BookCoverAspectRatio, BookshelfView } = require('../../utils/constants')
|
||||
const Logger = require('../../Logger')
|
||||
|
||||
class ServerSettings {
|
||||
constructor(settings) {
|
Loading…
Add table
Add a link
Reference in a new issue