4df937fc460715cc3804410c76761d1ff4ef7597
[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 _0x16b3=['body','duration','createdAt','closedAt','params','describe','download','../../components/encryptor','uniqueid','value','root','existsSync','decryptFile','secrets','recording','join','server/files/screen_recordings','Sequelize','ValidationError','ScreenRecording\x20not\x20found','filename','extname','unlink','message','send','Not\x20found','destroy','Entity\x20not\x20found','info','isNil','File:\x20\x22','\x22\x20trovato\x20eseguo\x20la\x20cancellazione','unlinkSync','.cypher','html-pdf','rimraf','zip-dir','request-promise','moment','bluebird','mustache','util','to-csv','lodash','jsforce','desk.js','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','../../config/utils','../../config/license/util','../../mysqldb','sendStatus','status','end','json','offset','limit','set','Content-Range','apply','reject','update','then','error','stack','name','index','map','ScreenRecording','fieldName','type','key','model','differenceBy','format','query','keys','intersection','attributes','fields','nolimit','order','sort','filters','filter','merge','where','VIRTUAL','options','count','includeAll','include','rows','catch','show','filtears','length','find','create'];(function(_0x3fb030,_0x12aebe){var _0xd6899b=function(_0x327646){while(--_0x327646){_0x3fb030['push'](_0x3fb030['shift']());}};_0xd6899b(++_0x12aebe);}(_0x16b3,0x15a));var _0x316b=function(_0x1d3f95,_0x4bde08){_0x1d3f95=_0x1d3f95-0x0;var _0x17c0ae=_0x16b3[_0x1d3f95];return _0x17c0ae;};'use strict';var pdf=require(_0x316b('0x0'));var emlformat=require('eml-format');var rimraf=require(_0x316b('0x1'));var zipdir=require(_0x316b('0x2'));var jsonpatch=require('fast-json-patch');var rp=require(_0x316b('0x3'));var moment=require(_0x316b('0x4'));var BPromise=require(_0x316b('0x5'));var Mustache=require(_0x316b('0x6'));var util=require(_0x316b('0x7'));var path=require('path');var sox=require('sox');var csv=require(_0x316b('0x8'));var ejs=require('ejs');var fs=require('fs');var _=require(_0x316b('0x9'));var squel=require('squel');var crypto=require('crypto');var jsforce=require(_0x316b('0xa'));var deskjs=require(_0x316b('0xb'));var toCsv=require('to-csv');var querystring=require('querystring');var Papa=require(_0x316b('0xc'));var Redis=require(_0x316b('0xd'));var authService=require(_0x316b('0xe'));var qs=require(_0x316b('0xf'));var as=require(_0x316b('0x10'));var hardwareService=require(_0x316b('0x11'));var logger=require(_0x316b('0x12'))('api');var utils=require(_0x316b('0x13'));var config=require('../../config/environment');var licenseUtil=require(_0x316b('0x14'));var db=require(_0x316b('0x15'))['db'];function respondWithStatusCode(_0x2f69a0,_0x1195c5){_0x1195c5=_0x1195c5||0xcc;return function(_0x5cf3e7){if(_0x5cf3e7){return _0x2f69a0[_0x316b('0x16')](_0x1195c5);}return _0x2f69a0[_0x316b('0x17')](_0x1195c5)[_0x316b('0x18')]();};}function respondWithResult(_0x387c36,_0x360da3){_0x360da3=_0x360da3||0xc8;return function(_0x2995fd){if(_0x2995fd){return _0x387c36['status'](_0x360da3)[_0x316b('0x19')](_0x2995fd);}};}function respondWithFilteredResult(_0xfe6509,_0x175d34){return function(_0x3d0404){if(_0x3d0404){var _0x30a9dc=_0x3d0404['count'],_0x176b2d=_0x175d34[_0x316b('0x1a')],_0x5760f4=_0x175d34['offset']+_0x175d34[_0x316b('0x1b')],_0x93f7e1;if(_0x5760f4>=_0x30a9dc){_0x5760f4=_0x30a9dc;_0x93f7e1=0xc8;}else{_0x93f7e1=0xce;}_0xfe6509[_0x316b('0x17')](_0x93f7e1);return _0xfe6509[_0x316b('0x1c')](_0x316b('0x1d'),_0x176b2d+'-'+_0x5760f4+'/'+_0x30a9dc)['json'](_0x3d0404);}return null;};}function patchUpdates(_0x337055){return function(_0x4a0085){try{jsonpatch[_0x316b('0x1e')](_0x4a0085,_0x337055,!![]);}catch(_0x2389a5){return BPromise[_0x316b('0x1f')](_0x2389a5);}return _0x4a0085['save']();};}function saveUpdates(_0x2dd63,_0x373e07){return function(_0x21bab){if(_0x21bab){return _0x21bab[_0x316b('0x20')](_0x2dd63)['then'](function(_0x364771){return _0x364771;});}return null;};}function removeEntity(_0x3a802f,_0x49c67e){return function(_0xeee587){if(_0xeee587){return _0xeee587['destroy']()[_0x316b('0x21')](function(){_0x3a802f[_0x316b('0x17')](0xcc)[_0x316b('0x18')]();});}};}function handleEntityNotFound(_0x23c99e,_0x515a8e){return function(_0x5bffd5){if(!_0x5bffd5){_0x23c99e[_0x316b('0x16')](0x194);}return _0x5bffd5;};}function handleError(_0x5e6e59,_0x3c6ae1){_0x3c6ae1=_0x3c6ae1||0x1f4;return function(_0x410670){logger[_0x316b('0x22')](_0x410670[_0x316b('0x23')]);if(_0x410670['name']){delete _0x410670[_0x316b('0x24')];}_0x5e6e59[_0x316b('0x17')](_0x3c6ae1)['send'](_0x410670);};}exports[_0x316b('0x25')]=function(_0x424478,_0x961928){var _0x2e5d79={},_0x5a1983={},_0x211b74={'count':0x0,'rows':[]};var _0x2095a2=_[_0x316b('0x26')](db[_0x316b('0x27')]['rawAttributes'],function(_0x288070){return{'name':_0x288070[_0x316b('0x28')],'type':_0x288070[_0x316b('0x29')][_0x316b('0x2a')]};});_0x5a1983[_0x316b('0x2b')]=_[_0x316b('0x2c')](_[_0x316b('0x26')](_0x2095a2,_0x316b('0x24')),[_0x316b('0x2d')]);_0x5a1983[_0x316b('0x2e')]=_[_0x316b('0x2f')](_0x424478['query']);_0x5a1983['filters']=_[_0x316b('0x30')](_0x5a1983[_0x316b('0x2b')],_0x5a1983[_0x316b('0x2e')]);_0x2e5d79[_0x316b('0x31')]=_[_0x316b('0x30')](_0x5a1983[_0x316b('0x2b')],qs[_0x316b('0x32')](_0x424478[_0x316b('0x2e')][_0x316b('0x32')]));_0x2e5d79[_0x316b('0x31')]=_0x2e5d79[_0x316b('0x31')]['length']?_0x2e5d79[_0x316b('0x31')]:_0x5a1983['model'];if(!_0x424478[_0x316b('0x2e')]['hasOwnProperty'](_0x316b('0x33'))){_0x2e5d79['limit']=qs[_0x316b('0x1b')](_0x424478['query']['limit']);_0x2e5d79[_0x316b('0x1a')]=qs['offset'](_0x424478[_0x316b('0x2e')]['offset']);}_0x2e5d79[_0x316b('0x34')]=qs['sort'](_0x424478[_0x316b('0x2e')][_0x316b('0x35')]);_0x2e5d79['where']=qs[_0x316b('0x36')](_['pick'](_0x424478[_0x316b('0x2e')],_0x5a1983['filters']),_0x2095a2);if(_0x424478[_0x316b('0x2e')][_0x316b('0x37')]){_0x2e5d79['where']=_[_0x316b('0x38')](_0x2e5d79[_0x316b('0x39')],{'$or':_[_0x316b('0x26')](_0x2095a2,function(_0x3c4057){if(_0x3c4057['type']!==_0x316b('0x3a')){var _0x276254={};_0x276254[_0x3c4057['name']]={'$like':'%'+_0x424478[_0x316b('0x2e')][_0x316b('0x37')]+'%'};return _0x276254;}})});}_0x2e5d79=_[_0x316b('0x38')]({},_0x2e5d79,_0x424478[_0x316b('0x3b')]);var _0xb12b34={'where':_0x2e5d79[_0x316b('0x39')]};return db[_0x316b('0x27')][_0x316b('0x3c')](_0xb12b34)[_0x316b('0x21')](function(_0x54d9c4){_0x211b74[_0x316b('0x3c')]=_0x54d9c4;if(_0x424478[_0x316b('0x2e')][_0x316b('0x3d')]){_0x2e5d79[_0x316b('0x3e')]=[{'all':!![]}];}return db['ScreenRecording']['findAll'](_0x2e5d79);})[_0x316b('0x21')](function(_0x1a0f0a){_0x211b74[_0x316b('0x3f')]=_0x1a0f0a;return _0x211b74;})['then'](respondWithFilteredResult(_0x961928,_0x2e5d79))[_0x316b('0x40')](handleError(_0x961928,null));};exports[_0x316b('0x41')]=function(_0x14a030,_0x16d318){var _0x7ff0c={'raw':![],'where':{'id':_0x14a030['params']['id']}},_0x455cbc={};_0x455cbc[_0x316b('0x2b')]=_[_0x316b('0x2f')](db['ScreenRecording']['rawAttributes']);_0x455cbc[_0x316b('0x2e')]=_[_0x316b('0x2f')](_0x14a030[_0x316b('0x2e')]);_0x455cbc[_0x316b('0x42')]=_[_0x316b('0x30')](_0x455cbc[_0x316b('0x2b')],_0x455cbc[_0x316b('0x2e')]);_0x7ff0c[_0x316b('0x31')]=_[_0x316b('0x30')](_0x455cbc[_0x316b('0x2b')],qs[_0x316b('0x32')](_0x14a030[_0x316b('0x2e')]['fields']));_0x7ff0c['attributes']=_0x7ff0c[_0x316b('0x31')][_0x316b('0x43')]?_0x7ff0c['attributes']:_0x455cbc['model'];if(_0x14a030['query'][_0x316b('0x3d')]){_0x7ff0c['include']=[{'all':!![]}];}_0x7ff0c=_[_0x316b('0x38')]({},_0x7ff0c,_0x14a030[_0x316b('0x3b')]);return db[_0x316b('0x27')][_0x316b('0x44')](_0x7ff0c)['then'](handleEntityNotFound(_0x16d318,null))[_0x316b('0x21')](respondWithResult(_0x16d318,null))[_0x316b('0x40')](handleError(_0x16d318,null));};exports[_0x316b('0x45')]=function(_0x4911b2,_0x5b2dfd){return db[_0x316b('0x27')][_0x316b('0x45')](_0x4911b2['body'],{})[_0x316b('0x21')](respondWithResult(_0x5b2dfd,0xc9))['catch'](handleError(_0x5b2dfd,null));};exports[_0x316b('0x20')]=function(_0x2b3cd4,_0x5d6757){if(_0x2b3cd4['body']['id']){delete _0x2b3cd4[_0x316b('0x46')]['id'];}delete _0x2b3cd4[_0x316b('0x46')][_0x316b('0x47')];delete _0x2b3cd4['body'][_0x316b('0x48')];delete _0x2b3cd4['body'][_0x316b('0x49')];delete _0x2b3cd4[_0x316b('0x46')]['value'];return db[_0x316b('0x27')]['find']({'where':{'id':_0x2b3cd4[_0x316b('0x4a')]['id']}})[_0x316b('0x21')](handleEntityNotFound(_0x5d6757,null))[_0x316b('0x21')](saveUpdates(_0x2b3cd4['body'],null))['then'](respondWithResult(_0x5d6757,null))[_0x316b('0x40')](handleError(_0x5d6757,null));};exports[_0x316b('0x4b')]=function(_0x1d9d4b,_0x573b93){return db[_0x316b('0x27')][_0x316b('0x4b')]()[_0x316b('0x21')](respondWithResult(_0x573b93,null))[_0x316b('0x40')](handleError(_0x573b93,null));};exports[_0x316b('0x4c')]=function(_0xf4b139,_0x2df707,_0xc6a786){var _0x4f5a2f=require(_0x316b('0x4d'));var _0x50e811=![];var _0xbff6e2={};if(_0xf4b139[_0x316b('0x2e')][_0x316b('0x29')]&&_0xf4b139['query'][_0x316b('0x29')]==='uniqueid'){_0xbff6e2[_0x316b('0x4e')]=_0xf4b139[_0x316b('0x4a')]['id'];}else{_0xbff6e2['id']=_0xf4b139[_0x316b('0x4a')]['id'];}return db[_0x316b('0x27')][_0x316b('0x44')]({'where':_0xbff6e2,'attributes':['id',_0x316b('0x4f')],'raw':!![]})[_0x316b('0x21')](handleEntityNotFound(_0x2df707,null))[_0x316b('0x21')](function(_0x1fa184){if(_0x1fa184){var _0x589cc8=path['join'](config[_0x316b('0x50')],'server/files/screen_recordings',_0x1fa184[_0x316b('0x4f')]);var _0x2b6ed8=util[_0x316b('0x2d')]('%s.cypher',_0x589cc8);if(fs[_0x316b('0x51')](_0x2b6ed8)){_0x50e811=!![];return _0x4f5a2f[_0x316b('0x52')](_0x2b6ed8,_0x589cc8,config[_0x316b('0x53')][_0x316b('0x54')])[_0x316b('0x21')](function(){return _0x1fa184;});}return _0x1fa184;}})[_0x316b('0x21')](function(_0x492e72){if(_0x492e72){var _0x1f8099=path[_0x316b('0x55')](config['root'],_0x316b('0x56'),_0x492e72[_0x316b('0x4f')]);if(!fs[_0x316b('0x51')](_0x1f8099)){throw new db[(_0x316b('0x57'))][(_0x316b('0x58'))](_0x316b('0x59'));}if(_0x492e72[_0x316b('0x5a')]){return _0x2df707[_0x316b('0x4c')](_0x1f8099,_0x492e72['filename']+path[_0x316b('0x5b')](_0x1f8099),function(){if(_0x50e811){fs[_0x316b('0x5c')](_0x1f8099);}});}else{return _0x2df707['download'](_0x1f8099,function(_0x4ce679){if(_0x50e811){fs[_0x316b('0x5c')](_0x1f8099);}});}}})['catch'](function(_0x4d36a5){if(_0x4d36a5[_0x316b('0x5d')]===_0x316b('0x59')){_0x2df707['status'](0x194)[_0x316b('0x5e')](_0x316b('0x5f'));}else{return handleError(_0x2df707,null);}});};exports[_0x316b('0x60')]=function(_0x39066d,_0xf0cd91){return db[_0x316b('0x27')]['find']({'where':{'id':_0x39066d[_0x316b('0x4a')]['id']}})[_0x316b('0x21')](function(_0x382d14){if(!_0x382d14)throw new ReferenceError(_0x316b('0x61'));return _0x382d14;})[_0x316b('0x21')](function(_0x344581){var _0x5a0b65=path[_0x316b('0x55')](config[_0x316b('0x50')],_0x316b('0x56'),_0x344581[_0x316b('0x4f')]);logger[_0x316b('0x62')]('cancellazione\x20fisica\x20documento\x20%s',_0x5a0b65);if(!_[_0x316b('0x63')](_0x344581[_0x316b('0x4f')])&&fs[_0x316b('0x51')](_0x5a0b65)){logger[_0x316b('0x62')](_0x316b('0x64')+_0x5a0b65+_0x316b('0x65'));fs[_0x316b('0x66')](_0x5a0b65);}_0x5a0b65=_0x5a0b65+_0x316b('0x67');if(!_[_0x316b('0x63')](_0x344581['value'])&&fs['existsSync'](_0x5a0b65)){logger[_0x316b('0x62')](_0x316b('0x64')+_0x5a0b65+_0x316b('0x65'));fs['unlinkSync'](_0x5a0b65);}return _0x344581;})[_0x316b('0x21')](function(_0x1cd610){if(!_0x1cd610)throw new InternalError();return _0x1cd610[_0x316b('0x60')]();})[_0x316b('0x21')](function(){_0xf0cd91[_0x316b('0x17')](0xcc)[_0x316b('0x18')]();})['catch'](handleError(_0xf0cd91,null));};