Commit 166da82f35029dfd374268467e3ac436ec755d6d
1 parent
1abcba56c8
Exists in
master
ESLINT on api-server router-config
Showing 1 changed file with 22 additions and 23 deletions Side-by-side Diff
api-server/router-config.js
1 | -"use strict"; | |
2 | - | |
3 | 1 | const fs = require('fs'); |
4 | 2 | const express = require('express'); |
5 | 3 | const bodyParser = require('body-parser'); |
... | ... | @@ -14,7 +12,7 @@ const matrix = require('../matrix'); |
14 | 12 | const router = express.Router(); |
15 | 13 | module.exports = router; |
16 | 14 | |
17 | -fs.existsSync('config-backup') || fs.mkdirSync('config-backup'); | |
15 | +if (!fs.existsSync('config-backup')) fs.mkdirSync('config-backup'); | |
18 | 16 | |
19 | 17 | function getJsonConfig(req, res) { |
20 | 18 | res.json(config); |
... | ... | @@ -22,7 +20,7 @@ function getJsonConfig(req, res) { |
22 | 20 | |
23 | 21 | function getConfigElement(req, res) { |
24 | 22 | const key = ((req && req.params && req.params.key) ? req.params.key : '').replace(/^config\.*/, '').trim(); |
25 | - res.json(jsonQuery(key, {data: config}).value); | |
23 | + res.json(jsonQuery(key, { data: config }).value); | |
26 | 24 | } |
27 | 25 | |
28 | 26 | function setConfigElement(req, res) { |
... | ... | @@ -38,7 +36,7 @@ function setConfigElement(req, res) { |
38 | 36 | method: '/config/set', |
39 | 37 | key: req.body.key, |
40 | 38 | value: req.body.value, |
41 | - new_config: config | |
39 | + new_config: config, | |
42 | 40 | }); |
43 | 41 | } |
44 | 42 | |
... | ... | @@ -46,7 +44,7 @@ function delConfigElement(req, res) { |
46 | 44 | const key = ((req && req.params && req.params.key) ? req.params.key : '').replace(/^config\.*/, '').trim(); |
47 | 45 | |
48 | 46 | if (!key) { |
49 | - res.end('INVALID OBJECT KEY') | |
47 | + res.end('INVALID OBJECT KEY'); | |
50 | 48 | } |
51 | 49 | |
52 | 50 | dot.str(key, config); |
... | ... | @@ -55,45 +53,46 @@ function delConfigElement(req, res) { |
55 | 53 | res.json({ |
56 | 54 | method: '/config/del', |
57 | 55 | key: req.body.key, |
58 | - new_config: config | |
56 | + new_config: config, | |
59 | 57 | }); |
60 | 58 | } |
61 | 59 | |
62 | 60 | function saveConfig(req, res) { |
63 | - copyFile('config.json', 'config-backup/config_' + moment().format('YYYYMMDD_HHmmss.SS') + '.json', function(err) { | |
61 | + copyFile('config.json', `config-backup/config_${moment().format('YYYYMMDD_HHmmss.SS')}.json`, (err) => { | |
64 | 62 | if (err) { |
65 | 63 | res.json({ |
66 | 64 | method: '/config/save', |
67 | - error: err.toString() | |
68 | - }) | |
65 | + error: err.toString(), | |
66 | + }); | |
69 | 67 | return; |
70 | 68 | } |
71 | 69 | |
72 | - fs.writeFile('config.json', JSON.stringify(config, null, 2), function(err) { | |
73 | - if (err) { | |
70 | + fs.writeFile('config.json', JSON.stringify(config, null, 2), (errWriteFile) => { | |
71 | + if (errWriteFile) { | |
74 | 72 | res.json({ |
75 | 73 | method: '/config/save', |
76 | - error: err.toString() | |
77 | - }) | |
74 | + error: errWriteFile.toString(), | |
75 | + }); | |
76 | + | |
78 | 77 | return; |
79 | 78 | } |
80 | - }) | |
81 | 79 | |
82 | - matrix.config_is_dirty = false; | |
80 | + matrix.config_is_dirty = false; | |
83 | 81 | |
84 | - res.json({ | |
85 | - method: '/config/save', | |
86 | - error: null | |
87 | - }) | |
88 | - }) | |
82 | + res.json({ | |
83 | + method: '/config/save', | |
84 | + error: null, | |
85 | + }); | |
86 | + }); | |
87 | + }); | |
89 | 88 | } |
90 | 89 | |
91 | 90 | function isDirty(req, res) { |
92 | 91 | res.json({ |
93 | 92 | method: '/config/is-dirty', |
94 | 93 | error: null, |
95 | - dirty: matrix.config_is_dirty || false | |
96 | - }) | |
94 | + dirty: matrix.config_is_dirty || false, | |
95 | + }); | |
97 | 96 | } |
98 | 97 | |
99 | 98 | router.get('/', getJsonConfig); |