Commit ba2a6e968690a9a4cae0760d7614373da287e674
1 parent
1dadc8ab5f
Exists in
master
API-SERVER: config del and save
Showing 1 changed file with 25 additions and 9 deletions Side-by-side Diff
api-server/router-config.js
... | ... | @@ -17,31 +17,44 @@ function getJsonConfig(req, res, next) { |
17 | 17 | } |
18 | 18 | |
19 | 19 | function getConfigElement(req, res, next) { |
20 | - const key = ((req && req.params && req.params.key) ? req.params.key : '').replace(/^config\.*/, ''); | |
20 | + const key = ((req && req.params && req.params.key) ? req.params.key : '').replace(/^config\.*/, '').trim(); | |
21 | 21 | res.json(jsonQuery(key, {data: config}).value); |
22 | 22 | } |
23 | 23 | |
24 | 24 | function setConfigElement(req, res, next) { |
25 | - if (!req.params || !req.params.key) { | |
26 | - res.end('INVALID OBJECT KEY'); | |
27 | - return; | |
28 | - } | |
29 | - | |
30 | 25 | if (!req.body || !req.body.key || !req.body.value) { |
31 | 26 | res.end('INVALID BODY'); |
32 | 27 | return; |
33 | 28 | } |
34 | 29 | |
35 | - //const key = ((req && req.params && req.params.key) ? req.params.key : '').replace(/^config\.*/, ''); | |
36 | 30 | dot.str(req.body.key, req.body.value, config); |
31 | + res.json({ | |
32 | + method: '/config/set', | |
33 | + key: req.body.key, | |
34 | + value: req.body.value, | |
35 | + new_config: config | |
36 | + }); | |
37 | +} | |
37 | 38 | |
39 | +function delConfigElement(req, res, next) { | |
40 | + const key = ((req && req.params && req.params.key) ? req.params.key : '').replace(/^config\.*/, '').trim(); | |
41 | + | |
42 | + if (!key) { | |
43 | + res.end('INVALID OBJECT KEY') | |
44 | + } | |
45 | + | |
46 | + dot.str(key, config); | |
38 | 47 | res.json({ |
39 | - new_key: req.body.key, | |
40 | - new_value: req.body.value, | |
48 | + method: '/config/del', | |
49 | + key: req.body.key, | |
41 | 50 | new_config: config |
42 | 51 | }); |
43 | 52 | } |
44 | 53 | |
54 | +function saveConfig(req, res, next) { | |
55 | + res.end('NOT YET IMPLEMENTED'); | |
56 | +} | |
57 | + | |
45 | 58 | router.get('/', getJsonConfig); |
46 | 59 | router.post('/', getJsonConfig); |
47 | 60 | |
... | ... | @@ -49,3 +62,6 @@ router.get('/get', getConfigElement); |
49 | 62 | router.get('/get/:key', getConfigElement); |
50 | 63 | |
51 | 64 | router.post('/set/:key', bodyParser.json(), setConfigElement); |
65 | + | |
66 | +router.get('/del/:key', delConfigElement); | |
67 | +router.get('/save', saveConfig); |