35ab1d3c35ea18e27626d377543d7a7a2439fbc7
[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 _0x11f2=['Transcript\x20not\x20available','html-pdf','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','moment','bluebird','util','path','to-csv','ejs','crypto','jsforce','desk.js','querystring','papaparse','aws-sdk','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','status','end','json','count','offset','set','Content-Range','apply','reject','save','update','then','sendStatus','stack','name','send','index','map','VoiceRecording','rawAttributes','fieldName','type','model','format','query','keys','filters','intersection','attributes','fields','hasOwnProperty','nolimit','limit','sort','where','pick','filter','VIRTUAL','merge','options','includeAll','catch','show','params','length','find','create','body','describe','download','../../components/encryptor','uniqueid','value','secrets','existsSync','Sequelize','ValidationError','VoiceRecording\x20not\x20found','filename','extname','unlink','Not\x20found','sequelize','MD5','col','$and','push','%s.cypher','decryptFile','recording','destroy','Entity\x20not\x20found','info','cancellazione\x20fisica\x20documento\x20%s','isNil','\x22\x20trovato\x20eseguo\x20la\x20cancellazione','unlinkSync','.cypher','File:\x20\x22','createBucket','upload','TranscribeService','startTranscriptionJob','basename','readFileSync','[RUNTRANSCRIPT][%d]\x20Voice\x20recording\x20uploaded\x20in\x20bucket\x20%s\x20(%s)','Location','bucket','Bucket','location','[RUNTRANSCRIPT][%d]\x20Sending\x20transcribe\x20request','TranscriptionJob','TranscriptionJobName','transcribeName','transcribeStatus','TranscriptionJobStatus','runTranscribe','findOne','Setting','transcribe','language','Transcribe\x20not\x20configured','runSentiment','sentiment','Sentiment\x20Analysis\x20not\x20configured','CloudProvider','transcribeAccountId','data1','data2','Cloud\x20Provider\x20not\x20configured','transcribeRegion','Buckets','[RUNTRANSCRIPT][%d]\x20Bucket\x20%s\x20available','NEW','[RUNTRANSCRIPT][%d]\x20Transcript\x20action\x20already\x20requested','tempSentiment','downloadTranscribe','fileText','root','.txt'];(function(_0x378d90,_0x62ae32){var _0x46debe=function(_0x260ce2){while(--_0x260ce2){_0x378d90['push'](_0x378d90['shift']());}};_0x46debe(++_0x62ae32);}(_0x11f2,0x95));var _0x211f=function(_0x19c773,_0x18b116){_0x19c773=_0x19c773-0x0;var _0x441de7=_0x11f2[_0x19c773];return _0x441de7;};'use strict';var pdf=require(_0x211f('0x0'));var emlformat=require(_0x211f('0x1'));var rimraf=require(_0x211f('0x2'));var zipdir=require(_0x211f('0x3'));var jsonpatch=require(_0x211f('0x4'));var rp=require(_0x211f('0x5'));var moment=require(_0x211f('0x6'));var BPromise=require(_0x211f('0x7'));var Mustache=require('mustache');var util=require(_0x211f('0x8'));var path=require(_0x211f('0x9'));var sox=require('sox');var csv=require(_0x211f('0xa'));var ejs=require(_0x211f('0xb'));var fs=require('fs');var _=require('lodash');var squel=require('squel');var crypto=require(_0x211f('0xc'));var jsforce=require(_0x211f('0xd'));var deskjs=require(_0x211f('0xe'));var toCsv=require(_0x211f('0xa'));var querystring=require(_0x211f('0xf'));var Papa=require(_0x211f('0x10'));var AWS=require(_0x211f('0x11'));var uuidv4=require('uuid/v4');var Redis=require(_0x211f('0x12'));var authService=require(_0x211f('0x13'));var qs=require(_0x211f('0x14'));var as=require(_0x211f('0x15'));var hardwareService=require(_0x211f('0x16'));var logger=require(_0x211f('0x17'))(_0x211f('0x18'));var utils=require(_0x211f('0x19'));var config=require(_0x211f('0x1a'));var db=require('../../mysqldb')['db'];function respondWithStatusCode(_0x8954da,_0x48df1c){_0x48df1c=_0x48df1c||0xcc;return function(_0x5dc175){if(_0x5dc175){return _0x8954da['sendStatus'](_0x48df1c);}return _0x8954da[_0x211f('0x1b')](_0x48df1c)[_0x211f('0x1c')]();};}function respondWithResult(_0x533d44,_0x465432){_0x465432=_0x465432||0xc8;return function(_0x4c2b9c){if(_0x4c2b9c){return _0x533d44['status'](_0x465432)[_0x211f('0x1d')](_0x4c2b9c);}};}function respondWithFilteredResult(_0x67eb4d,_0x1a04c5){return function(_0x1fa017){if(_0x1fa017){var _0x23fb95=_0x1fa017[_0x211f('0x1e')],_0xce108d=_0x1a04c5[_0x211f('0x1f')],_0x120be5=_0x1a04c5[_0x211f('0x1f')]+_0x1a04c5['limit'],_0x563ff2;if(_0x120be5>=_0x23fb95){_0x120be5=_0x23fb95;_0x563ff2=0xc8;}else{_0x563ff2=0xce;}_0x67eb4d['status'](_0x563ff2);return _0x67eb4d[_0x211f('0x20')](_0x211f('0x21'),_0xce108d+'-'+_0x120be5+'/'+_0x23fb95)['json'](_0x1fa017);}return null;};}function patchUpdates(_0x35ad0d){return function(_0x26f0db){try{jsonpatch[_0x211f('0x22')](_0x26f0db,_0x35ad0d,!![]);}catch(_0x4aeeee){return BPromise[_0x211f('0x23')](_0x4aeeee);}return _0x26f0db[_0x211f('0x24')]();};}function saveUpdates(_0x2aa161,_0x1e42f8){return function(_0x50fe28){if(_0x50fe28){return _0x50fe28[_0x211f('0x25')](_0x2aa161)[_0x211f('0x26')](function(_0x4757ec){return _0x4757ec;});}return null;};}function removeEntity(_0xaac14b,_0x3c80aa){return function(_0x2d12ba){if(_0x2d12ba){return _0x2d12ba['destroy']()['then'](function(){_0xaac14b['status'](0xcc)[_0x211f('0x1c')]();});}};}function handleEntityNotFound(_0x49539c,_0x2af265){return function(_0x5ede26){if(!_0x5ede26){_0x49539c[_0x211f('0x27')](0x194);}return _0x5ede26;};}function handleError(_0x1ae0ff,_0x3a77f4){_0x3a77f4=_0x3a77f4||0x1f4;return function(_0x549b87){logger['error'](_0x549b87[_0x211f('0x28')]);if(_0x549b87[_0x211f('0x29')]){delete _0x549b87[_0x211f('0x29')];}_0x1ae0ff[_0x211f('0x1b')](_0x3a77f4)[_0x211f('0x2a')](_0x549b87);};}exports[_0x211f('0x2b')]=function(_0xaca1f5,_0x33da5d){var _0x446d76={},_0x22ab36={},_0x4d3a96={'count':0x0,'rows':[]};var _0x4585db=_[_0x211f('0x2c')](db[_0x211f('0x2d')][_0x211f('0x2e')],function(_0x2fbcb3){return{'name':_0x2fbcb3[_0x211f('0x2f')],'type':_0x2fbcb3[_0x211f('0x30')]['key']};});_0x22ab36[_0x211f('0x31')]=_['differenceBy'](_['map'](_0x4585db,'name'),[_0x211f('0x32')]);_0x22ab36[_0x211f('0x33')]=_[_0x211f('0x34')](_0xaca1f5[_0x211f('0x33')]);_0x22ab36[_0x211f('0x35')]=_[_0x211f('0x36')](_0x22ab36[_0x211f('0x31')],_0x22ab36[_0x211f('0x33')]);_0x446d76[_0x211f('0x37')]=_[_0x211f('0x36')](_0x22ab36[_0x211f('0x31')],qs[_0x211f('0x38')](_0xaca1f5['query']['fields']));_0x446d76[_0x211f('0x37')]=_0x446d76[_0x211f('0x37')]['length']?_0x446d76[_0x211f('0x37')]:_0x22ab36[_0x211f('0x31')];if(!_0xaca1f5[_0x211f('0x33')][_0x211f('0x39')](_0x211f('0x3a'))){_0x446d76[_0x211f('0x3b')]=qs[_0x211f('0x3b')](_0xaca1f5[_0x211f('0x33')][_0x211f('0x3b')]);_0x446d76['offset']=qs[_0x211f('0x1f')](_0xaca1f5[_0x211f('0x33')][_0x211f('0x1f')]);}_0x446d76['order']=qs['sort'](_0xaca1f5[_0x211f('0x33')][_0x211f('0x3c')]);_0x446d76[_0x211f('0x3d')]=qs['filters'](_[_0x211f('0x3e')](_0xaca1f5[_0x211f('0x33')],_0x22ab36[_0x211f('0x35')]),_0x4585db);if(_0xaca1f5[_0x211f('0x33')][_0x211f('0x3f')]){_0x446d76['where']=_['merge'](_0x446d76[_0x211f('0x3d')],{'$or':_[_0x211f('0x2c')](_0x4585db,function(_0x22284d){if(_0x22284d[_0x211f('0x30')]!==_0x211f('0x40')){var _0x5e510f={};_0x5e510f[_0x22284d[_0x211f('0x29')]]={'$like':'%'+_0xaca1f5[_0x211f('0x33')][_0x211f('0x3f')]+'%'};return _0x5e510f;}})});}_0x446d76=_[_0x211f('0x41')]({},_0x446d76,_0xaca1f5[_0x211f('0x42')]);var _0x4fbd5={'where':_0x446d76[_0x211f('0x3d')]};return db[_0x211f('0x2d')][_0x211f('0x1e')](_0x4fbd5)[_0x211f('0x26')](function(_0x541fbe){_0x4d3a96[_0x211f('0x1e')]=_0x541fbe;if(_0xaca1f5[_0x211f('0x33')][_0x211f('0x43')]){_0x446d76['include']=[{'all':!![]}];}return db[_0x211f('0x2d')]['findAll'](_0x446d76);})[_0x211f('0x26')](function(_0x336582){_0x4d3a96['rows']=_0x336582;return _0x4d3a96;})[_0x211f('0x26')](respondWithFilteredResult(_0x33da5d,_0x446d76))[_0x211f('0x44')](handleError(_0x33da5d,null));};exports[_0x211f('0x45')]=function(_0x1ca5a6,_0x32fff3){var _0x24bc6a={'raw':![],'where':{'id':_0x1ca5a6[_0x211f('0x46')]['id']}},_0x332ed2={};_0x332ed2[_0x211f('0x31')]=_[_0x211f('0x34')](db[_0x211f('0x2d')][_0x211f('0x2e')]);_0x332ed2['query']=_['keys'](_0x1ca5a6[_0x211f('0x33')]);_0x332ed2[_0x211f('0x35')]=_[_0x211f('0x36')](_0x332ed2['model'],_0x332ed2['query']);_0x24bc6a[_0x211f('0x37')]=_[_0x211f('0x36')](_0x332ed2['model'],qs[_0x211f('0x38')](_0x1ca5a6[_0x211f('0x33')][_0x211f('0x38')]));_0x24bc6a[_0x211f('0x37')]=_0x24bc6a[_0x211f('0x37')][_0x211f('0x47')]?_0x24bc6a[_0x211f('0x37')]:_0x332ed2[_0x211f('0x31')];if(_0x1ca5a6[_0x211f('0x33')][_0x211f('0x43')]){_0x24bc6a['include']=[{'all':!![]}];}_0x24bc6a=_[_0x211f('0x41')]({},_0x24bc6a,_0x1ca5a6[_0x211f('0x42')]);return db[_0x211f('0x2d')][_0x211f('0x48')](_0x24bc6a)['then'](handleEntityNotFound(_0x32fff3,null))[_0x211f('0x26')](respondWithResult(_0x32fff3,null))[_0x211f('0x44')](handleError(_0x32fff3,null));};exports[_0x211f('0x49')]=function(_0x6046cc,_0x54cf6b){return db[_0x211f('0x2d')][_0x211f('0x49')](_0x6046cc[_0x211f('0x4a')],{})[_0x211f('0x26')](respondWithResult(_0x54cf6b,0xc9))[_0x211f('0x44')](handleError(_0x54cf6b,null));};exports['update']=function(_0x11a085,_0x3954de){if(_0x11a085[_0x211f('0x4a')]['id']){delete _0x11a085[_0x211f('0x4a')]['id'];}return db[_0x211f('0x2d')][_0x211f('0x48')]({'where':{'id':_0x11a085[_0x211f('0x46')]['id']}})['then'](handleEntityNotFound(_0x3954de,null))[_0x211f('0x26')](saveUpdates(_0x11a085['body'],null))[_0x211f('0x26')](respondWithResult(_0x3954de,null))[_0x211f('0x44')](handleError(_0x3954de,null));};exports[_0x211f('0x4b')]=function(_0x41e081,_0x29e763){return db[_0x211f('0x2d')]['describe']()['then'](respondWithResult(_0x29e763,null))[_0x211f('0x44')](handleError(_0x29e763,null));};exports[_0x211f('0x4c')]=function(_0x3728bd,_0x52de4f,_0x36d49a){var _0x5c2261=require(_0x211f('0x4d'));var _0x3428c2=![];var _0x497c71={};if(_0x3728bd[_0x211f('0x33')][_0x211f('0x30')]&&_0x3728bd[_0x211f('0x33')][_0x211f('0x30')]===_0x211f('0x4e')){_0x497c71[_0x211f('0x4e')]=_0x3728bd[_0x211f('0x46')]['id'];}else{_0x497c71['id']=_0x3728bd[_0x211f('0x46')]['id'];}return db[_0x211f('0x2d')][_0x211f('0x48')]({'where':_0x497c71,'attributes':['id',_0x211f('0x4f')],'raw':!![]})[_0x211f('0x26')](handleEntityNotFound(_0x52de4f,null))['then'](function(_0x4f4ba6){if(_0x4f4ba6){var _0x46576d=_0x4f4ba6[_0x211f('0x4f')];var _0x409ac9=util[_0x211f('0x32')]('%s.cypher',_0x46576d);if(fs['existsSync'](_0x409ac9)){_0x3428c2=!![];return _0x5c2261['decryptFile'](_0x409ac9,_0x46576d,config[_0x211f('0x50')]['recording'])[_0x211f('0x26')](function(){return _0x4f4ba6;});}return _0x4f4ba6;}})['then'](function(_0x117544){if(_0x117544){var _0x4573de=_0x117544[_0x211f('0x4f')];if(!fs[_0x211f('0x51')](_0x4573de)){throw new db[(_0x211f('0x52'))][(_0x211f('0x53'))](_0x211f('0x54'));}if(_0x117544[_0x211f('0x55')]){return _0x52de4f[_0x211f('0x4c')](_0x4573de,_0x117544['filename']+path[_0x211f('0x56')](_0x4573de),function(){if(_0x3428c2){fs[_0x211f('0x57')](_0x4573de);}});}else{return _0x52de4f[_0x211f('0x4c')](_0x4573de,function(_0x21ea8a){if(_0x3428c2){fs[_0x211f('0x57')](_0x4573de);}});}}})[_0x211f('0x44')](function(_0x1271f5){if(_0x1271f5['message']===_0x211f('0x54')){_0x52de4f[_0x211f('0x1b')](0x194)[_0x211f('0x2a')](_0x211f('0x58'));}else{return handleError(_0x52de4f,null);}});};exports['downloads']=function(_0x22296c,_0x376710,_0x1aa2a2){var _0xf736f1=require(_0x211f('0x4d'));var _0x4835f8=![];var _0x13b686={'$and':[db[_0x211f('0x59')]['where'](db[_0x211f('0x59')]['fn'](_0x211f('0x5a'),db[_0x211f('0x59')][_0x211f('0x5b')](_0x211f('0x4e'))),_0x22296c[_0x211f('0x33')]['token'])]};if(_0x22296c[_0x211f('0x33')][_0x211f('0x30')]&&_0x22296c[_0x211f('0x33')]['type']===_0x211f('0x4e')){_0x13b686[_0x211f('0x5c')][_0x211f('0x5d')]({'uniqueid':_0x22296c[_0x211f('0x46')]['id']});}else{_0x13b686[_0x211f('0x5c')][_0x211f('0x5d')]({'id':_0x22296c[_0x211f('0x46')]['id']});}return db['VoiceRecording'][_0x211f('0x48')]({'where':_0x13b686,'attributes':['id',_0x211f('0x4f')],'raw':!![]})[_0x211f('0x26')](handleEntityNotFound(_0x376710,null))['then'](function(_0x364af5){if(_0x364af5){var _0x476e74=util[_0x211f('0x32')](_0x211f('0x5e'),_0x364af5[_0x211f('0x4f')]);if(fs[_0x211f('0x51')](_0x476e74)){_0x4835f8=!![];return _0xf736f1[_0x211f('0x5f')](_0x476e74,_0x364af5[_0x211f('0x4f')],config[_0x211f('0x50')][_0x211f('0x60')])[_0x211f('0x26')](function(){return _0x364af5;});}return _0x364af5;}})[_0x211f('0x26')](function(_0x4f305e){if(_0x4f305e){if(!fs[_0x211f('0x51')](_0x4f305e[_0x211f('0x4f')])){throw new db[(_0x211f('0x52'))]['ValidationError']('VoiceRecording\x20not\x20found');}if(_0x4f305e[_0x211f('0x55')]){return _0x376710[_0x211f('0x4c')](_0x4f305e[_0x211f('0x4f')],_0x4f305e['filename']+path[_0x211f('0x56')](_0x4f305e[_0x211f('0x4f')]),function(){if(_0x4835f8){fs[_0x211f('0x57')](_0x4f305e[_0x211f('0x4f')]);}});}else{return _0x376710[_0x211f('0x4c')](_0x4f305e[_0x211f('0x4f')],function(_0x318784){if(_0x4835f8){fs[_0x211f('0x57')](_0x4f305e[_0x211f('0x4f')]);}});}}})['catch'](handleError(_0x376710,null));};exports[_0x211f('0x61')]=function(_0x109194,_0x4ce3fe){return db['VoiceRecording'][_0x211f('0x48')]({'where':{'id':_0x109194['params']['id']}})[_0x211f('0x26')](function(_0x5c1554){if(!_0x5c1554)throw new ReferenceError(_0x211f('0x62'));return _0x5c1554;})[_0x211f('0x26')](function(_0x216e97){var _0x5ec8f9=_0x216e97['value'];logger[_0x211f('0x63')](_0x211f('0x64'),_0x5ec8f9);if(!_[_0x211f('0x65')](_0x216e97[_0x211f('0x4f')])&&fs[_0x211f('0x51')](_0x5ec8f9)){logger[_0x211f('0x63')]('File:\x20\x22'+_0x5ec8f9+_0x211f('0x66'));fs[_0x211f('0x67')](_0x5ec8f9);}_0x5ec8f9=_0x5ec8f9+_0x211f('0x68');if(!_['isNil'](_0x216e97[_0x211f('0x4f')])&&fs['existsSync'](_0x5ec8f9)){logger['info'](_0x211f('0x69')+_0x5ec8f9+'\x22\x20trovato\x20eseguo\x20la\x20cancellazione');fs[_0x211f('0x67')](_0x5ec8f9);}return _0x216e97;})[_0x211f('0x26')](function(_0x3a1368){if(!_0x3a1368)throw new InternalError();return _0x3a1368['destroy']();})[_0x211f('0x26')](function(){_0x4ce3fe[_0x211f('0x1b')](0xcc)['end']();})['catch'](handleError(_0x4ce3fe,null));};function getBucketslist(_0x399952,_0x5c5843,_0x457c21){return new Promise(function(_0x226e76,_0x11a149){var _0x5889db=new AWS['S3']({'accessKeyId':_0x5c5843,'secretAccessKey':_0x399952,'region':_0x457c21});_0x5889db['listBuckets']({},function(_0x887d29,_0x5d4b0c){if(_0x887d29){return _0x11a149(_0x887d29);}else{return _0x226e76(_0x5d4b0c);}});});}function createBucket(_0x3ea59a,_0x3d2168,_0x6a7a7a,_0x13e8b7){return new Promise(function(_0x19188f,_0x210e15){var _0x196f8f=new AWS['S3']({'accessKeyId':_0x3d2168,'secretAccessKey':_0x3ea59a,'region':_0x6a7a7a});_0x196f8f[_0x211f('0x6a')]({'Bucket':_0x13e8b7},function(_0x184660,_0xbfd97a){if(_0x184660){return _0x210e15(_0x184660);}else{return _0x19188f(_0xbfd97a);}});});}function uploadFile(_0x3a9fcf,_0x27b2e5,_0x30d3f2,_0x53013a,_0x543cb3,_0x2d896d){return new Promise(function(_0x391c56,_0x38f236){var _0x166e64=new AWS['S3']({'accessKeyId':_0x27b2e5,'secretAccessKey':_0x3a9fcf,'region':_0x30d3f2});_0x166e64[_0x211f('0x6b')]({'Bucket':_0x53013a,'Key':_0x543cb3,'Body':_0x2d896d},function(_0x2003ed,_0x488828){if(_0x2003ed){return _0x38f236(_0x2003ed);}else{return _0x391c56(_0x488828);}});});}function startTranscribe(_0x1a2a42,_0x37885c,_0x390977,_0x4e490b,_0x1d7331,_0x69ffbe){return new Promise(function(_0x4bb454,_0x4e1a14){var _0x5d521d=new AWS[(_0x211f('0x6c'))]({'accessKeyId':_0x37885c,'secretAccessKey':_0x1a2a42,'region':_0x390977});_0x5d521d[_0x211f('0x6d')]({'TranscriptionJobName':_0x4e490b,'LanguageCode':_0x1d7331,'Media':{'MediaFileUri':_0x69ffbe}},function(_0x5ce2d7,_0x2322db){if(_0x5ce2d7){return _0x4e1a14(_0x5ce2d7);}else{return _0x4bb454(_0x2322db);}});});}function transcribe(_0x433dbf,_0x3f71f1,_0x1db11e,_0x15083e,_0x3f86a0,_0x3828a1,_0x5f4afa){return new Promise(function(_0x1aff8,_0x47544b){var _0x4e940d={};logger[_0x211f('0x63')](util['format']('[RUNTRANSCRIPT][%d]\x20Starting\x20voice\x20recording\x20upload\x20in\x20bucket\x20%s',_0x433dbf,_0x3f86a0));return uploadFile(_0x3f71f1,_0x1db11e,_0x15083e,_0x3f86a0,path[_0x211f('0x6e')](_0x3828a1),fs[_0x211f('0x6f')](_0x3828a1))[_0x211f('0x26')](function(_0x26b75f){logger['info'](util['format'](_0x211f('0x70'),_0x433dbf,_0x3f86a0,_0x26b75f[_0x211f('0x71')]));_0x4e940d[_0x211f('0x72')]=_0x26b75f[_0x211f('0x73')];_0x4e940d[_0x211f('0x74')]=_0x26b75f[_0x211f('0x71')];logger[_0x211f('0x63')](util[_0x211f('0x32')](_0x211f('0x75'),_0x433dbf));return startTranscribe(_0x3f71f1,_0x1db11e,_0x15083e,uuidv4(),_0x5f4afa,_0x26b75f[_0x211f('0x71')]);})['then'](function(_0x2ddee2){logger[_0x211f('0x63')](util[_0x211f('0x32')]('[RUNTRANSCRIPT][%d]\x20Transcription\x20job\x20%s\x20created',_0x433dbf,_0x2ddee2[_0x211f('0x76')][_0x211f('0x77')]));_0x4e940d[_0x211f('0x78')]=_0x2ddee2[_0x211f('0x76')]['TranscriptionJobName'];_0x4e940d[_0x211f('0x79')]=_0x2ddee2[_0x211f('0x76')][_0x211f('0x7a')];return _0x1aff8(_0x4e940d);})[_0x211f('0x44')](function(_0x3b3c22){return _0x47544b(_0x3b3c22);});});}exports[_0x211f('0x7b')]=function(_0x408afc,_0xed75c3,_0x3b9fe2){var _0xb26c37;var _0x2c8244;var _0x36e071;var _0xda6ff9=require('../../components/encryptor');return db[_0x211f('0x2d')][_0x211f('0x7c')]({'where':{'id':_0x408afc[_0x211f('0x46')]['id']}})[_0x211f('0x26')](function(_0x369b32){if(_0x369b32){var _0x3baaf6=util[_0x211f('0x32')](_0x211f('0x5e'),_0x369b32[_0x211f('0x4f')]);if(fs[_0x211f('0x51')](_0x3baaf6)){cypher=!![];return _0xda6ff9[_0x211f('0x5f')](_0x3baaf6,_0x369b32[_0x211f('0x4f')],config[_0x211f('0x50')][_0x211f('0x60')])[_0x211f('0x26')](function(){return _0x369b32;});}return _0x369b32;}})['then'](function(_0x5cc376){if(!_0x5cc376){throw new db[(_0x211f('0x52'))]['ValidationError']('Voice\x20Recording\x20not\x20found');}_0x2c8244=_0x5cc376;return db[_0x211f('0x7d')][_0x211f('0x7c')]({'where':{'id':0x1}});})['then'](handleEntityNotFound(_0xed75c3,null))[_0x211f('0x26')](function(_0x37085e){if(_0x37085e){_0xb26c37=_0x37085e;if(!_0xb26c37[_0x211f('0x7e')]||!_0xb26c37['transcribeAccountId']||!_0xb26c37['transcribeRegion']||!_0xb26c37[_0x211f('0x7f')]||!_0xb26c37[_0x211f('0x72')]){throw new db['Sequelize'][(_0x211f('0x53'))](_0x211f('0x80'));}if(_0x408afc[_0x211f('0x4a')][_0x211f('0x81')]&&(!_0xb26c37[_0x211f('0x82')]||!_0xb26c37['sentimentAccountId']||!_0xb26c37['sentimentRegion']||!_0xb26c37[_0x211f('0x7f')]||!_0xb26c37['bucket'])){throw new db[(_0x211f('0x52'))][(_0x211f('0x53'))](_0x211f('0x83'));}return db[_0x211f('0x84')]['findOne']({'where':{'id':_0xb26c37[_0x211f('0x85')]}});}})[_0x211f('0x26')](function(_0x147a73){if(!_0x147a73){throw new db[(_0x211f('0x52'))][(_0x211f('0x53'))]('Cloud\x20Provider\x20not\x20available');}if(!_0x147a73[_0x211f('0x86')]||!_0x147a73[_0x211f('0x87')]){throw new db['Sequelize']['ValidationError'](_0x211f('0x88'));}_0x36e071=_0x147a73;return getBucketslist(_0x36e071['data1'],_0x36e071['data2'],_0xb26c37[_0x211f('0x89')]);})['then'](function(_0x2832ef){if(_0x2832ef&&_0x2832ef[_0x211f('0x8a')]){var _0x3af9ec=_[_0x211f('0x48')](_0x2832ef['Buckets'],function(_0x1a36d1){return _0x1a36d1['Name']===_0xb26c37[_0x211f('0x72')];});if(!_0x3af9ec){logger['info'](util['format']('[RUNTRANSCRIPT][%d]\x20Bucket\x20%s\x20not\x20available',_0x408afc[_0x211f('0x46')]['id'],_0xb26c37[_0x211f('0x72')]));return createBucket(_0x36e071[_0x211f('0x86')],_0x36e071[_0x211f('0x87')],_0xb26c37[_0x211f('0x89')],_0xb26c37[_0x211f('0x72')]);}logger[_0x211f('0x63')](util[_0x211f('0x32')](_0x211f('0x8b'),_0x408afc[_0x211f('0x46')]['id'],_0xb26c37[_0x211f('0x72')]));return;}})['then'](function(_0x985d69){if(_0x2c8244[_0x211f('0x79')]===_0x211f('0x8c')){return transcribe(_0x408afc[_0x211f('0x46')]['id'],_0x36e071[_0x211f('0x86')],_0x36e071[_0x211f('0x87')],_0xb26c37['transcribeRegion'],_0xb26c37['bucket'],_0x2c8244['value'],_0xb26c37[_0x211f('0x7f')]);}else{logger[_0x211f('0x63')](util[_0x211f('0x32')](_0x211f('0x8d'),_0x408afc[_0x211f('0x46')]['id']));return{'transcribeStatus':'IN_PROGRESS'};}})['then'](function(_0x3e7eb2){if(_0x3e7eb2){_0x3e7eb2[_0x211f('0x8e')]=_0x408afc[_0x211f('0x4a')][_0x211f('0x81')];return _0x2c8244['updateAttributes'](_0x3e7eb2);}})[_0x211f('0x26')](respondWithResult(_0xed75c3,null))[_0x211f('0x44')](handleError(_0xed75c3,null));};function writeFile(_0x3a8b60,_0x57bd9f){return new Promise(function(_0x25df9e,_0x7229ca){fs['writeFile'](_0x57bd9f,_0x3a8b60,function(_0x2806ce,_0x98e6d5){if(_0x2806ce){return _0x7229ca(_0x2806ce);}else{return _0x25df9e(_0x98e6d5);}});});}exports[_0x211f('0x8f')]=function(_0x1f3852,_0xb73e4c,_0x29478c){return db[_0x211f('0x2d')][_0x211f('0x7c')]({'where':{'id':_0x1f3852[_0x211f('0x46')]['id']}})[_0x211f('0x26')](handleEntityNotFound(_0xb73e4c))[_0x211f('0x26')](function(_0x5eafde){if(_0x5eafde&&_0x5eafde[_0x211f('0x90')]){var _0x519994=_0x5eafde[_0x211f('0x90')];var _0x36b0b0=config[_0x211f('0x91')]+'/server/files/transcribes/transcribe_'+_0x5eafde['id']+_0x211f('0x92');if(fs[_0x211f('0x51')](_0x36b0b0)){return _0x36b0b0;}return writeFile(_0x519994,_0x36b0b0)['then'](function(){return _0x36b0b0;});}else{throw new db[(_0x211f('0x52'))][(_0x211f('0x53'))](_0x211f('0x93'));}})[_0x211f('0x26')](function(_0x201d92){return _0xb73e4c['download'](_0x201d92);})[_0x211f('0x44')](handleError(_0xb73e4c));};