mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-07-20 18:18:56 +00:00
refactor(config) patch: then -> await
This commit is contained in:
parent
4a8b6e4f66
commit
d3b965ec38
2 changed files with 23 additions and 17 deletions
|
|
@ -155,6 +155,7 @@
|
|||
"squad": "^3.0.0",
|
||||
"table": "^5.0.2",
|
||||
"try-catch": "^2.0.0",
|
||||
"try-to-catch": "^1.0.2",
|
||||
"tryrequire": "^2.0.1",
|
||||
"wraptile": "^2.0.0",
|
||||
"writejson": "^2.0.0"
|
||||
|
|
@ -216,7 +217,6 @@
|
|||
"supermenu": "^2.0.0",
|
||||
"tape": "^4.4.0",
|
||||
"tar-stream": "^1.5.2",
|
||||
"try-to-catch": "^1.0.2",
|
||||
"unionfs": "^3.0.2",
|
||||
"url-loader": "^1.0.1",
|
||||
"version-io": "^2.0.1",
|
||||
|
|
|
|||
|
|
@ -11,11 +11,11 @@ const Emitter = require('events');
|
|||
const exit = require(DIR_SERVER + 'exit');
|
||||
const CloudFunc = require(DIR_COMMON + 'cloudfunc');
|
||||
|
||||
const fullstore = require('fullstore');
|
||||
const currify = require('currify');
|
||||
const wraptile = require('wraptile');
|
||||
const squad = require('squad');
|
||||
const promisify = require('es6-promisify').promisify;
|
||||
const tryToCatch = require('try-to-catch');
|
||||
const pullout = promisify(require('pullout'));
|
||||
const ponse = require('ponse');
|
||||
const jonny = require('jonny');
|
||||
|
|
@ -27,12 +27,9 @@ const HOME = require('os').homedir();
|
|||
|
||||
const manageConfig = squad(traverse, cryptoPass);
|
||||
const save = promisify(_save);
|
||||
const swap = currify((f, a, b) => f(b, a));
|
||||
const noArgs = (fn) => () => fn();
|
||||
const saveData = noArgs(save);
|
||||
|
||||
const sendError = swap(ponse.sendError);
|
||||
const send = swap(ponse.send);
|
||||
const formatMsg = currify((a, b) => CloudFunc.formatMsg(a, b));
|
||||
|
||||
const apiURL = CloudFunc.apiURL;
|
||||
|
|
@ -178,8 +175,7 @@ function get(request, response) {
|
|||
});
|
||||
}
|
||||
|
||||
function patch(request, response) {
|
||||
const jsonStore = fullstore();
|
||||
async function patch(request, response) {
|
||||
const name = 'config.json';
|
||||
const cache = false;
|
||||
const options = {
|
||||
|
|
@ -189,16 +185,26 @@ function patch(request, response) {
|
|||
cache,
|
||||
};
|
||||
|
||||
pullout(request, 'string')
|
||||
.then(jonny.parse)
|
||||
.then(jsonStore)
|
||||
.then(manageConfig)
|
||||
.then(saveData)
|
||||
.then(noArgs(jsonStore))
|
||||
.then(key)
|
||||
.then(formatMsg('config'))
|
||||
.then(send(options))
|
||||
.catch(sendError(options));
|
||||
const [e] = await tryToCatch(patchConfig, options);
|
||||
|
||||
if (e)
|
||||
ponse.sendError(e, options);
|
||||
}
|
||||
|
||||
async function patchConfig({name, request, response, cache}) {
|
||||
const str = await pullout(request, 'string');
|
||||
const json = jonny.parse(str);
|
||||
|
||||
manageConfig(json);
|
||||
saveData();
|
||||
|
||||
const msg = formatMsg('config', key(json));
|
||||
ponse.send(msg, {
|
||||
name,
|
||||
request,
|
||||
response,
|
||||
cache,
|
||||
});
|
||||
}
|
||||
|
||||
function traverse(json) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue