Browse Source

异步读取配置文件

dygapp 4 years ago
parent
commit
501654b053

+ 2 - 2
app/controller/admin.js

@@ -7,7 +7,7 @@ class AdminController extends Controller {
   async login() {
     const { ctx, app } = this;
     const { userName, password } = ctx.request.body;
-    const configJson = this.app.readConfig(filePath.configJson);
+    const configJson = await this.app.readConfig(filePath.configJson);
     const data = configJson.admin.filter(p => p.userName === userName);
     console.log(data);
     let msg;
@@ -28,7 +28,7 @@ class AdminController extends Controller {
   async changePass() {
     const { ctx } = this;
     const { userName, oldpass, newpass } = ctx.request.body;
-    const configJson = this.app.readConfig(filePath.configJson);
+    const configJson = await this.app.readConfig(filePath.configJson);
     const data = configJson.admin.filter(p => p.userName === userName);
     let msg;
     try {

+ 3 - 3
app/controller/cacert.js

@@ -7,7 +7,7 @@ const filePath = require('../../config/filespath');
 class CAcertController extends Controller {
   async caupload() {
     const { ctx } = this;
-    const configJson = this.app.readConfig(filePath.configJson);
+    const configJson = await this.app.readConfig(filePath.configJson);
     const uuid = UUID.v1();
     // 获取数据流
     const stream = await ctx.getFileStream();
@@ -42,7 +42,7 @@ class CAcertController extends Controller {
   // 删除ca证书
   async cadelete() {
     const uuid = this.ctx.query.uuid;
-    const configJson = this.app.readConfig(filePath.configJson);
+    const configJson = await this.app.readConfig(filePath.configJson);
     // 过滤掉当前uuid数据
     const data = configJson.ca.filter(p => p.uuid !== uuid);
     configJson.ca = data;
@@ -65,7 +65,7 @@ class CAcertController extends Controller {
   // 查询ca信息
   async caquery() {
     const { ctx } = this;
-    const configJson = this.app.readConfig(filePath.configJson);
+    const configJson = await this.app.readConfig(filePath.configJson);
     const data = configJson.ca;
     ctx.body = { errcode: 0, errmsg: '', data };
   }

+ 1 - 1
app/controller/enccert.js

@@ -21,7 +21,7 @@ class EnccertController extends Controller {
     // 创建文件名
     const fileName = `${filePath.p12}${uuid}.p12`;
     // 获取数据文件
-    const configJson = this.app.readConfig(filePath.configJson);
+    const configJson = await this.app.readConfig(filePath.configJson);
     try {
       // 存储P12文件
       const res = await this.service.fileshandler.upload({ name: fileName, stream });

+ 4 - 4
app/controller/ipsecvpn.js

@@ -10,7 +10,7 @@ class IpsecvpnController extends Controller {
     const { ctx } = this;
     const { address, addressTow, cert, digit, loglevel, pwa } = ctx.request.body;
     const form = { address, addressTow, cert, digit, loglevel, pwa };
-    const person = this.app.readConfig(filePath.configJson);
+    const person = await this.app.readConfig(filePath.configJson);
     person.ipsecvpn = form;
     const jsonstr = JSON.stringify(person);
     try {
@@ -36,7 +36,7 @@ class IpsecvpnController extends Controller {
   async secservice() {
     const { ctx } = this;
     const form = ctx.request.body;
-    const person = this.app.readConfig(filePath.configJson);
+    const person = await this.app.readConfig(filePath.configJson);
     person.ipsecservice = form;
     const jsonstr = JSON.stringify(person);
     try {
@@ -62,7 +62,7 @@ class IpsecvpnController extends Controller {
   async secclientquery() {
     try {
       const { ctx } = this;
-      const person = this.app.readConfig(filePath.configJson);
+      const person = await this.app.readConfig(filePath.configJson);
       const data = person.ipsecvpn;
       ctx.body = { errcode: 0, errmsg: '', data };
     } catch (error) {
@@ -73,7 +73,7 @@ class IpsecvpnController extends Controller {
   async ipsecservicequery() {
     try {
       const { ctx } = this;
-      const person = this.app.readConfig(filePath.configJson);
+      const person = await this.app.readConfig(filePath.configJson);
       const data = person.ipsecservice;
       ctx.body = { errcode: 0, errmsg: '', data };
     } catch (error) {

+ 2 - 2
app/controller/lan.js

@@ -8,7 +8,7 @@ class LanController extends Controller {
   // 修改lan信息
   async lanupdate() {
     const lanpath = filePath.lan;
-    const configJson = this.app.readConfig(filePath.configJson);
+    const configJson = await this.app.readConfig(filePath.configJson);
     const { address, start, end, type } = this.ctx.request.body;
     const form = { address, start, end, type };
     form.addressTow = form.address.substring(0, form.address.lastIndexOf('.'));
@@ -45,7 +45,7 @@ class LanController extends Controller {
   // 查询lan信息
   async lanquery() {
     const { ctx } = this;
-    const configJson = this.app.readConfig(filePath.configJson);
+    const configJson = await this.app.readConfig(filePath.configJson);
     const data = configJson.lan;
     ctx.body = { errcode: 0, errmsg: '', data };
   }

+ 4 - 4
app/controller/sigcert.js

@@ -19,7 +19,7 @@ class SigcertController extends Controller {
         const resreq = await this.service.shell.applyreq({ ...ctx.request.body, keyPath: `${filePath.keys}${uuid}.key`, filePath: `${filePath.req}${uuid}.pem` });
         if (resreq.errcode === 0) {
           const form = { state, dn, pwatype, name, uuid };
-          const person = this.app.readConfig(filePath.configJson);
+          const person = await this.app.readConfig(filePath.configJson);
           person.cert.push(form);
           const jsonstr = JSON.stringify(person);
           // 添加到数据文件
@@ -35,7 +35,7 @@ class SigcertController extends Controller {
   // 签名证书查询
   async sigcacertquery() {
     const { ctx } = this;
-    const person = this.app.readConfig(filePath.configJson);
+    const person = await this.app.readConfig(filePath.configJson);
     const data = person.cert;
     const total = data.length || 0;
     ctx.body = { errcode: 0, errmsg: '', data, total };
@@ -43,7 +43,7 @@ class SigcertController extends Controller {
   // 删除签名证书
   async sigcertdelete() {
     const uuid = this.ctx.query.uuid;
-    const configJson = this.app.readConfig(filePath.configJson);
+    const configJson = await this.app.readConfig(filePath.configJson);
     // 过滤掉当前uuid数据
     const data = configJson.cert.filter(p => p.uuid !== uuid);
     const isdata = configJson.cert.filter(p => p.uuid === uuid);
@@ -75,7 +75,7 @@ class SigcertController extends Controller {
   // 签名证书上传
   async sigcacertupload() {
     const { ctx } = this;
-    const person = this.app.readConfig(filePath.configJson);
+    const person = await this.app.readConfig(filePath.configJson);
     const stream = await this.ctx.getFileStream();
     const uuid = stream.fields.uuid;
     // 路径 + 文件名

+ 4 - 4
app/controller/sslvpn.js

@@ -9,7 +9,7 @@ class SslvpnController extends Controller {
     const { ctx } = this;
     const form = ctx.request.body;
     // 引入数据文件
-    const person = this.app.readConfig(filePath.configJson);
+    const person = await this.app.readConfig(filePath.configJson);
     person.sslvpn = form;
     const jsonstr = JSON.stringify(person);
     try {
@@ -34,7 +34,7 @@ class SslvpnController extends Controller {
   async sslvpnservice() {
     const { ctx } = this;
     const form = ctx.request.body;
-    const person = this.app.readConfig(filePath.configJson);
+    const person = await this.app.readConfig(filePath.configJson);
     person.sslvpnservice = form;
     const jsonstr = JSON.stringify(person);
     try {
@@ -59,7 +59,7 @@ class SslvpnController extends Controller {
   async sslquery() {
     try {
       const { ctx } = this;
-      const person = this.app.readConfig(filePath.configJson);
+      const person = await this.app.readConfig(filePath.configJson);
       const data = person.sslvpn;
       ctx.body = { errcode: 0, errmsg: '', data };
     } catch (error) {
@@ -71,7 +71,7 @@ class SslvpnController extends Controller {
   async sslserivcequery() {
     try {
       const { ctx } = this;
-      const person = this.app.readConfig(filePath.configJson);
+      const person = await this.app.readConfig(filePath.configJson);
       const data = person.sslvpnservice;
       ctx.body = { errcode: 0, errmsg: '', data };
     } catch (error) {

+ 1 - 1
app/controller/systemctl.js

@@ -161,7 +161,7 @@ class SystemctlController extends Controller {
   // 获取设备信息
   async devinfo() {
     try {
-      const configJson = this.app.readConfig(filePath.configJson);
+      const configJson = await this.app.readConfig(filePath.configJson);
       const model = configJson.model;
       const version = configJson.version;
       this.ctx.body = { errcode: 0, errmsg: '', data: { model, version } };

+ 2 - 2
app/controller/wan.js

@@ -6,7 +6,7 @@ class WanController extends Controller {
   // 修改wan信息
   async wanupdate() {
     const wanpath = filePath.wan;
-    const configJson = this.app.readConfig(filePath.configJson);
+    const configJson = await this.app.readConfig(filePath.configJson);
     const { address, netmask, gateway, type, dns, staticip } = this.ctx.request.body;
     const form = { address, netmask, gateway, type, dns, staticip };
     console.log(address, netmask, gateway, type, dns, staticip);
@@ -44,7 +44,7 @@ class WanController extends Controller {
   // 查询wan信息
   async wanquery() {
     const { ctx } = this;
-    const configJson = this.app.readConfig(filePath.configJson);
+    const configJson = await this.app.readConfig(filePath.configJson);
     const data = configJson.wan;
     ctx.body = { errcode: 0, errmsg: '', data };
   }