Built motion from commit f651e4b0a7312c0adceb5e57d6684a801a3aaf0d. Version 3.0.0...
[motion-next.git] / server / api / pm2 / pm2.controller.js
1 const a521_0x15bd=['exec','../../config/pm2','api','lodash','dirname','list','dump','body','create','npm\x20install','child_process','restart','destroy','sendStatus','path','then','name','Unknown\x20status','../../files/plugins','delete','params','undefined','info','chdir','update','send','express','Unknown\x20id','script','../../config/logger','show','catch','error','status'];(function(_0x5272b7,_0x15bd81){const _0x8e4612=function(_0x16a5dc){while(--_0x16a5dc){_0x5272b7['push'](_0x5272b7['shift']());}};_0x8e4612(++_0x15bd81);}(a521_0x15bd,0x1ee));const a521_0x8e46=function(_0x5272b7,_0x15bd81){_0x5272b7=_0x5272b7-0x0;let _0x8e4612=a521_0x15bd[_0x5272b7];return _0x8e4612;};const _0x1568b2=a521_0x8e46;'use strict';const _=require(_0x1568b2('0x13')),pm2=require(_0x1568b2('0x11')),logger=require(_0x1568b2('0xb'))(_0x1568b2('0x12')),path=require(_0x1568b2('0x1e')),exec=require(_0x1568b2('0x1a'))[_0x1568b2('0x10')];function handleEntityNotFound(_0x16a5dc){return function(_0x418c7c){const _0x1a16bb=a521_0x8e46;return!_0x418c7c&&_0x16a5dc[_0x1a16bb('0x1d')](0x194),_0x418c7c;};}function respondWithResult(_0x5b39fd,_0x59b438){return _0x59b438=_0x59b438||0xc8,function(_0x1cdbd6){if(_0x1cdbd6)return _0x5b39fd['status'](_0x59b438)['json'](_0x1cdbd6);return null;};}function handleError(_0x30159d,_0x5b586c){return _0x5b586c=_0x5b586c||0x1f4,function(_0x42f13f){const _0x57903f=a521_0x8e46;logger[_0x57903f('0xe')](_0x42f13f['stack']),_0x42f13f[_0x57903f('0x20')]&&delete _0x42f13f[_0x57903f('0x20')],_0x30159d[_0x57903f('0xf')](_0x5b586c)[_0x57903f('0x7')](_0x42f13f);};}function execChildProcess(){return new Promise(function(_0x15bb9d,_0x3e8acc){const _0x1b64c3=a521_0x8e46;exec(_0x1b64c3('0x19'),function(_0x9b0432,_0x50af7f,_0x122fb2){const _0x2edd11=_0x1b64c3;logger[_0x2edd11('0x4')](_0x50af7f),logger[_0x2edd11('0x4')](_0x122fb2);if(_0x9b0432)return logger['error'](_0x9b0432),_0x3e8acc(_0x9b0432);return _0x15bb9d(_0x50af7f);});});}exports['index']=function(_0x302c4c,_0x1099da){const _0x389c6d=_0x1568b2;return pm2[_0x389c6d('0x15')]()[_0x389c6d('0x1f')](function(_0x1afb74){if(_0x1afb74){const _0xbdfafa=_['reject'](_0x1afb74,function(_0x403173){const _0x357452=a521_0x8e46;return _0x403173[_0x357452('0x20')]===_0x357452('0x8')||_0x403173[_0x357452('0x20')]==='motion2';});return{'rows':_0xbdfafa,'count':_0xbdfafa['length']};}return null;})[_0x389c6d('0x1f')](respondWithResult(_0x1099da,null))['catch'](handleError(_0x1099da,null));},exports[_0x1568b2('0xc')]=function(_0x3a470e,_0x2f9d61){const _0x17d970=_0x1568b2;return pm2['describe'](_0x3a470e['params']['id'])[_0x17d970('0x1f')](respondWithResult(_0x2f9d61,null))[_0x17d970('0x1f')](handleEntityNotFound(_0x2f9d61,null))[_0x17d970('0xd')](handleError(_0x2f9d61,null));},exports[_0x1568b2('0x18')]=function(_0x5c65f2,_0x56bc70){const _0x4dbcae=_0x1568b2;if(_0x5c65f2[_0x4dbcae('0x17')]['name']&&_0x5c65f2[_0x4dbcae('0x17')][_0x4dbcae('0xa')]){const _0x570de3=path['join'](__dirname,_0x4dbcae('0x0'),_0x5c65f2[_0x4dbcae('0x17')][_0x4dbcae('0xa')]),_0x3ce3eb=process['cwd']();return process['chdir'](path[_0x4dbcae('0x14')](_0x570de3)),execChildProcess()[_0x4dbcae('0x1f')](function(){const _0x25d39e=_0x4dbcae;return process[_0x25d39e('0x5')](_0x3ce3eb),pm2['start']({'name':_0x5c65f2[_0x25d39e('0x17')]['name'],'script':_0x570de3});})[_0x4dbcae('0x1f')](function(_0x141713){const _0x1aa359=_0x4dbcae;return pm2[_0x1aa359('0x16')](),_0x141713[0x0];})[_0x4dbcae('0x1f')](respondWithResult(_0x56bc70,0xc9))[_0x4dbcae('0xd')](handleError(_0x56bc70,null));}else return _0x56bc70[_0x4dbcae('0xf')](0x1f4)[_0x4dbcae('0x7')]({'message':'Missing\x20name\x20and/or\x20path'});},exports[_0x1568b2('0x6')]=function(_0x5b4da6,_0x430a0c){const _0x40d702=_0x1568b2;_0x5b4da6['body']['id']&&delete _0x5b4da6[_0x40d702('0x17')]['id'];const _0x35b36f={'online':_0x40d702('0x1b'),'stopped':'stop'};return typeof _0x35b36f[_0x5b4da6['body']['status']]!==_0x40d702('0x3')?pm2[_0x35b36f[_0x5b4da6[_0x40d702('0x17')][_0x40d702('0xf')]]](_0x5b4da6[_0x40d702('0x2')]['id'])[_0x40d702('0x1f')](respondWithResult(_0x430a0c,0xc8))['catch'](handleError(_0x430a0c,null)):_0x430a0c[_0x40d702('0xf')](0x1f4)[_0x40d702('0x7')]({'message':_0x40d702('0x21')});},exports[_0x1568b2('0x1c')]=function(_0x13eeeb,_0x572cdb){const _0x4e1c0e=_0x1568b2;return _0x13eeeb[_0x4e1c0e('0x17')]['id']&&delete _0x13eeeb[_0x4e1c0e('0x17')]['id'],_0x13eeeb[_0x4e1c0e('0x2')]['id']?pm2[_0x4e1c0e('0x1')](_0x13eeeb[_0x4e1c0e('0x2')]['id'])['then'](function(_0x29adbd){return pm2['dump'](),_0x29adbd[0x0];})[_0x4e1c0e('0x1f')](respondWithResult(_0x572cdb,null))[_0x4e1c0e('0xd')](handleError(_0x572cdb,null)):_0x572cdb[_0x4e1c0e('0xf')](0x1f4)[_0x4e1c0e('0x7')]({'message':_0x4e1c0e('0x9')});};