19417931dde631114cc96420635e8a347d1922fd
[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 _0x0f9f=['../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','../../config/license/util','status','end','offset','limit','Content-Range','json','apply','reject','save','update','destroy','then','sendStatus','error','name','send','index','map','rawAttributes','type','key','model','differenceBy','format','keys','query','intersection','attributes','fields','length','hasOwnProperty','nolimit','order','sort','where','pick','filters','filter','merge','VIRTUAL','options','count','findAll','catch','includeAll','include','ScreenRecording','body','duration','value','find','params','describe','../../components/encryptor','uniqueid','server/files/screen_recordings','%s.cypher','existsSync','secrets','join','ValidationError','ScreenRecording\x20not\x20found','filename','download','extname','unlink','message','Not\x20found','Entity\x20not\x20found','root','info','cancellazione\x20fisica\x20documento\x20%s','File:\x20\x22','\x22\x20trovato\x20eseguo\x20la\x20cancellazione','unlinkSync','eml-format','rimraf','request-promise','bluebird','mustache','util','path','sox','to-csv','ejs','fs-extra','lodash','squel','crypto','jsforce','papaparse'];(function(_0x1ac9f1,_0x2de131){var _0x2924dc=function(_0x3b6c50){while(--_0x3b6c50){_0x1ac9f1['push'](_0x1ac9f1['shift']());}};_0x2924dc(++_0x2de131);}(_0x0f9f,0x180));var _0xf0f9=function(_0x515ef1,_0x476d57){_0x515ef1=_0x515ef1-0x0;var _0x2081a6=_0x0f9f[_0x515ef1];return _0x2081a6;};'use strict';var emlformat=require(_0xf0f9('0x0'));var rimraf=require(_0xf0f9('0x1'));var zipdir=require('zip-dir');var jsonpatch=require('fast-json-patch');var rp=require(_0xf0f9('0x2'));var moment=require('moment');var BPromise=require(_0xf0f9('0x3'));var Mustache=require(_0xf0f9('0x4'));var util=require(_0xf0f9('0x5'));var path=require(_0xf0f9('0x6'));var sox=require(_0xf0f9('0x7'));var csv=require(_0xf0f9('0x8'));var ejs=require(_0xf0f9('0x9'));var fs=require('fs');var fs_extra=require(_0xf0f9('0xa'));var _=require(_0xf0f9('0xb'));var squel=require(_0xf0f9('0xc'));var crypto=require(_0xf0f9('0xd'));var jsforce=require(_0xf0f9('0xe'));var deskjs=require('desk.js');var toCsv=require(_0xf0f9('0x8'));var querystring=require('querystring');var Papa=require(_0xf0f9('0xf'));var Redis=require('ioredis');var authService=require(_0xf0f9('0x10'));var qs=require(_0xf0f9('0x11'));var as=require(_0xf0f9('0x12'));var hardwareService=require(_0xf0f9('0x13'));var logger=require(_0xf0f9('0x14'))(_0xf0f9('0x15'));var utils=require(_0xf0f9('0x16'));var config=require(_0xf0f9('0x17'));var licenseUtil=require(_0xf0f9('0x18'));var db=require('../../mysqldb')['db'];function respondWithStatusCode(_0x4f8f0d,_0x232e80){_0x232e80=_0x232e80||0xcc;return function(_0x4918c7){if(_0x4918c7){return _0x4f8f0d['sendStatus'](_0x232e80);}return _0x4f8f0d[_0xf0f9('0x19')](_0x232e80)[_0xf0f9('0x1a')]();};}function respondWithResult(_0x5b7861,_0x504868){_0x504868=_0x504868||0xc8;return function(_0x12e38e){if(_0x12e38e){return _0x5b7861[_0xf0f9('0x19')](_0x504868)['json'](_0x12e38e);}};}function respondWithFilteredResult(_0x431d95,_0x353468){return function(_0x32badd){if(_0x32badd){var _0x29d38a=_0x32badd['count'],_0x14c03f=_0x353468[_0xf0f9('0x1b')],_0xd38196=_0x353468[_0xf0f9('0x1b')]+_0x353468[_0xf0f9('0x1c')],_0x5d4119;if(_0xd38196>=_0x29d38a){_0xd38196=_0x29d38a;_0x5d4119=0xc8;}else{_0x5d4119=0xce;}_0x431d95[_0xf0f9('0x19')](_0x5d4119);return _0x431d95['set'](_0xf0f9('0x1d'),_0x14c03f+'-'+_0xd38196+'/'+_0x29d38a)[_0xf0f9('0x1e')](_0x32badd);}return null;};}function patchUpdates(_0x3ccd49){return function(_0x38a166){try{jsonpatch[_0xf0f9('0x1f')](_0x38a166,_0x3ccd49,!![]);}catch(_0x45b6db){return BPromise[_0xf0f9('0x20')](_0x45b6db);}return _0x38a166[_0xf0f9('0x21')]();};}function saveUpdates(_0x5a0ff6,_0x5e2954){return function(_0x5c810e){if(_0x5c810e){return _0x5c810e[_0xf0f9('0x22')](_0x5a0ff6)['then'](function(_0x214bc4){return _0x214bc4;});}return null;};}function removeEntity(_0x1485ce,_0x1baf8d){return function(_0x16b5be){if(_0x16b5be){return _0x16b5be[_0xf0f9('0x23')]()[_0xf0f9('0x24')](function(){_0x1485ce[_0xf0f9('0x19')](0xcc)[_0xf0f9('0x1a')]();});}};}function handleEntityNotFound(_0x3abe4a,_0x3c943d){return function(_0x575fb0){if(!_0x575fb0){_0x3abe4a[_0xf0f9('0x25')](0x194);}return _0x575fb0;};}function handleError(_0x31a980,_0x4026f4){_0x4026f4=_0x4026f4||0x1f4;return function(_0x49f97b){logger[_0xf0f9('0x26')](_0x49f97b['stack']);if(_0x49f97b[_0xf0f9('0x27')]){delete _0x49f97b['name'];}_0x31a980[_0xf0f9('0x19')](_0x4026f4)[_0xf0f9('0x28')](_0x49f97b);};}exports[_0xf0f9('0x29')]=function(_0x56dae9,_0x365813){var _0x5396ca={},_0x2747e5={},_0x28030d={'count':0x0,'rows':[]};var _0x43e693=_[_0xf0f9('0x2a')](db['ScreenRecording'][_0xf0f9('0x2b')],function(_0xdaae){return{'name':_0xdaae['fieldName'],'type':_0xdaae[_0xf0f9('0x2c')][_0xf0f9('0x2d')]};});_0x2747e5[_0xf0f9('0x2e')]=_[_0xf0f9('0x2f')](_[_0xf0f9('0x2a')](_0x43e693,'name'),[_0xf0f9('0x30')]);_0x2747e5['query']=_[_0xf0f9('0x31')](_0x56dae9[_0xf0f9('0x32')]);_0x2747e5['filters']=_[_0xf0f9('0x33')](_0x2747e5[_0xf0f9('0x2e')],_0x2747e5['query']);_0x5396ca[_0xf0f9('0x34')]=_[_0xf0f9('0x33')](_0x2747e5[_0xf0f9('0x2e')],qs[_0xf0f9('0x35')](_0x56dae9[_0xf0f9('0x32')][_0xf0f9('0x35')]));_0x5396ca['attributes']=_0x5396ca[_0xf0f9('0x34')][_0xf0f9('0x36')]?_0x5396ca[_0xf0f9('0x34')]:_0x2747e5[_0xf0f9('0x2e')];if(!_0x56dae9[_0xf0f9('0x32')][_0xf0f9('0x37')](_0xf0f9('0x38'))){_0x5396ca[_0xf0f9('0x1c')]=qs[_0xf0f9('0x1c')](_0x56dae9['query']['limit']);_0x5396ca[_0xf0f9('0x1b')]=qs['offset'](_0x56dae9[_0xf0f9('0x32')][_0xf0f9('0x1b')]);}_0x5396ca[_0xf0f9('0x39')]=qs[_0xf0f9('0x3a')](_0x56dae9[_0xf0f9('0x32')][_0xf0f9('0x3a')]);_0x5396ca[_0xf0f9('0x3b')]=qs['filters'](_[_0xf0f9('0x3c')](_0x56dae9[_0xf0f9('0x32')],_0x2747e5[_0xf0f9('0x3d')]),_0x43e693);if(_0x56dae9[_0xf0f9('0x32')][_0xf0f9('0x3e')]){_0x5396ca[_0xf0f9('0x3b')]=_[_0xf0f9('0x3f')](_0x5396ca[_0xf0f9('0x3b')],{'$or':_[_0xf0f9('0x2a')](_0x43e693,function(_0x6435a0){if(_0x6435a0['type']!==_0xf0f9('0x40')){var _0x118cc9={};_0x118cc9[_0x6435a0[_0xf0f9('0x27')]]={'$like':'%'+_0x56dae9['query'][_0xf0f9('0x3e')]+'%'};return _0x118cc9;}})});}_0x5396ca=_[_0xf0f9('0x3f')]({},_0x5396ca,_0x56dae9[_0xf0f9('0x41')]);var _0x3f5444={'where':_0x5396ca[_0xf0f9('0x3b')]};return db['ScreenRecording'][_0xf0f9('0x42')](_0x3f5444)['then'](function(_0x4cc6ca){_0x28030d[_0xf0f9('0x42')]=_0x4cc6ca;if(_0x56dae9[_0xf0f9('0x32')]['includeAll']){_0x5396ca['include']=[{'all':!![]}];}return db['ScreenRecording'][_0xf0f9('0x43')](_0x5396ca);})[_0xf0f9('0x24')](function(_0x896404){_0x28030d['rows']=_0x896404;return _0x28030d;})[_0xf0f9('0x24')](respondWithFilteredResult(_0x365813,_0x5396ca))[_0xf0f9('0x44')](handleError(_0x365813,null));};exports['show']=function(_0x2abcfa,_0x1a9e72){var _0x35d775={'raw':![],'where':{'id':_0x2abcfa['params']['id']}},_0x25838f={};_0x25838f[_0xf0f9('0x2e')]=_[_0xf0f9('0x31')](db['ScreenRecording'][_0xf0f9('0x2b')]);_0x25838f['query']=_['keys'](_0x2abcfa[_0xf0f9('0x32')]);_0x25838f[_0xf0f9('0x3d')]=_[_0xf0f9('0x33')](_0x25838f[_0xf0f9('0x2e')],_0x25838f[_0xf0f9('0x32')]);_0x35d775[_0xf0f9('0x34')]=_['intersection'](_0x25838f[_0xf0f9('0x2e')],qs[_0xf0f9('0x35')](_0x2abcfa[_0xf0f9('0x32')][_0xf0f9('0x35')]));_0x35d775[_0xf0f9('0x34')]=_0x35d775[_0xf0f9('0x34')][_0xf0f9('0x36')]?_0x35d775['attributes']:_0x25838f['model'];if(_0x2abcfa[_0xf0f9('0x32')][_0xf0f9('0x45')]){_0x35d775[_0xf0f9('0x46')]=[{'all':!![]}];}_0x35d775=_['merge']({},_0x35d775,_0x2abcfa[_0xf0f9('0x41')]);return db['ScreenRecording']['find'](_0x35d775)[_0xf0f9('0x24')](handleEntityNotFound(_0x1a9e72,null))[_0xf0f9('0x24')](respondWithResult(_0x1a9e72,null))[_0xf0f9('0x44')](handleError(_0x1a9e72,null));};exports['create']=function(_0x888868,_0x402a2e){return db[_0xf0f9('0x47')]['create'](_0x888868[_0xf0f9('0x48')],{})[_0xf0f9('0x24')](respondWithResult(_0x402a2e,0xc9))['catch'](handleError(_0x402a2e,null));};exports['update']=function(_0xffeea3,_0xfa23cc){if(_0xffeea3['body']['id']){delete _0xffeea3[_0xf0f9('0x48')]['id'];}delete _0xffeea3['body'][_0xf0f9('0x49')];delete _0xffeea3[_0xf0f9('0x48')]['createdAt'];delete _0xffeea3[_0xf0f9('0x48')]['closedAt'];delete _0xffeea3[_0xf0f9('0x48')][_0xf0f9('0x4a')];return db[_0xf0f9('0x47')][_0xf0f9('0x4b')]({'where':{'id':_0xffeea3[_0xf0f9('0x4c')]['id']}})[_0xf0f9('0x24')](handleEntityNotFound(_0xfa23cc,null))[_0xf0f9('0x24')](saveUpdates(_0xffeea3[_0xf0f9('0x48')],null))[_0xf0f9('0x24')](respondWithResult(_0xfa23cc,null))['catch'](handleError(_0xfa23cc,null));};exports['describe']=function(_0x2e0b73,_0x3f100f){return db[_0xf0f9('0x47')][_0xf0f9('0x4d')]()['then'](respondWithResult(_0x3f100f,null))[_0xf0f9('0x44')](handleError(_0x3f100f,null));};exports['download']=function(_0x103fff,_0x16a72e,_0x1c7689){var _0x475243=require(_0xf0f9('0x4e'));var _0x543959=![];var _0x1a0206={};if(_0x103fff[_0xf0f9('0x32')][_0xf0f9('0x2c')]&&_0x103fff[_0xf0f9('0x32')][_0xf0f9('0x2c')]===_0xf0f9('0x4f')){_0x1a0206['uniqueid']=_0x103fff[_0xf0f9('0x4c')]['id'];}else{_0x1a0206['id']=_0x103fff[_0xf0f9('0x4c')]['id'];}return db[_0xf0f9('0x47')][_0xf0f9('0x4b')]({'where':_0x1a0206,'attributes':['id',_0xf0f9('0x4a')],'raw':!![]})[_0xf0f9('0x24')](handleEntityNotFound(_0x16a72e,null))['then'](function(_0x3fdb9b){if(_0x3fdb9b){var _0x31370e=path['join'](config['root'],_0xf0f9('0x50'),_0x3fdb9b[_0xf0f9('0x4a')]);var _0x31e8e5=util[_0xf0f9('0x30')](_0xf0f9('0x51'),_0x31370e);if(fs[_0xf0f9('0x52')](_0x31e8e5)){_0x543959=!![];return _0x475243['decryptFile'](_0x31e8e5,_0x31370e,config[_0xf0f9('0x53')]['recording'])['then'](function(){return _0x3fdb9b;});}return _0x3fdb9b;}})['then'](function(_0x5e5b1d){if(_0x5e5b1d){var _0x3bfeb1=path[_0xf0f9('0x54')](config['root'],'server/files/screen_recordings',_0x5e5b1d[_0xf0f9('0x4a')]);if(!fs['existsSync'](_0x3bfeb1)){throw new db['Sequelize'][(_0xf0f9('0x55'))](_0xf0f9('0x56'));}if(_0x5e5b1d[_0xf0f9('0x57')]){return _0x16a72e[_0xf0f9('0x58')](_0x3bfeb1,_0x5e5b1d['filename']+path[_0xf0f9('0x59')](_0x3bfeb1),function(){if(_0x543959){fs[_0xf0f9('0x5a')](_0x3bfeb1);}});}else{return _0x16a72e[_0xf0f9('0x58')](_0x3bfeb1,function(_0x17a862){if(_0x543959){fs[_0xf0f9('0x5a')](_0x3bfeb1);}});}}})['catch'](function(_0x14538a){if(_0x14538a[_0xf0f9('0x5b')]===_0xf0f9('0x56')){_0x16a72e[_0xf0f9('0x19')](0x194)['send'](_0xf0f9('0x5c'));}else{return handleError(_0x16a72e,null);}});};exports[_0xf0f9('0x23')]=function(_0x2fb10c,_0x3e1da1){return db[_0xf0f9('0x47')]['find']({'where':{'id':_0x2fb10c[_0xf0f9('0x4c')]['id']}})['then'](function(_0x227b9e){if(!_0x227b9e)throw new ReferenceError(_0xf0f9('0x5d'));return _0x227b9e;})[_0xf0f9('0x24')](function(_0x1cdd78){var _0xa59dbb=path[_0xf0f9('0x54')](config[_0xf0f9('0x5e')],_0xf0f9('0x50'),_0x1cdd78[_0xf0f9('0x4a')]);logger[_0xf0f9('0x5f')](_0xf0f9('0x60'),_0xa59dbb);if(!_['isNil'](_0x1cdd78[_0xf0f9('0x4a')])&&fs[_0xf0f9('0x52')](_0xa59dbb)){logger['info'](_0xf0f9('0x61')+_0xa59dbb+_0xf0f9('0x62'));fs[_0xf0f9('0x63')](_0xa59dbb);}_0xa59dbb=_0xa59dbb+'.cypher';if(!_['isNil'](_0x1cdd78[_0xf0f9('0x4a')])&&fs['existsSync'](_0xa59dbb)){logger[_0xf0f9('0x5f')](_0xf0f9('0x61')+_0xa59dbb+_0xf0f9('0x62'));fs[_0xf0f9('0x63')](_0xa59dbb);}return _0x1cdd78;})[_0xf0f9('0x24')](function(_0x1056ac){if(!_0x1056ac)throw new InternalError();return _0x1056ac[_0xf0f9('0x23')]();})['then'](function(){_0x3e1da1[_0xf0f9('0x19')](0xcc)[_0xf0f9('0x1a')]();})[_0xf0f9('0x44')](handleError(_0x3e1da1,null));};