From 294fb35f4d6483d07a7d61fb8d20927aeb41ed08 Mon Sep 17 00:00:00 2001 From: Book Pauk Date: Fri, 21 Oct 2022 13:47:10 +0700 Subject: [PATCH] =?UTF-8?q?=D0=A3=D0=BB=D1=83=D1=87=D1=88=D0=B5=D0=BD?= =?UTF-8?q?=D0=B8=D0=B5=20=D0=B7=D0=B0=D0=B3=D1=80=D1=83=D0=B7=D0=BA=D0=B8?= =?UTF-8?q?=20=D0=BA=D0=BE=D0=BD=D1=84=D0=B8=D0=B3=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/config/index.js | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/server/config/index.js b/server/config/index.js index b0b73ca..ee0aef5 100644 --- a/server/config/index.js +++ b/server/config/index.js @@ -85,13 +85,22 @@ class ConfigManager { async load() { if (!this.inited) throw new Error('not inited'); - if (!await fs.pathExists(this.userConfigFile)) { - await this.save(); - return; - } - const data = await fs.readFile(this.userConfigFile, 'utf8'); - this.config = JSON.parse(data); + if (await fs.pathExists(this.userConfigFile)) { + const data = JSON.parse(await fs.readFile(this.userConfigFile, 'utf8')); + const config = _.pick(data, propsToSave); + + this.config = config; + + //сохраним конфиг, если не все атрибуты присутствуют в файле конфига + for (const prop of propsToSave) + if (!Object.prototype.hasOwnProperty.call(config, prop)) { + await this.save(); + break; + } + } else { + await this.save(); + } } async save() {