Built motion from commit (unavailable).|2.5.5
[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 _0x4b0b=['duration','describe','download','../../components/encryptor','uniqueid','value','join','root','server/files/screen_recordings','format','%s.cypher','existsSync','decryptFile','secrets','recording','ValidationError','ScreenRecording\x20not\x20found','filename','unlink','message','Not\x20found','Entity\x20not\x20found','cancellazione\x20fisica\x20documento\x20%s','info','File:\x20\x22','\x22\x20trovato\x20eseguo\x20la\x20cancellazione','.cypher','html-pdf','eml-format','zip-dir','request-promise','moment','bluebird','mustache','util','path','sox','to-csv','ejs','lodash','squel','crypto','desk.js','querystring','papaparse','../../components/auth/service','../../components/parsers/advancedSearch','../../config/logger','api','../../config/utils','../../config/environment','../../config/license/util','sendStatus','status','json','count','offset','set','Content-Range','apply','save','then','end','stack','name','send','index','map','ScreenRecording','rawAttributes','fieldName','type','key','model','differenceBy','keys','query','filters','intersection','fields','attributes','length','hasOwnProperty','nolimit','limit','order','sort','where','pick','filter','merge','VIRTUAL','options','include','rows','show','params','includeAll','find','catch','create','update','body'];(function(_0xf04b83,_0x399c28){var _0x3d15eb=function(_0x3b554d){while(--_0x3b554d){_0xf04b83['push'](_0xf04b83['shift']());}};_0x3d15eb(++_0x399c28);}(_0x4b0b,0x150));var _0xb4b0=function(_0x489ca0,_0xbb5ffe){_0x489ca0=_0x489ca0-0x0;var _0x522236=_0x4b0b[_0x489ca0];return _0x522236;};'use strict';var pdf=require(_0xb4b0('0x0'));var emlformat=require(_0xb4b0('0x1'));var rimraf=require('rimraf');var zipdir=require(_0xb4b0('0x2'));var jsonpatch=require('fast-json-patch');var rp=require(_0xb4b0('0x3'));var moment=require(_0xb4b0('0x4'));var BPromise=require(_0xb4b0('0x5'));var Mustache=require(_0xb4b0('0x6'));var util=require(_0xb4b0('0x7'));var path=require(_0xb4b0('0x8'));var sox=require(_0xb4b0('0x9'));var csv=require(_0xb4b0('0xa'));var ejs=require(_0xb4b0('0xb'));var fs=require('fs');var _=require(_0xb4b0('0xc'));var squel=require(_0xb4b0('0xd'));var crypto=require(_0xb4b0('0xe'));var jsforce=require('jsforce');var deskjs=require(_0xb4b0('0xf'));var toCsv=require(_0xb4b0('0xa'));var querystring=require(_0xb4b0('0x10'));var Papa=require(_0xb4b0('0x11'));var Redis=require('ioredis');var authService=require(_0xb4b0('0x12'));var qs=require('../../components/parsers/qs');var as=require(_0xb4b0('0x13'));var hardwareService=require('../../config/license/hardware');var logger=require(_0xb4b0('0x14'))(_0xb4b0('0x15'));var utils=require(_0xb4b0('0x16'));var config=require(_0xb4b0('0x17'));var licenseUtil=require(_0xb4b0('0x18'));var db=require('../../mysqldb')['db'];function respondWithStatusCode(_0x4c5e69,_0x19779a){_0x19779a=_0x19779a||0xcc;return function(_0x561bab){if(_0x561bab){return _0x4c5e69[_0xb4b0('0x19')](_0x19779a);}return _0x4c5e69[_0xb4b0('0x1a')](_0x19779a)['end']();};}function respondWithResult(_0x4af0c8,_0x570933){_0x570933=_0x570933||0xc8;return function(_0x36fd71){if(_0x36fd71){return _0x4af0c8[_0xb4b0('0x1a')](_0x570933)[_0xb4b0('0x1b')](_0x36fd71);}};}function respondWithFilteredResult(_0x3e02c6,_0x1641f2){return function(_0x121c2a){if(_0x121c2a){var _0x3d74c9=_0x121c2a[_0xb4b0('0x1c')],_0x2a1191=_0x1641f2['offset'],_0x4a2795=_0x1641f2[_0xb4b0('0x1d')]+_0x1641f2['limit'],_0x4873dd;if(_0x4a2795>=_0x3d74c9){_0x4a2795=_0x3d74c9;_0x4873dd=0xc8;}else{_0x4873dd=0xce;}_0x3e02c6[_0xb4b0('0x1a')](_0x4873dd);return _0x3e02c6[_0xb4b0('0x1e')](_0xb4b0('0x1f'),_0x2a1191+'-'+_0x4a2795+'/'+_0x3d74c9)[_0xb4b0('0x1b')](_0x121c2a);}return null;};}function patchUpdates(_0x5713dd){return function(_0x1c1687){try{jsonpatch[_0xb4b0('0x20')](_0x1c1687,_0x5713dd,!![]);}catch(_0x59dd49){return BPromise['reject'](_0x59dd49);}return _0x1c1687[_0xb4b0('0x21')]();};}function saveUpdates(_0x20e0d8,_0x202c04){return function(_0x1f5c9f){if(_0x1f5c9f){return _0x1f5c9f['update'](_0x20e0d8)[_0xb4b0('0x22')](function(_0x12bc5d){return _0x12bc5d;});}return null;};}function removeEntity(_0x231215,_0x9e1730){return function(_0x504490){if(_0x504490){return _0x504490['destroy']()['then'](function(){_0x231215[_0xb4b0('0x1a')](0xcc)[_0xb4b0('0x23')]();});}};}function handleEntityNotFound(_0x7e8c3c,_0x48c957){return function(_0x2f2d8){if(!_0x2f2d8){_0x7e8c3c[_0xb4b0('0x19')](0x194);}return _0x2f2d8;};}function handleError(_0x59e160,_0x38d87b){_0x38d87b=_0x38d87b||0x1f4;return function(_0x4cfbdf){logger['error'](_0x4cfbdf[_0xb4b0('0x24')]);if(_0x4cfbdf[_0xb4b0('0x25')]){delete _0x4cfbdf[_0xb4b0('0x25')];}_0x59e160['status'](_0x38d87b)[_0xb4b0('0x26')](_0x4cfbdf);};}exports[_0xb4b0('0x27')]=function(_0x12f77a,_0x5ecf9a){var _0x1274f1={},_0x43ac29={},_0x511c14={'count':0x0,'rows':[]};var _0x348550=_[_0xb4b0('0x28')](db[_0xb4b0('0x29')][_0xb4b0('0x2a')],function(_0x13d980){return{'name':_0x13d980[_0xb4b0('0x2b')],'type':_0x13d980[_0xb4b0('0x2c')][_0xb4b0('0x2d')]};});_0x43ac29[_0xb4b0('0x2e')]=_[_0xb4b0('0x2f')](_[_0xb4b0('0x28')](_0x348550,_0xb4b0('0x25')),['format']);_0x43ac29['query']=_[_0xb4b0('0x30')](_0x12f77a[_0xb4b0('0x31')]);_0x43ac29[_0xb4b0('0x32')]=_['intersection'](_0x43ac29[_0xb4b0('0x2e')],_0x43ac29[_0xb4b0('0x31')]);_0x1274f1['attributes']=_[_0xb4b0('0x33')](_0x43ac29[_0xb4b0('0x2e')],qs[_0xb4b0('0x34')](_0x12f77a[_0xb4b0('0x31')][_0xb4b0('0x34')]));_0x1274f1[_0xb4b0('0x35')]=_0x1274f1[_0xb4b0('0x35')][_0xb4b0('0x36')]?_0x1274f1[_0xb4b0('0x35')]:_0x43ac29['model'];if(!_0x12f77a[_0xb4b0('0x31')][_0xb4b0('0x37')](_0xb4b0('0x38'))){_0x1274f1[_0xb4b0('0x39')]=qs['limit'](_0x12f77a[_0xb4b0('0x31')][_0xb4b0('0x39')]);_0x1274f1[_0xb4b0('0x1d')]=qs['offset'](_0x12f77a[_0xb4b0('0x31')]['offset']);}_0x1274f1[_0xb4b0('0x3a')]=qs['sort'](_0x12f77a[_0xb4b0('0x31')][_0xb4b0('0x3b')]);_0x1274f1[_0xb4b0('0x3c')]=qs[_0xb4b0('0x32')](_[_0xb4b0('0x3d')](_0x12f77a['query'],_0x43ac29['filters']),_0x348550);if(_0x12f77a[_0xb4b0('0x31')][_0xb4b0('0x3e')]){_0x1274f1[_0xb4b0('0x3c')]=_[_0xb4b0('0x3f')](_0x1274f1['where'],{'$or':_['map'](_0x348550,function(_0x38decb){if(_0x38decb[_0xb4b0('0x2c')]!==_0xb4b0('0x40')){var _0x3bf02a={};_0x3bf02a[_0x38decb[_0xb4b0('0x25')]]={'$like':'%'+_0x12f77a[_0xb4b0('0x31')][_0xb4b0('0x3e')]+'%'};return _0x3bf02a;}})});}_0x1274f1=_[_0xb4b0('0x3f')]({},_0x1274f1,_0x12f77a[_0xb4b0('0x41')]);var _0x41a8d2={'where':_0x1274f1[_0xb4b0('0x3c')]};return db[_0xb4b0('0x29')]['count'](_0x41a8d2)['then'](function(_0x3b14d2){_0x511c14['count']=_0x3b14d2;if(_0x12f77a[_0xb4b0('0x31')]['includeAll']){_0x1274f1[_0xb4b0('0x42')]=[{'all':!![]}];}return db['ScreenRecording']['findAll'](_0x1274f1);})[_0xb4b0('0x22')](function(_0x162347){_0x511c14[_0xb4b0('0x43')]=_0x162347;return _0x511c14;})[_0xb4b0('0x22')](respondWithFilteredResult(_0x5ecf9a,_0x1274f1))['catch'](handleError(_0x5ecf9a,null));};exports[_0xb4b0('0x44')]=function(_0x228d2c,_0x203458){var _0x39582c={'raw':![],'where':{'id':_0x228d2c[_0xb4b0('0x45')]['id']}},_0x17f931={};_0x17f931[_0xb4b0('0x2e')]=_[_0xb4b0('0x30')](db['ScreenRecording'][_0xb4b0('0x2a')]);_0x17f931[_0xb4b0('0x31')]=_[_0xb4b0('0x30')](_0x228d2c['query']);_0x17f931[_0xb4b0('0x32')]=_[_0xb4b0('0x33')](_0x17f931[_0xb4b0('0x2e')],_0x17f931[_0xb4b0('0x31')]);_0x39582c[_0xb4b0('0x35')]=_['intersection'](_0x17f931[_0xb4b0('0x2e')],qs['fields'](_0x228d2c[_0xb4b0('0x31')][_0xb4b0('0x34')]));_0x39582c['attributes']=_0x39582c[_0xb4b0('0x35')]['length']?_0x39582c[_0xb4b0('0x35')]:_0x17f931[_0xb4b0('0x2e')];if(_0x228d2c['query'][_0xb4b0('0x46')]){_0x39582c['include']=[{'all':!![]}];}_0x39582c=_['merge']({},_0x39582c,_0x228d2c[_0xb4b0('0x41')]);return db[_0xb4b0('0x29')][_0xb4b0('0x47')](_0x39582c)[_0xb4b0('0x22')](handleEntityNotFound(_0x203458,null))[_0xb4b0('0x22')](respondWithResult(_0x203458,null))[_0xb4b0('0x48')](handleError(_0x203458,null));};exports[_0xb4b0('0x49')]=function(_0xab807e,_0x3e2238){return db[_0xb4b0('0x29')][_0xb4b0('0x49')](_0xab807e['body'],{})['then'](respondWithResult(_0x3e2238,0xc9))[_0xb4b0('0x48')](handleError(_0x3e2238,null));};exports[_0xb4b0('0x4a')]=function(_0x143a12,_0x1a814d){if(_0x143a12[_0xb4b0('0x4b')]['id']){delete _0x143a12[_0xb4b0('0x4b')]['id'];}delete _0x143a12[_0xb4b0('0x4b')][_0xb4b0('0x4c')];delete _0x143a12[_0xb4b0('0x4b')]['createdAt'];delete _0x143a12[_0xb4b0('0x4b')]['closedAt'];delete _0x143a12['body']['value'];return db[_0xb4b0('0x29')][_0xb4b0('0x47')]({'where':{'id':_0x143a12[_0xb4b0('0x45')]['id']}})['then'](handleEntityNotFound(_0x1a814d,null))[_0xb4b0('0x22')](saveUpdates(_0x143a12[_0xb4b0('0x4b')],null))[_0xb4b0('0x22')](respondWithResult(_0x1a814d,null))[_0xb4b0('0x48')](handleError(_0x1a814d,null));};exports[_0xb4b0('0x4d')]=function(_0xc9ab0,_0x55c822){return db['ScreenRecording'][_0xb4b0('0x4d')]()[_0xb4b0('0x22')](respondWithResult(_0x55c822,null))['catch'](handleError(_0x55c822,null));};exports[_0xb4b0('0x4e')]=function(_0x1deda2,_0x550fdf,_0x151da0){var _0x4eb212=require(_0xb4b0('0x4f'));var _0x33b25d=![];var _0x2cf067={};if(_0x1deda2[_0xb4b0('0x31')][_0xb4b0('0x2c')]&&_0x1deda2[_0xb4b0('0x31')][_0xb4b0('0x2c')]===_0xb4b0('0x50')){_0x2cf067[_0xb4b0('0x50')]=_0x1deda2[_0xb4b0('0x45')]['id'];}else{_0x2cf067['id']=_0x1deda2['params']['id'];}return db[_0xb4b0('0x29')][_0xb4b0('0x47')]({'where':_0x2cf067,'attributes':['id',_0xb4b0('0x51')],'raw':!![]})[_0xb4b0('0x22')](handleEntityNotFound(_0x550fdf,null))['then'](function(_0x744459){if(_0x744459){var _0x16b68d=path[_0xb4b0('0x52')](config[_0xb4b0('0x53')],_0xb4b0('0x54'),_0x744459[_0xb4b0('0x51')]);var _0x4677f9=util[_0xb4b0('0x55')](_0xb4b0('0x56'),_0x16b68d);if(fs[_0xb4b0('0x57')](_0x4677f9)){_0x33b25d=!![];return _0x4eb212[_0xb4b0('0x58')](_0x4677f9,_0x16b68d,config[_0xb4b0('0x59')][_0xb4b0('0x5a')])[_0xb4b0('0x22')](function(){return _0x744459;});}return _0x744459;}})['then'](function(_0x267a45){if(_0x267a45){var _0x2a5615=path[_0xb4b0('0x52')](config[_0xb4b0('0x53')],_0xb4b0('0x54'),_0x267a45[_0xb4b0('0x51')]);if(!fs[_0xb4b0('0x57')](_0x2a5615)){throw new db['Sequelize'][(_0xb4b0('0x5b'))](_0xb4b0('0x5c'));}if(_0x267a45[_0xb4b0('0x5d')]){return _0x550fdf['download'](_0x2a5615,_0x267a45[_0xb4b0('0x5d')]+path['extname'](_0x2a5615),function(){if(_0x33b25d){fs[_0xb4b0('0x5e')](_0x2a5615);}});}else{return _0x550fdf[_0xb4b0('0x4e')](_0x2a5615,function(_0x4f3421){if(_0x33b25d){fs['unlink'](_0x2a5615);}});}}})[_0xb4b0('0x48')](function(_0xa6fbe3){if(_0xa6fbe3[_0xb4b0('0x5f')]===_0xb4b0('0x5c')){_0x550fdf[_0xb4b0('0x1a')](0x194)[_0xb4b0('0x26')](_0xb4b0('0x60'));}else{return handleError(_0x550fdf,null);}});};exports['destroy']=function(_0x4e69ed,_0x51a5c8){return db[_0xb4b0('0x29')][_0xb4b0('0x47')]({'where':{'id':_0x4e69ed['params']['id']}})[_0xb4b0('0x22')](function(_0x461c6a){if(!_0x461c6a)throw new ReferenceError(_0xb4b0('0x61'));return _0x461c6a;})[_0xb4b0('0x22')](function(_0x4955c8){var _0x1dda47=path[_0xb4b0('0x52')](config['root'],'server/files/screen_recordings',_0x4955c8[_0xb4b0('0x51')]);logger['info'](_0xb4b0('0x62'),_0x1dda47);if(!_['isNil'](_0x4955c8[_0xb4b0('0x51')])&&fs[_0xb4b0('0x57')](_0x1dda47)){logger[_0xb4b0('0x63')](_0xb4b0('0x64')+_0x1dda47+_0xb4b0('0x65'));fs['unlinkSync'](_0x1dda47);}_0x1dda47=_0x1dda47+_0xb4b0('0x66');if(!_['isNil'](_0x4955c8[_0xb4b0('0x51')])&&fs[_0xb4b0('0x57')](_0x1dda47)){logger[_0xb4b0('0x63')](_0xb4b0('0x64')+_0x1dda47+'\x22\x20trovato\x20eseguo\x20la\x20cancellazione');fs['unlinkSync'](_0x1dda47);}return _0x4955c8;})[_0xb4b0('0x22')](function(_0x330322){if(!_0x330322)throw new InternalError();return _0x330322['destroy']();})[_0xb4b0('0x22')](function(){_0x51a5c8[_0xb4b0('0x1a')](0xcc)['end']();})[_0xb4b0('0x48')](handleError(_0x51a5c8,null));};