b8a6196f016047fbb85bb80c6145a31c6a7ec0ef
[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 _0x9ebf=['update','then','destroy','stack','name','send','index','map','ScreenRecording','rawAttributes','type','differenceBy','format','query','keys','filters','intersection','attributes','fields','length','model','hasOwnProperty','offset','order','sort','where','pick','filter','merge','options','count','includeAll','include','findAll','catch','show','params','find','create','body','duration','createdAt','closedAt','value','describe','download','../../components/encryptor','uniqueid','join','root','existsSync','decryptFile','secrets','recording','Sequelize','filename','extname','unlink','ScreenRecording\x20not\x20found','info','cancellazione\x20fisica\x20documento\x20%s','isNil','\x22\x20trovato\x20eseguo\x20la\x20cancellazione','unlinkSync','.cypher','eml-format','rimraf','zip-dir','fast-json-patch','moment','bluebird','mustache','path','sox','to-csv','fs-extra','lodash','crypto','jsforce','papaparse','ioredis','../../components/auth/service','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','sendStatus','status','end','limit','set','json','apply','reject'];(function(_0x11239b,_0xdfd2b0){var _0x1d51c4=function(_0x2bba88){while(--_0x2bba88){_0x11239b['push'](_0x11239b['shift']());}};_0x1d51c4(++_0xdfd2b0);}(_0x9ebf,0x105));var _0xf9eb=function(_0x199572,_0x33e667){_0x199572=_0x199572-0x0;var _0x13cfa3=_0x9ebf[_0x199572];return _0x13cfa3;};'use strict';var emlformat=require(_0xf9eb('0x0'));var rimraf=require(_0xf9eb('0x1'));var zipdir=require(_0xf9eb('0x2'));var jsonpatch=require(_0xf9eb('0x3'));var rp=require('request-promise');var moment=require(_0xf9eb('0x4'));var BPromise=require(_0xf9eb('0x5'));var Mustache=require(_0xf9eb('0x6'));var util=require('util');var path=require(_0xf9eb('0x7'));var sox=require(_0xf9eb('0x8'));var csv=require(_0xf9eb('0x9'));var ejs=require('ejs');var fs=require('fs');var fs_extra=require(_0xf9eb('0xa'));var _=require(_0xf9eb('0xb'));var squel=require('squel');var crypto=require(_0xf9eb('0xc'));var jsforce=require(_0xf9eb('0xd'));var deskjs=require('desk.js');var toCsv=require(_0xf9eb('0x9'));var querystring=require('querystring');var Papa=require(_0xf9eb('0xe'));var Redis=require(_0xf9eb('0xf'));var authService=require(_0xf9eb('0x10'));var qs=require('../../components/parsers/qs');var as=require(_0xf9eb('0x11'));var hardwareService=require(_0xf9eb('0x12'));var logger=require(_0xf9eb('0x13'))(_0xf9eb('0x14'));var utils=require(_0xf9eb('0x15'));var config=require(_0xf9eb('0x16'));var licenseUtil=require(_0xf9eb('0x17'));var db=require(_0xf9eb('0x18'))['db'];function respondWithStatusCode(_0x2ec624,_0x1d75c4){_0x1d75c4=_0x1d75c4||0xcc;return function(_0x26c03a){if(_0x26c03a){return _0x2ec624[_0xf9eb('0x19')](_0x1d75c4);}return _0x2ec624[_0xf9eb('0x1a')](_0x1d75c4)[_0xf9eb('0x1b')]();};}function respondWithResult(_0x3b7e37,_0x1c3f75){_0x1c3f75=_0x1c3f75||0xc8;return function(_0x123215){if(_0x123215){return _0x3b7e37['status'](_0x1c3f75)['json'](_0x123215);}};}function respondWithFilteredResult(_0x271777,_0x3440b0){return function(_0x491990){if(_0x491990){var _0x25cd70=_0x491990['count'],_0x33fa20=_0x3440b0['offset'],_0x470e41=_0x3440b0['offset']+_0x3440b0[_0xf9eb('0x1c')],_0x490292;if(_0x470e41>=_0x25cd70){_0x470e41=_0x25cd70;_0x490292=0xc8;}else{_0x490292=0xce;}_0x271777[_0xf9eb('0x1a')](_0x490292);return _0x271777[_0xf9eb('0x1d')]('Content-Range',_0x33fa20+'-'+_0x470e41+'/'+_0x25cd70)[_0xf9eb('0x1e')](_0x491990);}return null;};}function patchUpdates(_0x43892c){return function(_0x384262){try{jsonpatch[_0xf9eb('0x1f')](_0x384262,_0x43892c,!![]);}catch(_0x5848ad){return BPromise[_0xf9eb('0x20')](_0x5848ad);}return _0x384262['save']();};}function saveUpdates(_0x2c248c,_0x4e760d){return function(_0x534c9b){if(_0x534c9b){return _0x534c9b[_0xf9eb('0x21')](_0x2c248c)[_0xf9eb('0x22')](function(_0x132f87){return _0x132f87;});}return null;};}function removeEntity(_0x18ba96,_0x35a489){return function(_0x3b9e73){if(_0x3b9e73){return _0x3b9e73[_0xf9eb('0x23')]()[_0xf9eb('0x22')](function(){_0x18ba96[_0xf9eb('0x1a')](0xcc)['end']();});}};}function handleEntityNotFound(_0x28ef1b,_0x3a7ef8){return function(_0x28c375){if(!_0x28c375){_0x28ef1b[_0xf9eb('0x19')](0x194);}return _0x28c375;};}function handleError(_0x35c130,_0x58a3c8){_0x58a3c8=_0x58a3c8||0x1f4;return function(_0x495170){logger['error'](_0x495170[_0xf9eb('0x24')]);if(_0x495170[_0xf9eb('0x25')]){delete _0x495170['name'];}_0x35c130['status'](_0x58a3c8)[_0xf9eb('0x26')](_0x495170);};}exports[_0xf9eb('0x27')]=function(_0xd927e7,_0x368136){var _0x12e152={},_0x40269f={},_0x1df9ca={'count':0x0,'rows':[]};var _0x10c612=_[_0xf9eb('0x28')](db[_0xf9eb('0x29')][_0xf9eb('0x2a')],function(_0x234a92){return{'name':_0x234a92['fieldName'],'type':_0x234a92[_0xf9eb('0x2b')]['key']};});_0x40269f['model']=_[_0xf9eb('0x2c')](_['map'](_0x10c612,_0xf9eb('0x25')),[_0xf9eb('0x2d')]);_0x40269f[_0xf9eb('0x2e')]=_[_0xf9eb('0x2f')](_0xd927e7[_0xf9eb('0x2e')]);_0x40269f[_0xf9eb('0x30')]=_[_0xf9eb('0x31')](_0x40269f['model'],_0x40269f[_0xf9eb('0x2e')]);_0x12e152[_0xf9eb('0x32')]=_['intersection'](_0x40269f['model'],qs[_0xf9eb('0x33')](_0xd927e7[_0xf9eb('0x2e')][_0xf9eb('0x33')]));_0x12e152[_0xf9eb('0x32')]=_0x12e152[_0xf9eb('0x32')][_0xf9eb('0x34')]?_0x12e152['attributes']:_0x40269f[_0xf9eb('0x35')];if(!_0xd927e7[_0xf9eb('0x2e')][_0xf9eb('0x36')]('nolimit')){_0x12e152[_0xf9eb('0x1c')]=qs[_0xf9eb('0x1c')](_0xd927e7[_0xf9eb('0x2e')]['limit']);_0x12e152['offset']=qs['offset'](_0xd927e7[_0xf9eb('0x2e')][_0xf9eb('0x37')]);}_0x12e152[_0xf9eb('0x38')]=qs[_0xf9eb('0x39')](_0xd927e7[_0xf9eb('0x2e')][_0xf9eb('0x39')]);_0x12e152[_0xf9eb('0x3a')]=qs[_0xf9eb('0x30')](_[_0xf9eb('0x3b')](_0xd927e7[_0xf9eb('0x2e')],_0x40269f[_0xf9eb('0x30')]),_0x10c612);if(_0xd927e7[_0xf9eb('0x2e')][_0xf9eb('0x3c')]){_0x12e152[_0xf9eb('0x3a')]=_[_0xf9eb('0x3d')](_0x12e152[_0xf9eb('0x3a')],{'$or':_[_0xf9eb('0x28')](_0x10c612,function(_0x4cd351){if(_0x4cd351[_0xf9eb('0x2b')]!=='VIRTUAL'){var _0x514233={};_0x514233[_0x4cd351[_0xf9eb('0x25')]]={'$like':'%'+_0xd927e7['query'][_0xf9eb('0x3c')]+'%'};return _0x514233;}})});}_0x12e152=_['merge']({},_0x12e152,_0xd927e7[_0xf9eb('0x3e')]);var _0x18c50c={'where':_0x12e152['where']};return db['ScreenRecording'][_0xf9eb('0x3f')](_0x18c50c)[_0xf9eb('0x22')](function(_0x303403){_0x1df9ca[_0xf9eb('0x3f')]=_0x303403;if(_0xd927e7[_0xf9eb('0x2e')][_0xf9eb('0x40')]){_0x12e152[_0xf9eb('0x41')]=[{'all':!![]}];}return db[_0xf9eb('0x29')][_0xf9eb('0x42')](_0x12e152);})[_0xf9eb('0x22')](function(_0x19c345){_0x1df9ca['rows']=_0x19c345;return _0x1df9ca;})[_0xf9eb('0x22')](respondWithFilteredResult(_0x368136,_0x12e152))[_0xf9eb('0x43')](handleError(_0x368136,null));};exports[_0xf9eb('0x44')]=function(_0x41c742,_0x4a91f0){var _0x1b38cc={'raw':![],'where':{'id':_0x41c742[_0xf9eb('0x45')]['id']}},_0xb54f88={};_0xb54f88['model']=_[_0xf9eb('0x2f')](db[_0xf9eb('0x29')][_0xf9eb('0x2a')]);_0xb54f88[_0xf9eb('0x2e')]=_[_0xf9eb('0x2f')](_0x41c742[_0xf9eb('0x2e')]);_0xb54f88['filters']=_[_0xf9eb('0x31')](_0xb54f88['model'],_0xb54f88[_0xf9eb('0x2e')]);_0x1b38cc[_0xf9eb('0x32')]=_[_0xf9eb('0x31')](_0xb54f88[_0xf9eb('0x35')],qs[_0xf9eb('0x33')](_0x41c742[_0xf9eb('0x2e')][_0xf9eb('0x33')]));_0x1b38cc[_0xf9eb('0x32')]=_0x1b38cc[_0xf9eb('0x32')][_0xf9eb('0x34')]?_0x1b38cc['attributes']:_0xb54f88[_0xf9eb('0x35')];if(_0x41c742[_0xf9eb('0x2e')]['includeAll']){_0x1b38cc[_0xf9eb('0x41')]=[{'all':!![]}];}_0x1b38cc=_[_0xf9eb('0x3d')]({},_0x1b38cc,_0x41c742[_0xf9eb('0x3e')]);return db[_0xf9eb('0x29')][_0xf9eb('0x46')](_0x1b38cc)['then'](handleEntityNotFound(_0x4a91f0,null))[_0xf9eb('0x22')](respondWithResult(_0x4a91f0,null))[_0xf9eb('0x43')](handleError(_0x4a91f0,null));};exports[_0xf9eb('0x47')]=function(_0x4173ed,_0x8ccf1){return db[_0xf9eb('0x29')][_0xf9eb('0x47')](_0x4173ed['body'],{})['then'](respondWithResult(_0x8ccf1,0xc9))[_0xf9eb('0x43')](handleError(_0x8ccf1,null));};exports[_0xf9eb('0x21')]=function(_0x4a9565,_0x19d9af){if(_0x4a9565[_0xf9eb('0x48')]['id']){delete _0x4a9565[_0xf9eb('0x48')]['id'];}delete _0x4a9565[_0xf9eb('0x48')][_0xf9eb('0x49')];delete _0x4a9565['body'][_0xf9eb('0x4a')];delete _0x4a9565[_0xf9eb('0x48')][_0xf9eb('0x4b')];delete _0x4a9565['body'][_0xf9eb('0x4c')];return db[_0xf9eb('0x29')][_0xf9eb('0x46')]({'where':{'id':_0x4a9565['params']['id']}})[_0xf9eb('0x22')](handleEntityNotFound(_0x19d9af,null))[_0xf9eb('0x22')](saveUpdates(_0x4a9565[_0xf9eb('0x48')],null))['then'](respondWithResult(_0x19d9af,null))[_0xf9eb('0x43')](handleError(_0x19d9af,null));};exports[_0xf9eb('0x4d')]=function(_0x44317d,_0xcab799){return db[_0xf9eb('0x29')][_0xf9eb('0x4d')]()[_0xf9eb('0x22')](respondWithResult(_0xcab799,null))[_0xf9eb('0x43')](handleError(_0xcab799,null));};exports[_0xf9eb('0x4e')]=function(_0x1537b5,_0x102f58,_0x5414d6){var _0x32d761=require(_0xf9eb('0x4f'));var _0x49515c=![];var _0x522d4c={};if(_0x1537b5[_0xf9eb('0x2e')]['type']&&_0x1537b5[_0xf9eb('0x2e')][_0xf9eb('0x2b')]===_0xf9eb('0x50')){_0x522d4c[_0xf9eb('0x50')]=_0x1537b5[_0xf9eb('0x45')]['id'];}else{_0x522d4c['id']=_0x1537b5[_0xf9eb('0x45')]['id'];}return db['ScreenRecording'][_0xf9eb('0x46')]({'where':_0x522d4c,'attributes':['id',_0xf9eb('0x4c')],'raw':!![]})[_0xf9eb('0x22')](handleEntityNotFound(_0x102f58,null))[_0xf9eb('0x22')](function(_0x5b2410){if(_0x5b2410){var _0x2d83be=path[_0xf9eb('0x51')](config[_0xf9eb('0x52')],'server/files/screen_recordings',_0x5b2410['value']);var _0x16836c=util[_0xf9eb('0x2d')]('%s.cypher',_0x2d83be);if(fs[_0xf9eb('0x53')](_0x16836c)){_0x49515c=!![];return _0x32d761[_0xf9eb('0x54')](_0x16836c,_0x2d83be,config[_0xf9eb('0x55')][_0xf9eb('0x56')])[_0xf9eb('0x22')](function(){return _0x5b2410;});}return _0x5b2410;}})['then'](function(_0x12d628){if(_0x12d628){var _0x55e939=path[_0xf9eb('0x51')](config['root'],'server/files/screen_recordings',_0x12d628[_0xf9eb('0x4c')]);if(!fs[_0xf9eb('0x53')](_0x55e939)){throw new db[(_0xf9eb('0x57'))]['ValidationError']('ScreenRecording\x20not\x20found');}if(_0x12d628[_0xf9eb('0x58')]){return _0x102f58[_0xf9eb('0x4e')](_0x55e939,_0x12d628[_0xf9eb('0x58')]+path[_0xf9eb('0x59')](_0x55e939),function(){if(_0x49515c){fs[_0xf9eb('0x5a')](_0x55e939);}});}else{return _0x102f58['download'](_0x55e939,function(_0x32a0e4){if(_0x49515c){fs['unlink'](_0x55e939);}});}}})['catch'](function(_0x5abe7f){if(_0x5abe7f['message']===_0xf9eb('0x5b')){_0x102f58[_0xf9eb('0x1a')](0x194)[_0xf9eb('0x26')]('Not\x20found');}else{return handleError(_0x102f58,null);}});};exports['destroy']=function(_0x430f9c,_0x19ef71){return db[_0xf9eb('0x29')][_0xf9eb('0x46')]({'where':{'id':_0x430f9c[_0xf9eb('0x45')]['id']}})[_0xf9eb('0x22')](function(_0x470922){if(!_0x470922)throw new ReferenceError('Entity\x20not\x20found');return _0x470922;})[_0xf9eb('0x22')](function(_0x19ace3){var _0x4ee7ab=path[_0xf9eb('0x51')](config['root'],'server/files/screen_recordings',_0x19ace3['value']);logger[_0xf9eb('0x5c')](_0xf9eb('0x5d'),_0x4ee7ab);if(!_[_0xf9eb('0x5e')](_0x19ace3[_0xf9eb('0x4c')])&&fs[_0xf9eb('0x53')](_0x4ee7ab)){logger['info']('File:\x20\x22'+_0x4ee7ab+_0xf9eb('0x5f'));fs[_0xf9eb('0x60')](_0x4ee7ab);}_0x4ee7ab=_0x4ee7ab+_0xf9eb('0x61');if(!_[_0xf9eb('0x5e')](_0x19ace3['value'])&&fs[_0xf9eb('0x53')](_0x4ee7ab)){logger[_0xf9eb('0x5c')]('File:\x20\x22'+_0x4ee7ab+_0xf9eb('0x5f'));fs[_0xf9eb('0x60')](_0x4ee7ab);}return _0x19ace3;})['then'](function(_0xb714a7){if(!_0xb714a7)throw new InternalError();return _0xb714a7[_0xf9eb('0x23')]();})[_0xf9eb('0x22')](function(){_0x19ef71[_0xf9eb('0x1a')](0xcc)[_0xf9eb('0x1b')]();})[_0xf9eb('0x43')](handleError(_0x19ef71,null));};