Convert content to use database instead of individual configs
This commit is contained in:
parent
30a886d84a
commit
8d33d80e1c
|
@ -10,6 +10,7 @@
|
|||
|
||||
import { Utils, FileUtils, ClientLogger as Logger, AsyncEventEmitter } from 'common';
|
||||
import { Modals } from 'ui';
|
||||
import Database from './database';
|
||||
|
||||
export default class Content {
|
||||
|
||||
|
@ -72,12 +73,21 @@ export default class Content {
|
|||
*/
|
||||
async saveConfiguration() {
|
||||
try {
|
||||
/*
|
||||
await FileUtils.writeFile(`${this.contentPath}/user.config.json`, JSON.stringify({
|
||||
enabled: this.enabled,
|
||||
config: this.settings.strip().settings,
|
||||
data: this.data
|
||||
}));
|
||||
|
||||
*/
|
||||
Database.insertOrUpdate({ type: 'contentconfig', $or: [{ id: this.id }, { name: this.name }] }, {
|
||||
type: 'contentconfig',
|
||||
id: this.id,
|
||||
name: this.name,
|
||||
enabled: this.enabled,
|
||||
config: this.settings.strip().settings,
|
||||
data: this.data
|
||||
});
|
||||
this.settings.setSaved();
|
||||
} catch (err) {
|
||||
Logger.err(this.name, ['Failed to save configuration', err]);
|
||||
|
|
|
@ -15,6 +15,7 @@ import path from 'path';
|
|||
import { Events } from 'modules';
|
||||
import { SettingsSet, ErrorEvent } from 'structs';
|
||||
import { Modals } from 'ui';
|
||||
import Database from './database';
|
||||
|
||||
/**
|
||||
* Base class for external content managing
|
||||
|
@ -189,13 +190,16 @@ export default class {
|
|||
};
|
||||
|
||||
try {
|
||||
const readUserConfig = await this.readUserConfig(contentPath);
|
||||
userConfig.enabled = readUserConfig.enabled || false;
|
||||
//const readUserConfig = await this.readUserConfig(contentPath);
|
||||
const readUserConfig = await Database.find({ type: 'contentconfig', name: readConfig.info.name });
|
||||
if (readUserConfig.length) {
|
||||
userConfig.enabled = readUserConfig[0].enabled || false;
|
||||
// await userConfig.config.merge({ settings: readUserConfig.config });
|
||||
// userConfig.config.setSaved();
|
||||
// userConfig.config = userConfig.config.clone({ settings: readUserConfig.config });
|
||||
userConfig.config = readUserConfig.config;
|
||||
userConfig.data = readUserConfig.data || {};
|
||||
userConfig.config = readUserConfig[0].config;
|
||||
userConfig.data = readUserConfig[0].data || {};
|
||||
}
|
||||
} catch (err) { /*We don't care if this fails it either means that user config doesn't exist or there's something wrong with it so we revert to default config*/
|
||||
Logger.info(this.moduleName, `Failed reading config for ${this.contentType} ${readConfig.info.name} in ${dirName}`);
|
||||
Logger.err(this.moduleName, err);
|
||||
|
|
|
@ -12,6 +12,10 @@ import { ClientIPC } from 'bdipc';
|
|||
|
||||
export default class {
|
||||
|
||||
static async init() {
|
||||
return true;
|
||||
}
|
||||
|
||||
static async insertOrUpdate(args, data) {
|
||||
try {
|
||||
return ClientIPC.send('bd-dba', { action: 'update', args, data });
|
||||
|
|
Loading…
Reference in New Issue