5115c471943fa90ae9020a59b5511972717201b5
[motion2.git] / server / api / screenRecording / screenRecording.controller.js
1 // *************************************************************************
2 // *                                                                       *
3 // * xCALLY Motion -  The Omnichannel Contact Center                       *
4 // * Copyright (c) Xenialab s.r.l. All Rights Reserved                     *
5 // *                                                                       *
6 // *************************************************************************
7 // *                                                                       *
8 // * Email: info@xcally.com                                                *
9 // * Website: https://www.xcally.com                                       *
10 // *                                                                       *
11 // *************************************************************************
12 // *                                                                       *
13 // * The SOFTWARE PRODUCT is protected by copyright laws and international *
14 // * copyright treaties, as well as other intellectual property laws and   *
15 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                         *
16 // *                                                                       *
17 // *************************************************************************
18 var _0xdc97=['join','root','%s.cypher','existsSync','decryptFile','Sequelize','ValidationError','ScreenRecording\x20not\x20found','filename','extname','unlink','message','Not\x20found','destroy','isNil','info','cancellazione\x20fisica\x20documento\x20%s','File:\x20\x22','\x22\x20trovato\x20eseguo\x20la\x20cancellazione','unlinkSync','.cypher','eml-format','rimraf','zip-dir','request-promise','bluebird','mustache','path','sox','to-csv','ejs','lodash','jsforce','desk.js','querystring','papaparse','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','status','end','offset','undefined','limit','count','set','Content-Range','json','apply','update','then','sendStatus','error','name','send','index','map','format','query','keys','intersection','model','fields','attributes','length','hasOwnProperty','nolimit','order','sort','filters','pick','filter','where','merge','type','options','ScreenRecording','includeAll','rows','catch','show','params','include','find','create','body','duration','createdAt','closedAt','value','describe','download','../../components/encryptor','uniqueid'];(function(_0x304412,_0x5c775c){var _0x3a52fa=function(_0xae402c){while(--_0xae402c){_0x304412['push'](_0x304412['shift']());}};_0x3a52fa(++_0x5c775c);}(_0xdc97,0x13b));var _0x7dc9=function(_0x45644e,_0x47c18d){_0x45644e=_0x45644e-0x0;var _0x3ecd7f=_0xdc97[_0x45644e];return _0x3ecd7f;};'use strict';var emlformat=require(_0x7dc9('0x0'));var rimraf=require(_0x7dc9('0x1'));var zipdir=require(_0x7dc9('0x2'));var jsonpatch=require('fast-json-patch');var rp=require(_0x7dc9('0x3'));var moment=require('moment');var BPromise=require(_0x7dc9('0x4'));var Mustache=require(_0x7dc9('0x5'));var util=require('util');var path=require(_0x7dc9('0x6'));var sox=require(_0x7dc9('0x7'));var csv=require(_0x7dc9('0x8'));var ejs=require(_0x7dc9('0x9'));var fs=require('fs');var fs_extra=require('fs-extra');var _=require(_0x7dc9('0xa'));var squel=require('squel');var crypto=require('crypto');var jsforce=require(_0x7dc9('0xb'));var deskjs=require(_0x7dc9('0xc'));var toCsv=require(_0x7dc9('0x8'));var querystring=require(_0x7dc9('0xd'));var Papa=require(_0x7dc9('0xe'));var Redis=require('ioredis');var authService=require(_0x7dc9('0xf'));var qs=require(_0x7dc9('0x10'));var as=require(_0x7dc9('0x11'));var hardwareService=require(_0x7dc9('0x12'));var logger=require(_0x7dc9('0x13'))(_0x7dc9('0x14'));var utils=require(_0x7dc9('0x15'));var config=require('../../config/environment');var licenseUtil=require('../../config/license/util');var db=require('../../mysqldb')['db'];function respondWithStatusCode(_0x599ef1,_0x94c75a){_0x94c75a=_0x94c75a||0xcc;return function(_0x14e5db){if(_0x14e5db){return _0x599ef1['sendStatus'](_0x94c75a);}return _0x599ef1[_0x7dc9('0x16')](_0x94c75a)[_0x7dc9('0x17')]();};}function respondWithResult(_0xaadf2,_0xf37bc7){_0xf37bc7=_0xf37bc7||0xc8;return function(_0x31d43d){if(_0x31d43d){return _0xaadf2[_0x7dc9('0x16')](_0xf37bc7)['json'](_0x31d43d);}};}function respondWithFilteredResult(_0x3a54f2,_0x278191){return function(_0x1b0aa1){if(_0x1b0aa1){var _0x442819=typeof _0x278191[_0x7dc9('0x18')]===_0x7dc9('0x19')&&typeof _0x278191[_0x7dc9('0x1a')]===_0x7dc9('0x19');var _0x4778d5=_0x1b0aa1['count'];var _0x22577e=_0x442819?0x0:_0x278191['offset'];var _0x1f5906=_0x442819?_0x1b0aa1[_0x7dc9('0x1b')]:_0x278191['offset']+_0x278191[_0x7dc9('0x1a')];var _0x3b738a;if(_0x1f5906>=_0x4778d5){_0x1f5906=_0x4778d5;_0x3b738a=0xc8;}else{_0x3b738a=0xce;}_0x3a54f2[_0x7dc9('0x16')](_0x3b738a);return _0x3a54f2[_0x7dc9('0x1c')](_0x7dc9('0x1d'),_0x22577e+'-'+_0x1f5906+'/'+_0x4778d5)[_0x7dc9('0x1e')](_0x1b0aa1);}return null;};}function patchUpdates(_0x2dad65){return function(_0x2895f5){try{jsonpatch[_0x7dc9('0x1f')](_0x2895f5,_0x2dad65,!![]);}catch(_0x2b38d6){return BPromise['reject'](_0x2b38d6);}return _0x2895f5['save']();};}function saveUpdates(_0x12954f,_0x5981e2){return function(_0x596e0f){if(_0x596e0f){return _0x596e0f[_0x7dc9('0x20')](_0x12954f)[_0x7dc9('0x21')](function(_0x5e9525){return _0x5e9525;});}return null;};}function removeEntity(_0xffc080,_0x43d31f){return function(_0x41110a){if(_0x41110a){return _0x41110a['destroy']()[_0x7dc9('0x21')](function(){_0xffc080[_0x7dc9('0x16')](0xcc)[_0x7dc9('0x17')]();});}};}function handleEntityNotFound(_0x55a482,_0x48c6bc){return function(_0x4b9ba6){if(!_0x4b9ba6){_0x55a482[_0x7dc9('0x22')](0x194);}return _0x4b9ba6;};}function handleError(_0x32d032,_0x5843bf){_0x5843bf=_0x5843bf||0x1f4;return function(_0x585eef){logger[_0x7dc9('0x23')](_0x585eef['stack']);if(_0x585eef[_0x7dc9('0x24')]){delete _0x585eef[_0x7dc9('0x24')];}_0x32d032[_0x7dc9('0x16')](_0x5843bf)[_0x7dc9('0x25')](_0x585eef);};}exports[_0x7dc9('0x26')]=function(_0x450124,_0x236d42){var _0x229f8e={},_0x1fcf0e={},_0x3c4379={'count':0x0,'rows':[]};var _0x14083d=_[_0x7dc9('0x27')](db['ScreenRecording']['rawAttributes'],function(_0x513dd6){return{'name':_0x513dd6['fieldName'],'type':_0x513dd6['type']['key']};});_0x1fcf0e['model']=_['differenceBy'](_[_0x7dc9('0x27')](_0x14083d,_0x7dc9('0x24')),[_0x7dc9('0x28')]);_0x1fcf0e[_0x7dc9('0x29')]=_[_0x7dc9('0x2a')](_0x450124[_0x7dc9('0x29')]);_0x1fcf0e['filters']=_['intersection'](_0x1fcf0e['model'],_0x1fcf0e[_0x7dc9('0x29')]);_0x229f8e['attributes']=_[_0x7dc9('0x2b')](_0x1fcf0e[_0x7dc9('0x2c')],qs[_0x7dc9('0x2d')](_0x450124[_0x7dc9('0x29')][_0x7dc9('0x2d')]));_0x229f8e[_0x7dc9('0x2e')]=_0x229f8e[_0x7dc9('0x2e')][_0x7dc9('0x2f')]?_0x229f8e['attributes']:_0x1fcf0e[_0x7dc9('0x2c')];if(!_0x450124['query'][_0x7dc9('0x30')](_0x7dc9('0x31'))){_0x229f8e[_0x7dc9('0x1a')]=qs[_0x7dc9('0x1a')](_0x450124['query'][_0x7dc9('0x1a')]);_0x229f8e['offset']=qs[_0x7dc9('0x18')](_0x450124['query']['offset']);}_0x229f8e[_0x7dc9('0x32')]=qs[_0x7dc9('0x33')](_0x450124[_0x7dc9('0x29')][_0x7dc9('0x33')]);_0x229f8e['where']=qs[_0x7dc9('0x34')](_[_0x7dc9('0x35')](_0x450124[_0x7dc9('0x29')],_0x1fcf0e[_0x7dc9('0x34')]),_0x14083d);if(_0x450124[_0x7dc9('0x29')][_0x7dc9('0x36')]){_0x229f8e[_0x7dc9('0x37')]=_[_0x7dc9('0x38')](_0x229f8e[_0x7dc9('0x37')],{'$or':_[_0x7dc9('0x27')](_0x14083d,function(_0x452aed){if(_0x452aed[_0x7dc9('0x39')]!=='VIRTUAL'){var _0x34b5c9={};_0x34b5c9[_0x452aed[_0x7dc9('0x24')]]={'$like':'%'+_0x450124[_0x7dc9('0x29')][_0x7dc9('0x36')]+'%'};return _0x34b5c9;}})});}_0x229f8e=_['merge']({},_0x229f8e,_0x450124[_0x7dc9('0x3a')]);var _0x89db0e={'where':_0x229f8e[_0x7dc9('0x37')]};return db[_0x7dc9('0x3b')][_0x7dc9('0x1b')](_0x89db0e)[_0x7dc9('0x21')](function(_0x5a1201){_0x3c4379['count']=_0x5a1201;if(_0x450124[_0x7dc9('0x29')][_0x7dc9('0x3c')]){_0x229f8e['include']=[{'all':!![]}];}return db[_0x7dc9('0x3b')]['findAll'](_0x229f8e);})[_0x7dc9('0x21')](function(_0x2a91fe){_0x3c4379[_0x7dc9('0x3d')]=_0x2a91fe;return _0x3c4379;})['then'](respondWithFilteredResult(_0x236d42,_0x229f8e))[_0x7dc9('0x3e')](handleError(_0x236d42,null));};exports[_0x7dc9('0x3f')]=function(_0x1929b6,_0x95513c){var _0x28ffc0={'raw':![],'where':{'id':_0x1929b6[_0x7dc9('0x40')]['id']}},_0x23499a={};_0x23499a['model']=_[_0x7dc9('0x2a')](db['ScreenRecording']['rawAttributes']);_0x23499a[_0x7dc9('0x29')]=_[_0x7dc9('0x2a')](_0x1929b6[_0x7dc9('0x29')]);_0x23499a[_0x7dc9('0x34')]=_[_0x7dc9('0x2b')](_0x23499a[_0x7dc9('0x2c')],_0x23499a[_0x7dc9('0x29')]);_0x28ffc0[_0x7dc9('0x2e')]=_[_0x7dc9('0x2b')](_0x23499a['model'],qs[_0x7dc9('0x2d')](_0x1929b6[_0x7dc9('0x29')][_0x7dc9('0x2d')]));_0x28ffc0[_0x7dc9('0x2e')]=_0x28ffc0[_0x7dc9('0x2e')][_0x7dc9('0x2f')]?_0x28ffc0['attributes']:_0x23499a[_0x7dc9('0x2c')];if(_0x1929b6[_0x7dc9('0x29')]['includeAll']){_0x28ffc0[_0x7dc9('0x41')]=[{'all':!![]}];}_0x28ffc0=_[_0x7dc9('0x38')]({},_0x28ffc0,_0x1929b6[_0x7dc9('0x3a')]);return db['ScreenRecording'][_0x7dc9('0x42')](_0x28ffc0)['then'](handleEntityNotFound(_0x95513c,null))['then'](respondWithResult(_0x95513c,null))[_0x7dc9('0x3e')](handleError(_0x95513c,null));};exports[_0x7dc9('0x43')]=function(_0x36d591,_0x5e0dc5){return db['ScreenRecording'][_0x7dc9('0x43')](_0x36d591['body'],{})[_0x7dc9('0x21')](respondWithResult(_0x5e0dc5,0xc9))[_0x7dc9('0x3e')](handleError(_0x5e0dc5,null));};exports['update']=function(_0x24ccce,_0x1d6c0a){if(_0x24ccce[_0x7dc9('0x44')]['id']){delete _0x24ccce[_0x7dc9('0x44')]['id'];}delete _0x24ccce[_0x7dc9('0x44')][_0x7dc9('0x45')];delete _0x24ccce[_0x7dc9('0x44')][_0x7dc9('0x46')];delete _0x24ccce[_0x7dc9('0x44')][_0x7dc9('0x47')];delete _0x24ccce[_0x7dc9('0x44')][_0x7dc9('0x48')];return db[_0x7dc9('0x3b')]['find']({'where':{'id':_0x24ccce[_0x7dc9('0x40')]['id']}})['then'](handleEntityNotFound(_0x1d6c0a,null))['then'](saveUpdates(_0x24ccce[_0x7dc9('0x44')],null))[_0x7dc9('0x21')](respondWithResult(_0x1d6c0a,null))[_0x7dc9('0x3e')](handleError(_0x1d6c0a,null));};exports[_0x7dc9('0x49')]=function(_0x346d27,_0x510e2a){return db[_0x7dc9('0x3b')][_0x7dc9('0x49')]()[_0x7dc9('0x21')](respondWithResult(_0x510e2a,null))['catch'](handleError(_0x510e2a,null));};exports[_0x7dc9('0x4a')]=function(_0x3fc164,_0x2cf133,_0x32bc31){var _0xf41b8c=require(_0x7dc9('0x4b'));var _0x593132=![];var _0x366b8b={};if(_0x3fc164[_0x7dc9('0x29')][_0x7dc9('0x39')]&&_0x3fc164[_0x7dc9('0x29')][_0x7dc9('0x39')]===_0x7dc9('0x4c')){_0x366b8b[_0x7dc9('0x4c')]=_0x3fc164[_0x7dc9('0x40')]['id'];}else{_0x366b8b['id']=_0x3fc164[_0x7dc9('0x40')]['id'];}return db[_0x7dc9('0x3b')][_0x7dc9('0x42')]({'where':_0x366b8b,'attributes':['id',_0x7dc9('0x48')],'raw':!![]})['then'](handleEntityNotFound(_0x2cf133,null))[_0x7dc9('0x21')](function(_0x39be46){if(_0x39be46){var _0x38df9a=path[_0x7dc9('0x4d')](config[_0x7dc9('0x4e')],'server/files/screen_recordings',_0x39be46[_0x7dc9('0x48')]);var _0xd8d327=util[_0x7dc9('0x28')](_0x7dc9('0x4f'),_0x38df9a);if(fs[_0x7dc9('0x50')](_0xd8d327)){_0x593132=!![];return _0xf41b8c[_0x7dc9('0x51')](_0xd8d327,_0x38df9a,config['secrets']['recording'])['then'](function(){return _0x39be46;});}return _0x39be46;}})[_0x7dc9('0x21')](function(_0x3daf33){if(_0x3daf33){var _0x32a64f=path[_0x7dc9('0x4d')](config['root'],'server/files/screen_recordings',_0x3daf33[_0x7dc9('0x48')]);if(!fs[_0x7dc9('0x50')](_0x32a64f)){throw new db[(_0x7dc9('0x52'))][(_0x7dc9('0x53'))](_0x7dc9('0x54'));}if(_0x3daf33[_0x7dc9('0x55')]){return _0x2cf133[_0x7dc9('0x4a')](_0x32a64f,_0x3daf33['filename']+path[_0x7dc9('0x56')](_0x32a64f),function(){if(_0x593132){fs[_0x7dc9('0x57')](_0x32a64f);}});}else{return _0x2cf133[_0x7dc9('0x4a')](_0x32a64f,function(_0x1dad95){if(_0x593132){fs[_0x7dc9('0x57')](_0x32a64f);}});}}})['catch'](function(_0x175858){if(_0x175858[_0x7dc9('0x58')]===_0x7dc9('0x54')){_0x2cf133[_0x7dc9('0x16')](0x194)[_0x7dc9('0x25')](_0x7dc9('0x59'));}else{return handleError(_0x2cf133,null);}});};exports[_0x7dc9('0x5a')]=function(_0x2a02ed,_0x3463e4){return db[_0x7dc9('0x3b')][_0x7dc9('0x42')]({'where':{'id':_0x2a02ed[_0x7dc9('0x40')]['id']}})[_0x7dc9('0x21')](function(_0x5eee27){if(_[_0x7dc9('0x5b')](_0x5eee27)){throw new ReferenceError('Entity\x20not\x20found');}return _0x5eee27;})[_0x7dc9('0x21')](function(_0x15cf19){var _0x48ea37=path[_0x7dc9('0x4d')](config[_0x7dc9('0x4e')],'server/files/screen_recordings',_0x15cf19[_0x7dc9('0x48')]);logger[_0x7dc9('0x5c')](_0x7dc9('0x5d'),_0x48ea37);if(!_['isNil'](_0x15cf19['value'])&&fs[_0x7dc9('0x50')](_0x48ea37)){logger[_0x7dc9('0x5c')](_0x7dc9('0x5e')+_0x48ea37+_0x7dc9('0x5f'));fs[_0x7dc9('0x60')](_0x48ea37);}_0x48ea37=_0x48ea37+_0x7dc9('0x61');if(!_[_0x7dc9('0x5b')](_0x15cf19[_0x7dc9('0x48')])&&fs[_0x7dc9('0x50')](_0x48ea37)){logger['info'](_0x7dc9('0x5e')+_0x48ea37+_0x7dc9('0x5f'));fs[_0x7dc9('0x60')](_0x48ea37);}return _0x15cf19;})['then'](function(_0x4f80bd){if(!_0x4f80bd)throw new InternalError();return _0x4f80bd[_0x7dc9('0x5a')]();})[_0x7dc9('0x21')](function(){_0x3463e4[_0x7dc9('0x16')](0xcc)[_0x7dc9('0x17')]();})['catch'](handleError(_0x3463e4,null));};