d60bd479c340f46370a17965f8d9468d081ca060
[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 _0x22bb=['hasOwnProperty','nolimit','order','sort','filters','pick','filter','merge','where','VIRTUAL','options','count','include','findAll','rows','catch','params','keys','includeAll','find','create','body','duration','createdAt','closedAt','value','describe','download','../../components/encryptor','type','root','server/files/screen_recordings','%s.cypher','existsSync','decryptFile','secrets','recording','Sequelize','ValidationError','ScreenRecording\x20not\x20found','filename','extname','unlink','Not\x20found','Entity\x20not\x20found','cancellazione\x20fisica\x20documento\x20%s','File:\x20\x22','\x22\x20trovato\x20eseguo\x20la\x20cancellazione','unlinkSync','.cypher','isNil','info','html-pdf','rimraf','zip-dir','fast-json-patch','request-promise','moment','mustache','path','sox','to-csv','lodash','squel','crypto','desk.js','querystring','papaparse','ioredis','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','sendStatus','status','end','offset','limit','set','Content-Range','json','apply','destroy','then','stack','name','send','index','map','ScreenRecording','rawAttributes','model','differenceBy','format','query','intersection','attributes','fields','length'];(function(_0x38f4f1,_0x556542){var _0x276d57=function(_0x338c15){while(--_0x338c15){_0x38f4f1['push'](_0x38f4f1['shift']());}};_0x276d57(++_0x556542);}(_0x22bb,0x104));var _0xb22b=function(_0x21549c,_0x6d64d1){_0x21549c=_0x21549c-0x0;var _0x426cbd=_0x22bb[_0x21549c];return _0x426cbd;};'use strict';var pdf=require(_0xb22b('0x0'));var emlformat=require('eml-format');var rimraf=require(_0xb22b('0x1'));var zipdir=require(_0xb22b('0x2'));var jsonpatch=require(_0xb22b('0x3'));var rp=require(_0xb22b('0x4'));var moment=require(_0xb22b('0x5'));var BPromise=require('bluebird');var Mustache=require(_0xb22b('0x6'));var util=require('util');var path=require(_0xb22b('0x7'));var sox=require(_0xb22b('0x8'));var csv=require(_0xb22b('0x9'));var ejs=require('ejs');var fs=require('fs');var _=require(_0xb22b('0xa'));var squel=require(_0xb22b('0xb'));var crypto=require(_0xb22b('0xc'));var jsforce=require('jsforce');var deskjs=require(_0xb22b('0xd'));var toCsv=require(_0xb22b('0x9'));var querystring=require(_0xb22b('0xe'));var Papa=require(_0xb22b('0xf'));var Redis=require(_0xb22b('0x10'));var authService=require('../../components/auth/service');var qs=require(_0xb22b('0x11'));var as=require(_0xb22b('0x12'));var hardwareService=require(_0xb22b('0x13'));var logger=require(_0xb22b('0x14'))(_0xb22b('0x15'));var utils=require(_0xb22b('0x16'));var config=require(_0xb22b('0x17'));var licenseUtil=require(_0xb22b('0x18'));var db=require(_0xb22b('0x19'))['db'];function respondWithStatusCode(_0x4b7cfb,_0xa054c6){_0xa054c6=_0xa054c6||0xcc;return function(_0x2a71cd){if(_0x2a71cd){return _0x4b7cfb[_0xb22b('0x1a')](_0xa054c6);}return _0x4b7cfb[_0xb22b('0x1b')](_0xa054c6)[_0xb22b('0x1c')]();};}function respondWithResult(_0x2aa25a,_0x515a24){_0x515a24=_0x515a24||0xc8;return function(_0x396a06){if(_0x396a06){return _0x2aa25a['status'](_0x515a24)['json'](_0x396a06);}};}function respondWithFilteredResult(_0x575adc,_0x189f14){return function(_0xc764a){if(_0xc764a){var _0x20bf80=_0xc764a['count'],_0x14abfe=_0x189f14[_0xb22b('0x1d')],_0xff13d1=_0x189f14[_0xb22b('0x1d')]+_0x189f14[_0xb22b('0x1e')],_0x21ebba;if(_0xff13d1>=_0x20bf80){_0xff13d1=_0x20bf80;_0x21ebba=0xc8;}else{_0x21ebba=0xce;}_0x575adc['status'](_0x21ebba);return _0x575adc[_0xb22b('0x1f')](_0xb22b('0x20'),_0x14abfe+'-'+_0xff13d1+'/'+_0x20bf80)[_0xb22b('0x21')](_0xc764a);}return null;};}function patchUpdates(_0x2662a9){return function(_0x3131c9){try{jsonpatch[_0xb22b('0x22')](_0x3131c9,_0x2662a9,!![]);}catch(_0x1452a4){return BPromise['reject'](_0x1452a4);}return _0x3131c9['save']();};}function saveUpdates(_0x4e5dc7,_0x52de9a){return function(_0x3064ff){if(_0x3064ff){return _0x3064ff['update'](_0x4e5dc7)['then'](function(_0x3992d5){return _0x3992d5;});}return null;};}function removeEntity(_0xda6a6c,_0x21ba71){return function(_0xaceaf9){if(_0xaceaf9){return _0xaceaf9[_0xb22b('0x23')]()[_0xb22b('0x24')](function(){_0xda6a6c[_0xb22b('0x1b')](0xcc)[_0xb22b('0x1c')]();});}};}function handleEntityNotFound(_0x44e7ad,_0x399fb7){return function(_0x4832de){if(!_0x4832de){_0x44e7ad[_0xb22b('0x1a')](0x194);}return _0x4832de;};}function handleError(_0x3dc8d2,_0x445807){_0x445807=_0x445807||0x1f4;return function(_0x5ac690){logger['error'](_0x5ac690[_0xb22b('0x25')]);if(_0x5ac690[_0xb22b('0x26')]){delete _0x5ac690[_0xb22b('0x26')];}_0x3dc8d2[_0xb22b('0x1b')](_0x445807)[_0xb22b('0x27')](_0x5ac690);};}exports[_0xb22b('0x28')]=function(_0x3fdc12,_0x4bdc2e){var _0xefb7bc={},_0x595791={},_0x12349e={'count':0x0,'rows':[]};var _0x24425b=_[_0xb22b('0x29')](db[_0xb22b('0x2a')][_0xb22b('0x2b')],function(_0x4f1116){return{'name':_0x4f1116['fieldName'],'type':_0x4f1116['type']['key']};});_0x595791[_0xb22b('0x2c')]=_[_0xb22b('0x2d')](_[_0xb22b('0x29')](_0x24425b,'name'),[_0xb22b('0x2e')]);_0x595791['query']=_['keys'](_0x3fdc12[_0xb22b('0x2f')]);_0x595791['filters']=_[_0xb22b('0x30')](_0x595791[_0xb22b('0x2c')],_0x595791[_0xb22b('0x2f')]);_0xefb7bc[_0xb22b('0x31')]=_[_0xb22b('0x30')](_0x595791[_0xb22b('0x2c')],qs['fields'](_0x3fdc12[_0xb22b('0x2f')][_0xb22b('0x32')]));_0xefb7bc[_0xb22b('0x31')]=_0xefb7bc[_0xb22b('0x31')][_0xb22b('0x33')]?_0xefb7bc[_0xb22b('0x31')]:_0x595791[_0xb22b('0x2c')];if(!_0x3fdc12['query'][_0xb22b('0x34')](_0xb22b('0x35'))){_0xefb7bc[_0xb22b('0x1e')]=qs[_0xb22b('0x1e')](_0x3fdc12[_0xb22b('0x2f')][_0xb22b('0x1e')]);_0xefb7bc[_0xb22b('0x1d')]=qs[_0xb22b('0x1d')](_0x3fdc12[_0xb22b('0x2f')][_0xb22b('0x1d')]);}_0xefb7bc[_0xb22b('0x36')]=qs[_0xb22b('0x37')](_0x3fdc12[_0xb22b('0x2f')][_0xb22b('0x37')]);_0xefb7bc['where']=qs[_0xb22b('0x38')](_[_0xb22b('0x39')](_0x3fdc12[_0xb22b('0x2f')],_0x595791[_0xb22b('0x38')]),_0x24425b);if(_0x3fdc12['query'][_0xb22b('0x3a')]){_0xefb7bc['where']=_[_0xb22b('0x3b')](_0xefb7bc[_0xb22b('0x3c')],{'$or':_[_0xb22b('0x29')](_0x24425b,function(_0x248b17){if(_0x248b17['type']!==_0xb22b('0x3d')){var _0x1a64f3={};_0x1a64f3[_0x248b17[_0xb22b('0x26')]]={'$like':'%'+_0x3fdc12[_0xb22b('0x2f')][_0xb22b('0x3a')]+'%'};return _0x1a64f3;}})});}_0xefb7bc=_[_0xb22b('0x3b')]({},_0xefb7bc,_0x3fdc12[_0xb22b('0x3e')]);var _0x17486f={'where':_0xefb7bc[_0xb22b('0x3c')]};return db['ScreenRecording'][_0xb22b('0x3f')](_0x17486f)['then'](function(_0x3ef4e3){_0x12349e[_0xb22b('0x3f')]=_0x3ef4e3;if(_0x3fdc12[_0xb22b('0x2f')]['includeAll']){_0xefb7bc[_0xb22b('0x40')]=[{'all':!![]}];}return db[_0xb22b('0x2a')][_0xb22b('0x41')](_0xefb7bc);})[_0xb22b('0x24')](function(_0x4791ba){_0x12349e[_0xb22b('0x42')]=_0x4791ba;return _0x12349e;})[_0xb22b('0x24')](respondWithFilteredResult(_0x4bdc2e,_0xefb7bc))[_0xb22b('0x43')](handleError(_0x4bdc2e,null));};exports['show']=function(_0x347a7c,_0x5d2201){var _0x2d6cf7={'raw':![],'where':{'id':_0x347a7c[_0xb22b('0x44')]['id']}},_0x1144ed={};_0x1144ed[_0xb22b('0x2c')]=_[_0xb22b('0x45')](db[_0xb22b('0x2a')]['rawAttributes']);_0x1144ed[_0xb22b('0x2f')]=_[_0xb22b('0x45')](_0x347a7c[_0xb22b('0x2f')]);_0x1144ed[_0xb22b('0x38')]=_[_0xb22b('0x30')](_0x1144ed['model'],_0x1144ed[_0xb22b('0x2f')]);_0x2d6cf7[_0xb22b('0x31')]=_['intersection'](_0x1144ed[_0xb22b('0x2c')],qs['fields'](_0x347a7c[_0xb22b('0x2f')][_0xb22b('0x32')]));_0x2d6cf7[_0xb22b('0x31')]=_0x2d6cf7['attributes'][_0xb22b('0x33')]?_0x2d6cf7[_0xb22b('0x31')]:_0x1144ed['model'];if(_0x347a7c['query'][_0xb22b('0x46')]){_0x2d6cf7[_0xb22b('0x40')]=[{'all':!![]}];}_0x2d6cf7=_['merge']({},_0x2d6cf7,_0x347a7c[_0xb22b('0x3e')]);return db[_0xb22b('0x2a')][_0xb22b('0x47')](_0x2d6cf7)['then'](handleEntityNotFound(_0x5d2201,null))[_0xb22b('0x24')](respondWithResult(_0x5d2201,null))[_0xb22b('0x43')](handleError(_0x5d2201,null));};exports[_0xb22b('0x48')]=function(_0x95c91a,_0x482e74){return db[_0xb22b('0x2a')]['create'](_0x95c91a[_0xb22b('0x49')],{})[_0xb22b('0x24')](respondWithResult(_0x482e74,0xc9))[_0xb22b('0x43')](handleError(_0x482e74,null));};exports['update']=function(_0x1fe142,_0x436e7e){if(_0x1fe142[_0xb22b('0x49')]['id']){delete _0x1fe142[_0xb22b('0x49')]['id'];}delete _0x1fe142[_0xb22b('0x49')][_0xb22b('0x4a')];delete _0x1fe142[_0xb22b('0x49')][_0xb22b('0x4b')];delete _0x1fe142[_0xb22b('0x49')][_0xb22b('0x4c')];delete _0x1fe142[_0xb22b('0x49')][_0xb22b('0x4d')];return db[_0xb22b('0x2a')][_0xb22b('0x47')]({'where':{'id':_0x1fe142[_0xb22b('0x44')]['id']}})[_0xb22b('0x24')](handleEntityNotFound(_0x436e7e,null))[_0xb22b('0x24')](saveUpdates(_0x1fe142[_0xb22b('0x49')],null))['then'](respondWithResult(_0x436e7e,null))['catch'](handleError(_0x436e7e,null));};exports[_0xb22b('0x4e')]=function(_0x297c23,_0x37a717){return db['ScreenRecording']['describe']()[_0xb22b('0x24')](respondWithResult(_0x37a717,null))[_0xb22b('0x43')](handleError(_0x37a717,null));};exports[_0xb22b('0x4f')]=function(_0x1c67e5,_0x4ad9ae,_0x347a23){var _0x232674=require(_0xb22b('0x50'));var _0x369770=![];var _0x194c5f={};if(_0x1c67e5['query'][_0xb22b('0x51')]&&_0x1c67e5[_0xb22b('0x2f')]['type']==='uniqueid'){_0x194c5f['uniqueid']=_0x1c67e5[_0xb22b('0x44')]['id'];}else{_0x194c5f['id']=_0x1c67e5[_0xb22b('0x44')]['id'];}return db['ScreenRecording']['find']({'where':_0x194c5f,'attributes':['id',_0xb22b('0x4d')],'raw':!![]})[_0xb22b('0x24')](handleEntityNotFound(_0x4ad9ae,null))[_0xb22b('0x24')](function(_0x2ee06d){if(_0x2ee06d){var _0x1cf32e=path['join'](config[_0xb22b('0x52')],_0xb22b('0x53'),_0x2ee06d[_0xb22b('0x4d')]);var _0x573056=util['format'](_0xb22b('0x54'),_0x1cf32e);if(fs[_0xb22b('0x55')](_0x573056)){_0x369770=!![];return _0x232674[_0xb22b('0x56')](_0x573056,_0x1cf32e,config[_0xb22b('0x57')][_0xb22b('0x58')])[_0xb22b('0x24')](function(){return _0x2ee06d;});}return _0x2ee06d;}})['then'](function(_0x60aa62){if(_0x60aa62){var _0x388eac=path['join'](config['root'],_0xb22b('0x53'),_0x60aa62[_0xb22b('0x4d')]);if(!fs['existsSync'](_0x388eac)){throw new db[(_0xb22b('0x59'))][(_0xb22b('0x5a'))](_0xb22b('0x5b'));}if(_0x60aa62[_0xb22b('0x5c')]){return _0x4ad9ae[_0xb22b('0x4f')](_0x388eac,_0x60aa62['filename']+path[_0xb22b('0x5d')](_0x388eac),function(){if(_0x369770){fs[_0xb22b('0x5e')](_0x388eac);}});}else{return _0x4ad9ae[_0xb22b('0x4f')](_0x388eac,function(_0x282c0a){if(_0x369770){fs[_0xb22b('0x5e')](_0x388eac);}});}}})['catch'](function(_0x4223af){if(_0x4223af['message']===_0xb22b('0x5b')){_0x4ad9ae[_0xb22b('0x1b')](0x194)[_0xb22b('0x27')](_0xb22b('0x5f'));}else{return handleError(_0x4ad9ae,null);}});};exports[_0xb22b('0x23')]=function(_0x7f98b,_0x169559){return db[_0xb22b('0x2a')][_0xb22b('0x47')]({'where':{'id':_0x7f98b['params']['id']}})[_0xb22b('0x24')](function(_0x2dda47){if(!_0x2dda47)throw new ReferenceError(_0xb22b('0x60'));return _0x2dda47;})[_0xb22b('0x24')](function(_0x415751){var _0x167627=path['join'](config[_0xb22b('0x52')],'server/files/screen_recordings',_0x415751[_0xb22b('0x4d')]);logger['info'](_0xb22b('0x61'),_0x167627);if(!_['isNil'](_0x415751[_0xb22b('0x4d')])&&fs[_0xb22b('0x55')](_0x167627)){logger['info'](_0xb22b('0x62')+_0x167627+_0xb22b('0x63'));fs[_0xb22b('0x64')](_0x167627);}_0x167627=_0x167627+_0xb22b('0x65');if(!_[_0xb22b('0x66')](_0x415751[_0xb22b('0x4d')])&&fs[_0xb22b('0x55')](_0x167627)){logger[_0xb22b('0x67')]('File:\x20\x22'+_0x167627+_0xb22b('0x63'));fs[_0xb22b('0x64')](_0x167627);}return _0x415751;})[_0xb22b('0x24')](function(_0x2866a4){if(!_0x2866a4)throw new InternalError();return _0x2866a4[_0xb22b('0x23')]();})[_0xb22b('0x24')](function(){_0x169559[_0xb22b('0x1b')](0xcc)[_0xb22b('0x1c')]();})[_0xb22b('0x43')](handleError(_0x169559,null));};