Change:Main dir paths moved to global vars, server settings stored in globals vars

This commit is contained in:
advplyr 2022-02-27 13:47:52 -06:00
parent eb109c398f
commit aa50cc2d81
14 changed files with 84 additions and 95 deletions

View file

@ -12,17 +12,14 @@ const Author = require('./objects/Author')
const ServerSettings = require('./objects/ServerSettings')
class Db {
constructor(ConfigPath, AudiobookPath) {
this.ConfigPath = ConfigPath
this.AudiobookPath = AudiobookPath
this.AudiobooksPath = Path.join(ConfigPath, 'audiobooks')
this.UsersPath = Path.join(ConfigPath, 'users')
this.SessionsPath = Path.join(ConfigPath, 'sessions')
this.LibrariesPath = Path.join(ConfigPath, 'libraries')
this.SettingsPath = Path.join(ConfigPath, 'settings')
this.CollectionsPath = Path.join(ConfigPath, 'collections')
this.AuthorsPath = Path.join(ConfigPath, 'authors')
constructor() {
this.AudiobooksPath = Path.join(global.ConfigPath, 'audiobooks')
this.UsersPath = Path.join(global.ConfigPath, 'users')
this.SessionsPath = Path.join(global.ConfigPath, 'sessions')
this.LibrariesPath = Path.join(global.ConfigPath, 'libraries')
this.SettingsPath = Path.join(global.ConfigPath, 'settings')
this.CollectionsPath = Path.join(global.ConfigPath, 'collections')
this.AuthorsPath = Path.join(global.ConfigPath, 'authors')
this.audiobooksDb = new njodb.Database(this.AudiobooksPath)
this.usersDb = new njodb.Database(this.UsersPath)
@ -88,7 +85,7 @@ class Db {
name: 'Main',
folder: { // Generates default folder
id: 'audiobooks',
fullPath: this.AudiobookPath,
fullPath: global.AudiobookPath,
libraryId: 'main'
}
})
@ -127,6 +124,7 @@ class Db {
if (!this.serverSettings) {
this.serverSettings = new ServerSettings()
await this.insertEntity('settings', this.serverSettings)
global.ServerSettings = this.serverSettings.toJSON()
}
}
@ -170,7 +168,7 @@ class Db {
// Update server version in server settings
if (this.previousVersion) {
this.serverSettings.version = version
await this.updateEntity('settings', this.serverSettings)
await this.updateServerSettings()
}
}
@ -201,6 +199,11 @@ class Db {
})
}
updateServerSettings() {
global.ServerSettings = this.serverSettings.toJSON()
return this.updateEntity('settings', this.serverSettings)
}
insertEntities(entityName, entities) {
var entityDb = this.getEntityDb(entityName)
return entityDb.insert(entities).then((results) => {