mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-01-23 10:45:47 +00:00
refactor(config) connection
This commit is contained in:
parent
aa707d9afb
commit
c03fbbf11f
1 changed files with 10 additions and 4 deletions
|
|
@ -105,20 +105,26 @@ function listen(sock, authCheck) {
|
|||
function connection(socket) {
|
||||
socket.emit('config', config);
|
||||
|
||||
const emit = currify((socket, name, e) => {
|
||||
return socket.emit(name, e.message);
|
||||
});
|
||||
|
||||
socket.on('message', (json) => {
|
||||
if (typeof json !== 'object')
|
||||
return socket.emit('err', 'Error: Wrong data type!');
|
||||
|
||||
manageConfig(json);
|
||||
|
||||
save().then(() => {
|
||||
const send = () => {
|
||||
const data = CloudFunc.formatMsg('config', key(json));
|
||||
socket.broadcast.send(json);
|
||||
socket.send(json);
|
||||
socket.emit('log', data);
|
||||
}).catch((e) => {
|
||||
socket.emit('err', e.message);
|
||||
});
|
||||
};
|
||||
|
||||
save()
|
||||
.then(send)
|
||||
.catch(emit(socket, 'err'));
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue