From 08c632a5c5b1d3c125275d7da934bb9bcd78c316 Mon Sep 17 00:00:00 2001 From: ckcz123 Date: Wed, 21 Oct 2020 11:49:42 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dconfig.json=E5=8F=AF=E8=83=BD?= =?UTF-8?q?=E6=8A=A5=E9=94=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- _server/editor_config.js | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/_server/editor_config.js b/_server/editor_config.js index 0eb2a4ba..9430de59 100644 --- a/_server/editor_config.js +++ b/_server/editor_config.js @@ -11,8 +11,14 @@ editor_config.prototype.load = function(callback) { _this.config = {}; _this.save(callback); } else { - _this.config = JSON.parse(d); - if (callback) callback(); + try { + _this.config = JSON.parse(d); + if (callback) callback(); + } catch (e) { + console.error(e); + _this.config = {}; + _this.save(callback); + } } }); } @@ -32,11 +38,12 @@ editor_config.prototype.save = function(callback) { if (this._isWriting) return; try { this._isWriting = true; - fs.writeFile(this.address, JSON.stringify(this.config) ,'utf-8', (function(e) { - this._isWriting = false; + var _this = this; + fs.writeFile(this.address, JSON.stringify(this.config) ,'utf-8', function(e) { + _this._isWriting = false; if (e) console.error("写入配置文件失败"); if (callback instanceof Function) callback(); - }).bind(this)) + }) } catch (e) { this._isWriting = false; console.error(e);