bd67b191d4cb1776902ff12656bd9c13dee238b8
[motion2.git] / server / api / voiceRecording / voiceRecording.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 _0x3ccb=['col','token','$and','push','secrets','filename','html-pdf','eml-format','rimraf','zip-dir','fast-json-patch','moment','bluebird','mustache','path','sox','to-csv','ejs','squel','crypto','desk.js','querystring','ioredis','../../components/parsers/qs','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','../../mysqldb','sendStatus','status','count','offset','limit','set','Content-Range','json','apply','reject','save','then','destroy','error','stack','name','send','VoiceRecording','rawAttributes','model','differenceBy','format','query','keys','filters','intersection','attributes','length','hasOwnProperty','nolimit','order','sort','pick','where','map','key','VIRTUAL','field','filter','merge','options','includeAll','include','findAll','rows','catch','show','fields','find','create','body','update','params','describe','download','../../components/encryptor','type','uniqueid','value','%s.cypher','existsSync','decryptFile','recording','Sequelize','ValidationError','extname','unlink','message','VoiceRecording\x20not\x20found','Not\x20found','downloads','sequelize','MD5'];(function(_0x558e45,_0x4f5e4f){var _0x3e9075=function(_0x289725){while(--_0x289725){_0x558e45['push'](_0x558e45['shift']());}};_0x3e9075(++_0x4f5e4f);}(_0x3ccb,0x1a2));var _0xb3cc=function(_0x26307f,_0x562b44){_0x26307f=_0x26307f-0x0;var _0x5ac553=_0x3ccb[_0x26307f];return _0x5ac553;};'use strict';var pdf=require(_0xb3cc('0x0'));var emlformat=require(_0xb3cc('0x1'));var rimraf=require(_0xb3cc('0x2'));var zipdir=require(_0xb3cc('0x3'));var jsonpatch=require(_0xb3cc('0x4'));var rp=require('request-promise');var moment=require(_0xb3cc('0x5'));var BPromise=require(_0xb3cc('0x6'));var Mustache=require(_0xb3cc('0x7'));var util=require('util');var path=require(_0xb3cc('0x8'));var sox=require(_0xb3cc('0x9'));var csv=require(_0xb3cc('0xa'));var ejs=require(_0xb3cc('0xb'));var fs=require('fs');var _=require('lodash');var squel=require(_0xb3cc('0xc'));var crypto=require(_0xb3cc('0xd'));var jsforce=require('jsforce');var deskjs=require(_0xb3cc('0xe'));var toCsv=require(_0xb3cc('0xa'));var querystring=require(_0xb3cc('0xf'));var Papa=require('papaparse');var Redis=require(_0xb3cc('0x10'));var authService=require('../../components/auth/service');var qs=require(_0xb3cc('0x11'));var hardwareService=require(_0xb3cc('0x12'));var logger=require(_0xb3cc('0x13'))(_0xb3cc('0x14'));var utils=require(_0xb3cc('0x15'));var config=require(_0xb3cc('0x16'));var db=require(_0xb3cc('0x17'))['db'];function respondWithStatusCode(_0x6f4cde,_0x35382e){_0x35382e=_0x35382e||0xcc;return function(_0x5425a2){if(_0x5425a2){return _0x6f4cde[_0xb3cc('0x18')](_0x35382e);}return _0x6f4cde['status'](_0x35382e)['end']();};}function respondWithResult(_0x3a3368,_0xc38622){_0xc38622=_0xc38622||0xc8;return function(_0x195bb1){if(_0x195bb1){return _0x3a3368[_0xb3cc('0x19')](_0xc38622)['json'](_0x195bb1);}};}function respondWithFilteredResult(_0x273523,_0xb1f291){return function(_0x57f35b){if(_0x57f35b){var _0x2b93a7=_0x57f35b[_0xb3cc('0x1a')],_0x57d567=_0xb1f291[_0xb3cc('0x1b')],_0x1c215b=_0xb1f291[_0xb3cc('0x1b')]+_0xb1f291[_0xb3cc('0x1c')],_0x225b5e;if(_0x1c215b>=_0x2b93a7){_0x1c215b=_0x2b93a7;_0x225b5e=0xc8;}else{_0x225b5e=0xce;}_0x273523[_0xb3cc('0x19')](_0x225b5e);return _0x273523[_0xb3cc('0x1d')](_0xb3cc('0x1e'),_0x57d567+'-'+_0x1c215b+'/'+_0x2b93a7)[_0xb3cc('0x1f')](_0x57f35b);}return null;};}function patchUpdates(_0x287575){return function(_0xd25a6d){try{jsonpatch[_0xb3cc('0x20')](_0xd25a6d,_0x287575,!![]);}catch(_0x32861f){return BPromise[_0xb3cc('0x21')](_0x32861f);}return _0xd25a6d[_0xb3cc('0x22')]();};}function saveUpdates(_0x35d6c0,_0x18ed56){return function(_0x5a4fac){if(_0x5a4fac){return _0x5a4fac['update'](_0x35d6c0)[_0xb3cc('0x23')](function(_0x48a774){return _0x48a774;});}return null;};}function removeEntity(_0x5905fa,_0x121ef4){return function(_0x41514b){if(_0x41514b){return _0x41514b[_0xb3cc('0x24')]()['then'](function(){_0x5905fa[_0xb3cc('0x19')](0xcc)['end']();});}};}function handleEntityNotFound(_0x3cd134,_0x545f09){return function(_0x5301b9){if(!_0x5301b9){_0x3cd134['sendStatus'](0x194);}return _0x5301b9;};}function handleError(_0x5447a7,_0x589f36){_0x589f36=_0x589f36||0x1f4;return function(_0x290635){logger[_0xb3cc('0x25')](_0x290635[_0xb3cc('0x26')]);if(_0x290635[_0xb3cc('0x27')]){delete _0x290635['name'];}_0x5447a7[_0xb3cc('0x19')](_0x589f36)[_0xb3cc('0x28')](_0x290635);};}exports['index']=function(_0x3a386a,_0x325bbd){var _0x471d45={},_0x58a7b2={},_0x580749={'count':0x0,'rows':[]};var _0x13e4ee=db[_0xb3cc('0x29')][_0xb3cc('0x2a')];_0x58a7b2[_0xb3cc('0x2b')]=_[_0xb3cc('0x2c')](_['keys'](_0x13e4ee),[_0xb3cc('0x2d')]);_0x58a7b2[_0xb3cc('0x2e')]=_[_0xb3cc('0x2f')](_0x3a386a['query']);_0x58a7b2[_0xb3cc('0x30')]=_[_0xb3cc('0x31')](_0x58a7b2[_0xb3cc('0x2b')],_0x58a7b2[_0xb3cc('0x2e')]);_0x471d45['attributes']=_['intersection'](_0x58a7b2[_0xb3cc('0x2b')],qs['fields'](_0x3a386a['query']['fields']));_0x471d45[_0xb3cc('0x32')]=_0x471d45['attributes'][_0xb3cc('0x33')]?_0x471d45[_0xb3cc('0x32')]:_0x58a7b2[_0xb3cc('0x2b')];if(!_0x3a386a['query'][_0xb3cc('0x34')](_0xb3cc('0x35'))){_0x471d45[_0xb3cc('0x1c')]=qs[_0xb3cc('0x1c')](_0x3a386a['query'][_0xb3cc('0x1c')]);_0x471d45[_0xb3cc('0x1b')]=qs[_0xb3cc('0x1b')](_0x3a386a[_0xb3cc('0x2e')][_0xb3cc('0x1b')]);}_0x471d45[_0xb3cc('0x36')]=qs[_0xb3cc('0x37')](_0x3a386a[_0xb3cc('0x2e')][_0xb3cc('0x37')]);_0x471d45['where']=qs[_0xb3cc('0x30')](_[_0xb3cc('0x38')](_0x3a386a['query'],_0x58a7b2[_0xb3cc('0x30')]));if(_0x3a386a[_0xb3cc('0x2e')]['filter']){_0x471d45[_0xb3cc('0x39')]=_['merge'](_0x471d45[_0xb3cc('0x39')],{'$or':_[_0xb3cc('0x3a')](_0x13e4ee,function(_0x276d66){if(_0x276d66['type'][_0xb3cc('0x3b')]!==_0xb3cc('0x3c')){var _0x807682={};_0x807682[_0x276d66[_0xb3cc('0x3d')]]={'$like':'%'+_0x3a386a[_0xb3cc('0x2e')][_0xb3cc('0x3e')]+'%'};return _0x807682;}})});}_0x471d45=_[_0xb3cc('0x3f')]({},_0x471d45,_0x3a386a[_0xb3cc('0x40')]);var _0x116623={'where':_0x471d45[_0xb3cc('0x39')]};return db[_0xb3cc('0x29')][_0xb3cc('0x1a')](_0x116623)[_0xb3cc('0x23')](function(_0x57c780){_0x580749[_0xb3cc('0x1a')]=_0x57c780;if(_0x3a386a['query'][_0xb3cc('0x41')]){_0x471d45[_0xb3cc('0x42')]=[{'all':!![]}];}return db[_0xb3cc('0x29')][_0xb3cc('0x43')](_0x471d45);})['then'](function(_0x4e4cd0){_0x580749[_0xb3cc('0x44')]=_0x4e4cd0;return _0x580749;})[_0xb3cc('0x23')](respondWithFilteredResult(_0x325bbd,_0x471d45))[_0xb3cc('0x45')](handleError(_0x325bbd,null));};exports[_0xb3cc('0x46')]=function(_0x4f2ebe,_0x36ffa7){var _0xe03a82={'raw':![],'where':{'id':_0x4f2ebe['params']['id']}},_0x5924b7={};_0x5924b7['model']=_[_0xb3cc('0x2f')](db[_0xb3cc('0x29')][_0xb3cc('0x2a')]);_0x5924b7[_0xb3cc('0x2e')]=_[_0xb3cc('0x2f')](_0x4f2ebe['query']);_0x5924b7[_0xb3cc('0x30')]=_['intersection'](_0x5924b7[_0xb3cc('0x2b')],_0x5924b7[_0xb3cc('0x2e')]);_0xe03a82[_0xb3cc('0x32')]=_[_0xb3cc('0x31')](_0x5924b7['model'],qs[_0xb3cc('0x47')](_0x4f2ebe[_0xb3cc('0x2e')][_0xb3cc('0x47')]));_0xe03a82[_0xb3cc('0x32')]=_0xe03a82[_0xb3cc('0x32')][_0xb3cc('0x33')]?_0xe03a82['attributes']:_0x5924b7[_0xb3cc('0x2b')];if(_0x4f2ebe[_0xb3cc('0x2e')][_0xb3cc('0x41')]){_0xe03a82[_0xb3cc('0x42')]=[{'all':!![]}];}_0xe03a82=_['merge']({},_0xe03a82,_0x4f2ebe[_0xb3cc('0x40')]);return db[_0xb3cc('0x29')][_0xb3cc('0x48')](_0xe03a82)['then'](handleEntityNotFound(_0x36ffa7,null))[_0xb3cc('0x23')](respondWithResult(_0x36ffa7,null))[_0xb3cc('0x45')](handleError(_0x36ffa7,null));};exports['create']=function(_0x5325f2,_0x54ae58){return db[_0xb3cc('0x29')][_0xb3cc('0x49')](_0x5325f2[_0xb3cc('0x4a')],{})[_0xb3cc('0x23')](respondWithResult(_0x54ae58,0xc9))[_0xb3cc('0x45')](handleError(_0x54ae58,null));};exports[_0xb3cc('0x4b')]=function(_0x56a168,_0x18a3f7){if(_0x56a168[_0xb3cc('0x4a')]['id']){delete _0x56a168[_0xb3cc('0x4a')]['id'];}return db['VoiceRecording'][_0xb3cc('0x48')]({'where':{'id':_0x56a168[_0xb3cc('0x4c')]['id']}})['then'](handleEntityNotFound(_0x18a3f7,null))[_0xb3cc('0x23')](saveUpdates(_0x56a168[_0xb3cc('0x4a')],null))[_0xb3cc('0x23')](respondWithResult(_0x18a3f7,null))[_0xb3cc('0x45')](handleError(_0x18a3f7,null));};exports[_0xb3cc('0x24')]=function(_0x3f22c4,_0x2486a4){return db[_0xb3cc('0x29')][_0xb3cc('0x48')]({'where':{'id':_0x3f22c4['params']['id']}})[_0xb3cc('0x23')](handleEntityNotFound(_0x2486a4,null))[_0xb3cc('0x23')](removeEntity(_0x2486a4,null))[_0xb3cc('0x45')](handleError(_0x2486a4,null));};exports[_0xb3cc('0x4d')]=function(_0x40aab6,_0x26ac1e){return db[_0xb3cc('0x29')][_0xb3cc('0x4d')]()[_0xb3cc('0x23')](respondWithResult(_0x26ac1e,null))[_0xb3cc('0x45')](handleError(_0x26ac1e,null));};exports[_0xb3cc('0x4e')]=function(_0xb58c9b,_0x59404a,_0x3d14be){var _0x53a8b1=require(_0xb3cc('0x4f'));var _0x15c342=![];var _0x1482dd={};if(_0xb58c9b['query'][_0xb3cc('0x50')]&&_0xb58c9b[_0xb3cc('0x2e')][_0xb3cc('0x50')]===_0xb3cc('0x51')){_0x1482dd[_0xb3cc('0x51')]=_0xb58c9b[_0xb3cc('0x4c')]['id'];}else{_0x1482dd['id']=_0xb58c9b[_0xb3cc('0x4c')]['id'];}return db[_0xb3cc('0x29')][_0xb3cc('0x48')]({'where':_0x1482dd,'attributes':['id',_0xb3cc('0x52')],'raw':!![]})[_0xb3cc('0x23')](handleEntityNotFound(_0x59404a,null))['then'](function(_0x24feb4){if(_0x24feb4){var _0x532d8c=_0x24feb4[_0xb3cc('0x52')];var _0x568ef8=util[_0xb3cc('0x2d')](_0xb3cc('0x53'),_0x532d8c);if(fs[_0xb3cc('0x54')](_0x568ef8)){_0x15c342=!![];return _0x53a8b1[_0xb3cc('0x55')](_0x568ef8,_0x532d8c,config['secrets'][_0xb3cc('0x56')])['then'](function(){return _0x24feb4;});}return _0x24feb4;}})['then'](function(_0x486463){if(_0x486463){var _0x22aca6=_0x486463[_0xb3cc('0x52')];if(!fs[_0xb3cc('0x54')](_0x22aca6)){throw new db[(_0xb3cc('0x57'))][(_0xb3cc('0x58'))]('VoiceRecording\x20not\x20found');}if(_0x486463['filename']){return _0x59404a[_0xb3cc('0x4e')](_0x22aca6,_0x486463['filename']+path[_0xb3cc('0x59')](_0x22aca6),function(){if(_0x15c342){fs[_0xb3cc('0x5a')](_0x22aca6);}});}else{return _0x59404a[_0xb3cc('0x4e')](_0x22aca6,function(_0x12c9e2){if(_0x15c342){fs[_0xb3cc('0x5a')](_0x22aca6);}});}}})['catch'](function(_0x5c87ea){if(_0x5c87ea[_0xb3cc('0x5b')]===_0xb3cc('0x5c')){_0x59404a[_0xb3cc('0x19')](0x194)[_0xb3cc('0x28')](_0xb3cc('0x5d'));}else{return handleError(_0x59404a,null);}});};exports[_0xb3cc('0x5e')]=function(_0x616963,_0x37a3f7,_0x203266){var _0x3e3aee=require(_0xb3cc('0x4f'));var _0x50394f=![];var _0x3c5ce0={'$and':[db['sequelize'][_0xb3cc('0x39')](db[_0xb3cc('0x5f')]['fn'](_0xb3cc('0x60'),db[_0xb3cc('0x5f')][_0xb3cc('0x61')](_0xb3cc('0x51'))),_0x616963[_0xb3cc('0x2e')][_0xb3cc('0x62')])]};if(_0x616963[_0xb3cc('0x2e')][_0xb3cc('0x50')]&&_0x616963[_0xb3cc('0x2e')][_0xb3cc('0x50')]==='uniqueid'){_0x3c5ce0[_0xb3cc('0x63')]['push']({'uniqueid':_0x616963['params']['id']});}else{_0x3c5ce0['$and'][_0xb3cc('0x64')]({'id':_0x616963[_0xb3cc('0x4c')]['id']});}return db['VoiceRecording']['find']({'where':_0x3c5ce0,'attributes':['id',_0xb3cc('0x52')],'raw':!![]})[_0xb3cc('0x23')](handleEntityNotFound(_0x37a3f7,null))[_0xb3cc('0x23')](function(_0x11db90){if(_0x11db90){var _0x133c13=util[_0xb3cc('0x2d')](_0xb3cc('0x53'),_0x11db90[_0xb3cc('0x52')]);if(fs[_0xb3cc('0x54')](_0x133c13)){_0x50394f=!![];return _0x3e3aee[_0xb3cc('0x55')](_0x133c13,_0x11db90[_0xb3cc('0x52')],config[_0xb3cc('0x65')][_0xb3cc('0x56')])['then'](function(){return _0x11db90;});}return _0x11db90;}})[_0xb3cc('0x23')](function(_0x3e1b90){if(_0x3e1b90){if(!fs[_0xb3cc('0x54')](_0x3e1b90[_0xb3cc('0x52')])){throw new db['Sequelize']['ValidationError'](_0xb3cc('0x5c'));}if(_0x3e1b90[_0xb3cc('0x66')]){return _0x37a3f7[_0xb3cc('0x4e')](_0x3e1b90[_0xb3cc('0x52')],_0x3e1b90['filename']+path['extname'](_0x3e1b90[_0xb3cc('0x52')]),function(){if(_0x50394f){fs['unlink'](_0x3e1b90['value']);}});}else{return _0x37a3f7[_0xb3cc('0x4e')](_0x3e1b90[_0xb3cc('0x52')],function(_0x555c22){if(_0x50394f){fs[_0xb3cc('0x5a')](_0x3e1b90['value']);}});}}})[_0xb3cc('0x45')](handleError(_0x37a3f7,null));};