Built motion from commit d32f51f5.|2.6.31
[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 _0x00bb=['json','undefined','limit','offset','apply','reject','update','destroy','end','stack','name','send','index','map','rawAttributes','fieldName','type','key','model','differenceBy','query','keys','filters','intersection','fields','attributes','hasOwnProperty','nolimit','order','sort','where','pick','filter','merge','VIRTUAL','ScreenRecording','count','then','includeAll','include','rows','catch','show','params','length','options','find','body','createdAt','closedAt','value','describe','download','uniqueid','join','root','format','%s.cypher','existsSync','decryptFile','secrets','recording','server/files/screen_recordings','Sequelize','ScreenRecording\x20not\x20found','filename','unlink','message','Not\x20found','info','cancellazione\x20fisica\x20documento\x20%s','isNil','\x22\x20trovato\x20eseguo\x20la\x20cancellazione','unlinkSync','.cypher','File:\x20\x22','eml-format','rimraf','zip-dir','request-promise','bluebird','mustache','path','sox','lodash','squel','crypto','jsforce','desk.js','to-csv','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','api','../../mysqldb','sendStatus','status'];(function(_0x322539,_0x208d04){var _0x4dcce7=function(_0x439524){while(--_0x439524){_0x322539['push'](_0x322539['shift']());}};_0x4dcce7(++_0x208d04);}(_0x00bb,0x1d8));var _0xb00b=function(_0x47e7cb,_0x4c1b8d){_0x47e7cb=_0x47e7cb-0x0;var _0x2a8874=_0x00bb[_0x47e7cb];return _0x2a8874;};'use strict';var emlformat=require(_0xb00b('0x0'));var rimraf=require(_0xb00b('0x1'));var zipdir=require(_0xb00b('0x2'));var jsonpatch=require('fast-json-patch');var rp=require(_0xb00b('0x3'));var moment=require('moment');var BPromise=require(_0xb00b('0x4'));var Mustache=require(_0xb00b('0x5'));var util=require('util');var path=require(_0xb00b('0x6'));var sox=require(_0xb00b('0x7'));var csv=require('to-csv');var ejs=require('ejs');var fs=require('fs');var fs_extra=require('fs-extra');var _=require(_0xb00b('0x8'));var squel=require(_0xb00b('0x9'));var crypto=require(_0xb00b('0xa'));var jsforce=require(_0xb00b('0xb'));var deskjs=require(_0xb00b('0xc'));var toCsv=require(_0xb00b('0xd'));var querystring=require('querystring');var Papa=require('papaparse');var Redis=require(_0xb00b('0xe'));var authService=require(_0xb00b('0xf'));var qs=require(_0xb00b('0x10'));var as=require(_0xb00b('0x11'));var hardwareService=require(_0xb00b('0x12'));var logger=require('../../config/logger')(_0xb00b('0x13'));var utils=require('../../config/utils');var config=require('../../config/environment');var licenseUtil=require('../../config/license/util');var db=require(_0xb00b('0x14'))['db'];function respondWithStatusCode(_0x2d8ddf,_0x1be8aa){_0x1be8aa=_0x1be8aa||0xcc;return function(_0x466b9b){if(_0x466b9b){return _0x2d8ddf[_0xb00b('0x15')](_0x1be8aa);}return _0x2d8ddf[_0xb00b('0x16')](_0x1be8aa)['end']();};}function respondWithResult(_0x218de2,_0xb0d42e){_0xb0d42e=_0xb0d42e||0xc8;return function(_0x482fe6){if(_0x482fe6){return _0x218de2[_0xb00b('0x16')](_0xb0d42e)[_0xb00b('0x17')](_0x482fe6);}};}function respondWithFilteredResult(_0x540b79,_0x5da36b){return function(_0x9b471e){if(_0x9b471e){var _0x4dcd45=typeof _0x5da36b['offset']===_0xb00b('0x18')&&typeof _0x5da36b[_0xb00b('0x19')]===_0xb00b('0x18');var _0xbb72fc=_0x9b471e['count'];var _0x2a7231=_0x4dcd45?0x0:_0x5da36b['offset'];var _0x415f91=_0x4dcd45?_0x9b471e['count']:_0x5da36b[_0xb00b('0x1a')]+_0x5da36b['limit'];var _0xb26ebb;if(_0x415f91>=_0xbb72fc){_0x415f91=_0xbb72fc;_0xb26ebb=0xc8;}else{_0xb26ebb=0xce;}_0x540b79[_0xb00b('0x16')](_0xb26ebb);return _0x540b79['set']('Content-Range',_0x2a7231+'-'+_0x415f91+'/'+_0xbb72fc)[_0xb00b('0x17')](_0x9b471e);}return null;};}function patchUpdates(_0x4a334b){return function(_0x1344c4){try{jsonpatch[_0xb00b('0x1b')](_0x1344c4,_0x4a334b,!![]);}catch(_0x2fe48d){return BPromise[_0xb00b('0x1c')](_0x2fe48d);}return _0x1344c4['save']();};}function saveUpdates(_0x362ee0,_0x4df284){return function(_0x25a973){if(_0x25a973){return _0x25a973[_0xb00b('0x1d')](_0x362ee0)['then'](function(_0x231293){return _0x231293;});}return null;};}function removeEntity(_0x2896d1,_0x520444){return function(_0x3ab3cc){if(_0x3ab3cc){return _0x3ab3cc[_0xb00b('0x1e')]()['then'](function(){_0x2896d1[_0xb00b('0x16')](0xcc)[_0xb00b('0x1f')]();});}};}function handleEntityNotFound(_0x3c9500,_0x8caadf){return function(_0x520e55){if(!_0x520e55){_0x3c9500['sendStatus'](0x194);}return _0x520e55;};}function handleError(_0x3785e9,_0x490380){_0x490380=_0x490380||0x1f4;return function(_0x550587){logger['error'](_0x550587[_0xb00b('0x20')]);if(_0x550587[_0xb00b('0x21')]){delete _0x550587[_0xb00b('0x21')];}_0x3785e9[_0xb00b('0x16')](_0x490380)[_0xb00b('0x22')](_0x550587);};}exports[_0xb00b('0x23')]=function(_0x15d3b9,_0x4a8d2b){var _0x22c22d={},_0x503c9c={},_0x450129={'count':0x0,'rows':[]};var _0x348165=_[_0xb00b('0x24')](db['ScreenRecording'][_0xb00b('0x25')],function(_0x280ed3){return{'name':_0x280ed3[_0xb00b('0x26')],'type':_0x280ed3[_0xb00b('0x27')][_0xb00b('0x28')]};});_0x503c9c[_0xb00b('0x29')]=_[_0xb00b('0x2a')](_[_0xb00b('0x24')](_0x348165,_0xb00b('0x21')),['format']);_0x503c9c[_0xb00b('0x2b')]=_[_0xb00b('0x2c')](_0x15d3b9['query']);_0x503c9c[_0xb00b('0x2d')]=_[_0xb00b('0x2e')](_0x503c9c['model'],_0x503c9c[_0xb00b('0x2b')]);_0x22c22d['attributes']=_[_0xb00b('0x2e')](_0x503c9c[_0xb00b('0x29')],qs[_0xb00b('0x2f')](_0x15d3b9[_0xb00b('0x2b')][_0xb00b('0x2f')]));_0x22c22d[_0xb00b('0x30')]=_0x22c22d[_0xb00b('0x30')]['length']?_0x22c22d['attributes']:_0x503c9c['model'];if(!_0x15d3b9[_0xb00b('0x2b')][_0xb00b('0x31')](_0xb00b('0x32'))){_0x22c22d[_0xb00b('0x19')]=qs['limit'](_0x15d3b9[_0xb00b('0x2b')][_0xb00b('0x19')]);_0x22c22d[_0xb00b('0x1a')]=qs[_0xb00b('0x1a')](_0x15d3b9[_0xb00b('0x2b')][_0xb00b('0x1a')]);}_0x22c22d[_0xb00b('0x33')]=qs[_0xb00b('0x34')](_0x15d3b9['query']['sort']);_0x22c22d[_0xb00b('0x35')]=qs['filters'](_[_0xb00b('0x36')](_0x15d3b9[_0xb00b('0x2b')],_0x503c9c[_0xb00b('0x2d')]),_0x348165);if(_0x15d3b9[_0xb00b('0x2b')][_0xb00b('0x37')]){_0x22c22d[_0xb00b('0x35')]=_[_0xb00b('0x38')](_0x22c22d['where'],{'$or':_[_0xb00b('0x24')](_0x348165,function(_0x25578e){if(_0x25578e[_0xb00b('0x27')]!==_0xb00b('0x39')){var _0x2496e2={};_0x2496e2[_0x25578e[_0xb00b('0x21')]]={'$like':'%'+_0x15d3b9['query'][_0xb00b('0x37')]+'%'};return _0x2496e2;}})});}_0x22c22d=_[_0xb00b('0x38')]({},_0x22c22d,_0x15d3b9['options']);var _0x17ff34={'where':_0x22c22d[_0xb00b('0x35')]};return db[_0xb00b('0x3a')][_0xb00b('0x3b')](_0x17ff34)[_0xb00b('0x3c')](function(_0x5636b1){_0x450129[_0xb00b('0x3b')]=_0x5636b1;if(_0x15d3b9[_0xb00b('0x2b')][_0xb00b('0x3d')]){_0x22c22d[_0xb00b('0x3e')]=[{'all':!![]}];}return db['ScreenRecording']['findAll'](_0x22c22d);})[_0xb00b('0x3c')](function(_0xf6ae0c){_0x450129[_0xb00b('0x3f')]=_0xf6ae0c;return _0x450129;})[_0xb00b('0x3c')](respondWithFilteredResult(_0x4a8d2b,_0x22c22d))[_0xb00b('0x40')](handleError(_0x4a8d2b,null));};exports[_0xb00b('0x41')]=function(_0x275664,_0x493841){var _0x36200d={'raw':![],'where':{'id':_0x275664[_0xb00b('0x42')]['id']}},_0x3b72c4={};_0x3b72c4[_0xb00b('0x29')]=_[_0xb00b('0x2c')](db[_0xb00b('0x3a')][_0xb00b('0x25')]);_0x3b72c4[_0xb00b('0x2b')]=_[_0xb00b('0x2c')](_0x275664[_0xb00b('0x2b')]);_0x3b72c4[_0xb00b('0x2d')]=_[_0xb00b('0x2e')](_0x3b72c4['model'],_0x3b72c4[_0xb00b('0x2b')]);_0x36200d[_0xb00b('0x30')]=_[_0xb00b('0x2e')](_0x3b72c4[_0xb00b('0x29')],qs[_0xb00b('0x2f')](_0x275664[_0xb00b('0x2b')][_0xb00b('0x2f')]));_0x36200d[_0xb00b('0x30')]=_0x36200d[_0xb00b('0x30')][_0xb00b('0x43')]?_0x36200d[_0xb00b('0x30')]:_0x3b72c4[_0xb00b('0x29')];if(_0x275664['query']['includeAll']){_0x36200d['include']=[{'all':!![]}];}_0x36200d=_[_0xb00b('0x38')]({},_0x36200d,_0x275664[_0xb00b('0x44')]);return db['ScreenRecording'][_0xb00b('0x45')](_0x36200d)[_0xb00b('0x3c')](handleEntityNotFound(_0x493841,null))[_0xb00b('0x3c')](respondWithResult(_0x493841,null))[_0xb00b('0x40')](handleError(_0x493841,null));};exports['create']=function(_0x58e9cb,_0x172729){return db[_0xb00b('0x3a')]['create'](_0x58e9cb['body'],{})[_0xb00b('0x3c')](respondWithResult(_0x172729,0xc9))[_0xb00b('0x40')](handleError(_0x172729,null));};exports['update']=function(_0x2228e9,_0x47a814){if(_0x2228e9['body']['id']){delete _0x2228e9['body']['id'];}delete _0x2228e9[_0xb00b('0x46')]['duration'];delete _0x2228e9[_0xb00b('0x46')][_0xb00b('0x47')];delete _0x2228e9[_0xb00b('0x46')][_0xb00b('0x48')];delete _0x2228e9[_0xb00b('0x46')][_0xb00b('0x49')];return db['ScreenRecording']['find']({'where':{'id':_0x2228e9[_0xb00b('0x42')]['id']}})[_0xb00b('0x3c')](handleEntityNotFound(_0x47a814,null))['then'](saveUpdates(_0x2228e9[_0xb00b('0x46')],null))[_0xb00b('0x3c')](respondWithResult(_0x47a814,null))['catch'](handleError(_0x47a814,null));};exports[_0xb00b('0x4a')]=function(_0x10e066,_0x3b5d82){return db['ScreenRecording']['describe']()[_0xb00b('0x3c')](respondWithResult(_0x3b5d82,null))[_0xb00b('0x40')](handleError(_0x3b5d82,null));};exports[_0xb00b('0x4b')]=function(_0xde3cc1,_0x489b49,_0x380acb){var _0x3f31e5=require('../../components/encryptor');var _0x4cd9fd=![];var _0x160965={};if(_0xde3cc1['query'][_0xb00b('0x27')]&&_0xde3cc1[_0xb00b('0x2b')][_0xb00b('0x27')]===_0xb00b('0x4c')){_0x160965[_0xb00b('0x4c')]=_0xde3cc1[_0xb00b('0x42')]['id'];}else{_0x160965['id']=_0xde3cc1['params']['id'];}return db[_0xb00b('0x3a')]['find']({'where':_0x160965,'attributes':['id',_0xb00b('0x49')],'raw':!![]})[_0xb00b('0x3c')](handleEntityNotFound(_0x489b49,null))[_0xb00b('0x3c')](function(_0x5ac79e){if(_0x5ac79e){var _0x248335=path[_0xb00b('0x4d')](config[_0xb00b('0x4e')],'server/files/screen_recordings',_0x5ac79e[_0xb00b('0x49')]);var _0x309ae6=util[_0xb00b('0x4f')](_0xb00b('0x50'),_0x248335);if(fs[_0xb00b('0x51')](_0x309ae6)){_0x4cd9fd=!![];return _0x3f31e5[_0xb00b('0x52')](_0x309ae6,_0x248335,config[_0xb00b('0x53')][_0xb00b('0x54')])['then'](function(){return _0x5ac79e;});}return _0x5ac79e;}})[_0xb00b('0x3c')](function(_0x2cbe80){if(_0x2cbe80){var _0x1b4860=path['join'](config[_0xb00b('0x4e')],_0xb00b('0x55'),_0x2cbe80[_0xb00b('0x49')]);if(!fs[_0xb00b('0x51')](_0x1b4860)){throw new db[(_0xb00b('0x56'))]['ValidationError'](_0xb00b('0x57'));}if(_0x2cbe80[_0xb00b('0x58')]){return _0x489b49[_0xb00b('0x4b')](_0x1b4860,_0x2cbe80[_0xb00b('0x58')]+path['extname'](_0x1b4860),function(){if(_0x4cd9fd){fs[_0xb00b('0x59')](_0x1b4860);}});}else{return _0x489b49[_0xb00b('0x4b')](_0x1b4860,function(_0x2c93db){if(_0x4cd9fd){fs[_0xb00b('0x59')](_0x1b4860);}});}}})[_0xb00b('0x40')](function(_0x1e5ed8){if(_0x1e5ed8[_0xb00b('0x5a')]==='ScreenRecording\x20not\x20found'){_0x489b49[_0xb00b('0x16')](0x194)['send'](_0xb00b('0x5b'));}else{return handleError(_0x489b49,null);}});};exports['destroy']=function(_0x3b3272,_0x530d4a){return db[_0xb00b('0x3a')]['find']({'where':{'id':_0x3b3272[_0xb00b('0x42')]['id']}})[_0xb00b('0x3c')](function(_0x3bae02){if(_['isNil'](_0x3bae02)){throw new ReferenceError('Entity\x20not\x20found');}return _0x3bae02;})['then'](function(_0x21a53d){var _0x3126be=path[_0xb00b('0x4d')](config['root'],_0xb00b('0x55'),_0x21a53d[_0xb00b('0x49')]);logger[_0xb00b('0x5c')](_0xb00b('0x5d'),_0x3126be);if(!_[_0xb00b('0x5e')](_0x21a53d['value'])&&fs[_0xb00b('0x51')](_0x3126be)){logger[_0xb00b('0x5c')]('File:\x20\x22'+_0x3126be+_0xb00b('0x5f'));fs[_0xb00b('0x60')](_0x3126be);}_0x3126be=_0x3126be+_0xb00b('0x61');if(!_['isNil'](_0x21a53d['value'])&&fs[_0xb00b('0x51')](_0x3126be)){logger[_0xb00b('0x5c')](_0xb00b('0x62')+_0x3126be+'\x22\x20trovato\x20eseguo\x20la\x20cancellazione');fs['unlinkSync'](_0x3126be);}return _0x21a53d;})['then'](function(_0x5e9677){if(!_0x5e9677)throw new InternalError();return _0x5e9677[_0xb00b('0x1e')]();})['then'](function(){_0x530d4a[_0xb00b('0x16')](0xcc)[_0xb00b('0x1f')]();})['catch'](handleError(_0x530d4a,null));};