Built motion from commit (unavailable).|2.5.6
[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 _0xb799=['TranscriptionJobName','transcribeName','transcribeStatus','TranscriptionJob','TranscriptionJobStatus','runTranscribe','ValidationError','Voice\x20Recording\x20not\x20found','findOne','transcribe','transcribeAccountId','transcribeRegion','language','Transcribe\x20not\x20configured','runSentiment','sentiment','sentimentRegion','CloudProvider','Cloud\x20Provider\x20not\x20available','data1','data2','Cloud\x20Provider\x20not\x20configured','Buckets','Name','[RUNTRANSCRIPT][%d]\x20Bucket\x20%s\x20not\x20available','[RUNTRANSCRIPT][%d]\x20Bucket\x20%s\x20available','NEW','[RUNTRANSCRIPT][%d]\x20Transcript\x20action\x20already\x20requested','IN_PROGRESS','tempSentiment','updateAttributes','downloadTranscribe','fileText','root','/server/files/transcribes/transcribe_','.txt','Transcript\x20not\x20available','html-pdf','eml-format','rimraf','zip-dir','moment','bluebird','path','sox','to-csv','lodash','squel','crypto','papaparse','aws-sdk','uuid/v4','../../components/auth/service','../../config/license/hardware','../../config/logger','api','../../config/environment','../../config/license/util','status','end','count','offset','limit','set','json','apply','save','update','then','destroy','sendStatus','error','name','send','index','map','VoiceRecording','rawAttributes','key','model','differenceBy','format','query','keys','filters','intersection','fields','attributes','hasOwnProperty','order','sort','where','pick','filter','merge','type','VIRTUAL','options','includeAll','include','findAll','rows','catch','show','length','find','create','body','describe','download','../../components/encryptor','uniqueid','params','value','%s.cypher','decryptFile','secrets','existsSync','VoiceRecording\x20not\x20found','filename','extname','unlink','message','Not\x20found','MD5','sequelize','col','token','$and','recording','Sequelize','cancellazione\x20fisica\x20documento\x20%s','isNil','info','unlinkSync','.cypher','File:\x20\x22','\x22\x20trovato\x20eseguo\x20la\x20cancellazione','listBuckets','createBucket','startTranscriptionJob','[RUNTRANSCRIPT][%d]\x20Starting\x20voice\x20recording\x20upload\x20in\x20bucket\x20%s','basename','Location','bucket','[RUNTRANSCRIPT][%d]\x20Sending\x20transcribe\x20request','[RUNTRANSCRIPT][%d]\x20Transcription\x20job\x20%s\x20created'];(function(_0x334fea,_0x1f1e18){var _0x3c5829=function(_0x4fd6ac){while(--_0x4fd6ac){_0x334fea['push'](_0x334fea['shift']());}};_0x3c5829(++_0x1f1e18);}(_0xb799,0x14b));var _0x9b79=function(_0x3dd15e,_0x1f0015){_0x3dd15e=_0x3dd15e-0x0;var _0x231fd0=_0xb799[_0x3dd15e];return _0x231fd0;};'use strict';var pdf=require(_0x9b79('0x0'));var emlformat=require(_0x9b79('0x1'));var rimraf=require(_0x9b79('0x2'));var zipdir=require(_0x9b79('0x3'));var jsonpatch=require('fast-json-patch');var rp=require('request-promise');var moment=require(_0x9b79('0x4'));var BPromise=require(_0x9b79('0x5'));var Mustache=require('mustache');var util=require('util');var path=require(_0x9b79('0x6'));var sox=require(_0x9b79('0x7'));var csv=require(_0x9b79('0x8'));var ejs=require('ejs');var fs=require('fs');var _=require(_0x9b79('0x9'));var squel=require(_0x9b79('0xa'));var crypto=require(_0x9b79('0xb'));var jsforce=require('jsforce');var deskjs=require('desk.js');var toCsv=require(_0x9b79('0x8'));var querystring=require('querystring');var Papa=require(_0x9b79('0xc'));var AWS=require(_0x9b79('0xd'));var uuidv4=require(_0x9b79('0xe'));var Redis=require('ioredis');var authService=require(_0x9b79('0xf'));var qs=require('../../components/parsers/qs');var as=require('../../components/parsers/advancedSearch');var hardwareService=require(_0x9b79('0x10'));var logger=require(_0x9b79('0x11'))(_0x9b79('0x12'));var utils=require('../../config/utils');var config=require(_0x9b79('0x13'));var licenseUtil=require(_0x9b79('0x14'));var db=require('../../mysqldb')['db'];function respondWithStatusCode(_0x61679c,_0x1e51dc){_0x1e51dc=_0x1e51dc||0xcc;return function(_0x1c8331){if(_0x1c8331){return _0x61679c['sendStatus'](_0x1e51dc);}return _0x61679c[_0x9b79('0x15')](_0x1e51dc)[_0x9b79('0x16')]();};}function respondWithResult(_0x3fa3fe,_0x49ac02){_0x49ac02=_0x49ac02||0xc8;return function(_0x3a9964){if(_0x3a9964){return _0x3fa3fe[_0x9b79('0x15')](_0x49ac02)['json'](_0x3a9964);}};}function respondWithFilteredResult(_0x46ea0f,_0x412f4c){return function(_0x43564b){if(_0x43564b){var _0x3e7723=_0x43564b[_0x9b79('0x17')],_0x20bfc8=_0x412f4c[_0x9b79('0x18')],_0x2f339d=_0x412f4c['offset']+_0x412f4c[_0x9b79('0x19')],_0x1b2c08;if(_0x2f339d>=_0x3e7723){_0x2f339d=_0x3e7723;_0x1b2c08=0xc8;}else{_0x1b2c08=0xce;}_0x46ea0f['status'](_0x1b2c08);return _0x46ea0f[_0x9b79('0x1a')]('Content-Range',_0x20bfc8+'-'+_0x2f339d+'/'+_0x3e7723)[_0x9b79('0x1b')](_0x43564b);}return null;};}function patchUpdates(_0x1c1de4){return function(_0x456813){try{jsonpatch[_0x9b79('0x1c')](_0x456813,_0x1c1de4,!![]);}catch(_0x2b2232){return BPromise['reject'](_0x2b2232);}return _0x456813[_0x9b79('0x1d')]();};}function saveUpdates(_0x415117,_0x13f861){return function(_0x461ef4){if(_0x461ef4){return _0x461ef4[_0x9b79('0x1e')](_0x415117)[_0x9b79('0x1f')](function(_0x5409cf){return _0x5409cf;});}return null;};}function removeEntity(_0x10f5ff,_0x3b6a1e){return function(_0x2d6b97){if(_0x2d6b97){return _0x2d6b97[_0x9b79('0x20')]()[_0x9b79('0x1f')](function(){_0x10f5ff['status'](0xcc)['end']();});}};}function handleEntityNotFound(_0x37076f,_0x2b8063){return function(_0x3ba766){if(!_0x3ba766){_0x37076f[_0x9b79('0x21')](0x194);}return _0x3ba766;};}function handleError(_0x1e6f7e,_0x1b9daf){_0x1b9daf=_0x1b9daf||0x1f4;return function(_0x2cf991){logger[_0x9b79('0x22')](_0x2cf991['stack']);if(_0x2cf991[_0x9b79('0x23')]){delete _0x2cf991[_0x9b79('0x23')];}_0x1e6f7e[_0x9b79('0x15')](_0x1b9daf)[_0x9b79('0x24')](_0x2cf991);};}exports[_0x9b79('0x25')]=function(_0x5133bc,_0x499232){var _0x196206={},_0x4cc9c2={},_0x2988c9={'count':0x0,'rows':[]};var _0x548c42=_[_0x9b79('0x26')](db[_0x9b79('0x27')][_0x9b79('0x28')],function(_0x1c71ab){return{'name':_0x1c71ab['fieldName'],'type':_0x1c71ab['type'][_0x9b79('0x29')]};});_0x4cc9c2[_0x9b79('0x2a')]=_[_0x9b79('0x2b')](_['map'](_0x548c42,_0x9b79('0x23')),[_0x9b79('0x2c')]);_0x4cc9c2[_0x9b79('0x2d')]=_[_0x9b79('0x2e')](_0x5133bc[_0x9b79('0x2d')]);_0x4cc9c2[_0x9b79('0x2f')]=_[_0x9b79('0x30')](_0x4cc9c2['model'],_0x4cc9c2[_0x9b79('0x2d')]);_0x196206['attributes']=_[_0x9b79('0x30')](_0x4cc9c2[_0x9b79('0x2a')],qs['fields'](_0x5133bc[_0x9b79('0x2d')][_0x9b79('0x31')]));_0x196206[_0x9b79('0x32')]=_0x196206[_0x9b79('0x32')]['length']?_0x196206[_0x9b79('0x32')]:_0x4cc9c2['model'];if(!_0x5133bc[_0x9b79('0x2d')][_0x9b79('0x33')]('nolimit')){_0x196206[_0x9b79('0x19')]=qs['limit'](_0x5133bc[_0x9b79('0x2d')][_0x9b79('0x19')]);_0x196206[_0x9b79('0x18')]=qs[_0x9b79('0x18')](_0x5133bc[_0x9b79('0x2d')][_0x9b79('0x18')]);}_0x196206[_0x9b79('0x34')]=qs[_0x9b79('0x35')](_0x5133bc[_0x9b79('0x2d')]['sort']);_0x196206[_0x9b79('0x36')]=qs[_0x9b79('0x2f')](_[_0x9b79('0x37')](_0x5133bc[_0x9b79('0x2d')],_0x4cc9c2[_0x9b79('0x2f')]),_0x548c42);if(_0x5133bc[_0x9b79('0x2d')][_0x9b79('0x38')]){_0x196206[_0x9b79('0x36')]=_[_0x9b79('0x39')](_0x196206[_0x9b79('0x36')],{'$or':_[_0x9b79('0x26')](_0x548c42,function(_0xab3695){if(_0xab3695[_0x9b79('0x3a')]!==_0x9b79('0x3b')){var _0xd9c349={};_0xd9c349[_0xab3695[_0x9b79('0x23')]]={'$like':'%'+_0x5133bc[_0x9b79('0x2d')][_0x9b79('0x38')]+'%'};return _0xd9c349;}})});}_0x196206=_[_0x9b79('0x39')]({},_0x196206,_0x5133bc[_0x9b79('0x3c')]);var _0x51035e={'where':_0x196206[_0x9b79('0x36')]};return db[_0x9b79('0x27')][_0x9b79('0x17')](_0x51035e)[_0x9b79('0x1f')](function(_0x4064d0){_0x2988c9['count']=_0x4064d0;if(_0x5133bc['query'][_0x9b79('0x3d')]){_0x196206[_0x9b79('0x3e')]=[{'all':!![]}];}return db[_0x9b79('0x27')][_0x9b79('0x3f')](_0x196206);})[_0x9b79('0x1f')](function(_0x4cb6cc){_0x2988c9[_0x9b79('0x40')]=_0x4cb6cc;return _0x2988c9;})[_0x9b79('0x1f')](respondWithFilteredResult(_0x499232,_0x196206))[_0x9b79('0x41')](handleError(_0x499232,null));};exports[_0x9b79('0x42')]=function(_0x18604e,_0x20139d){var _0x7ea0fc={'raw':![],'where':{'id':_0x18604e['params']['id']}},_0x18af74={};_0x18af74[_0x9b79('0x2a')]=_['keys'](db[_0x9b79('0x27')]['rawAttributes']);_0x18af74[_0x9b79('0x2d')]=_[_0x9b79('0x2e')](_0x18604e[_0x9b79('0x2d')]);_0x18af74[_0x9b79('0x2f')]=_[_0x9b79('0x30')](_0x18af74[_0x9b79('0x2a')],_0x18af74[_0x9b79('0x2d')]);_0x7ea0fc[_0x9b79('0x32')]=_[_0x9b79('0x30')](_0x18af74['model'],qs[_0x9b79('0x31')](_0x18604e[_0x9b79('0x2d')][_0x9b79('0x31')]));_0x7ea0fc[_0x9b79('0x32')]=_0x7ea0fc[_0x9b79('0x32')][_0x9b79('0x43')]?_0x7ea0fc['attributes']:_0x18af74['model'];if(_0x18604e[_0x9b79('0x2d')][_0x9b79('0x3d')]){_0x7ea0fc[_0x9b79('0x3e')]=[{'all':!![]}];}_0x7ea0fc=_[_0x9b79('0x39')]({},_0x7ea0fc,_0x18604e[_0x9b79('0x3c')]);return db['VoiceRecording'][_0x9b79('0x44')](_0x7ea0fc)[_0x9b79('0x1f')](handleEntityNotFound(_0x20139d,null))[_0x9b79('0x1f')](respondWithResult(_0x20139d,null))[_0x9b79('0x41')](handleError(_0x20139d,null));};exports[_0x9b79('0x45')]=function(_0x4c15e7,_0x54f88a){return db[_0x9b79('0x27')][_0x9b79('0x45')](_0x4c15e7['body'],{})[_0x9b79('0x1f')](respondWithResult(_0x54f88a,0xc9))[_0x9b79('0x41')](handleError(_0x54f88a,null));};exports['update']=function(_0x241eee,_0x5b4c3d){if(_0x241eee[_0x9b79('0x46')]['id']){delete _0x241eee[_0x9b79('0x46')]['id'];}return db['VoiceRecording'][_0x9b79('0x44')]({'where':{'id':_0x241eee['params']['id']}})['then'](handleEntityNotFound(_0x5b4c3d,null))[_0x9b79('0x1f')](saveUpdates(_0x241eee[_0x9b79('0x46')],null))['then'](respondWithResult(_0x5b4c3d,null))[_0x9b79('0x41')](handleError(_0x5b4c3d,null));};exports['describe']=function(_0x4c8d64,_0x259046){return db[_0x9b79('0x27')][_0x9b79('0x47')]()['then'](respondWithResult(_0x259046,null))['catch'](handleError(_0x259046,null));};exports[_0x9b79('0x48')]=function(_0x2c107f,_0x186329,_0x46b0dc){var _0x3874ce=require(_0x9b79('0x49'));var _0x56f607=![];var _0x513cdc={};if(_0x2c107f[_0x9b79('0x2d')]['type']&&_0x2c107f[_0x9b79('0x2d')]['type']===_0x9b79('0x4a')){_0x513cdc[_0x9b79('0x4a')]=_0x2c107f[_0x9b79('0x4b')]['id'];}else{_0x513cdc['id']=_0x2c107f['params']['id'];}return db[_0x9b79('0x27')][_0x9b79('0x44')]({'where':_0x513cdc,'attributes':['id',_0x9b79('0x4c')],'raw':!![]})[_0x9b79('0x1f')](handleEntityNotFound(_0x186329,null))['then'](function(_0x34a93f){if(_0x34a93f){var _0x2dda07=_0x34a93f[_0x9b79('0x4c')];var _0x1a6b68=util[_0x9b79('0x2c')](_0x9b79('0x4d'),_0x2dda07);if(fs['existsSync'](_0x1a6b68)){_0x56f607=!![];return _0x3874ce[_0x9b79('0x4e')](_0x1a6b68,_0x2dda07,config[_0x9b79('0x4f')]['recording'])[_0x9b79('0x1f')](function(){return _0x34a93f;});}return _0x34a93f;}})[_0x9b79('0x1f')](function(_0x21ac0a){if(_0x21ac0a){var _0x5ce605=_0x21ac0a['value'];if(!fs[_0x9b79('0x50')](_0x5ce605)){throw new db['Sequelize']['ValidationError'](_0x9b79('0x51'));}if(_0x21ac0a[_0x9b79('0x52')]){return _0x186329[_0x9b79('0x48')](_0x5ce605,_0x21ac0a['filename']+path[_0x9b79('0x53')](_0x5ce605),function(){if(_0x56f607){fs[_0x9b79('0x54')](_0x5ce605);}});}else{return _0x186329[_0x9b79('0x48')](_0x5ce605,function(_0x473886){if(_0x56f607){fs[_0x9b79('0x54')](_0x5ce605);}});}}})[_0x9b79('0x41')](function(_0xc25fda){if(_0xc25fda[_0x9b79('0x55')]===_0x9b79('0x51')){_0x186329[_0x9b79('0x15')](0x194)['send'](_0x9b79('0x56'));}else{return handleError(_0x186329,null);}});};exports['downloads']=function(_0x310bda,_0x33afce,_0xbd8522){var _0x41927e=require('../../components/encryptor');var _0x18f0f7=![];var _0x3c2761={'$and':[db['sequelize'][_0x9b79('0x36')](db['sequelize']['fn'](_0x9b79('0x57'),db[_0x9b79('0x58')][_0x9b79('0x59')](_0x9b79('0x4a'))),_0x310bda[_0x9b79('0x2d')][_0x9b79('0x5a')])]};if(_0x310bda[_0x9b79('0x2d')][_0x9b79('0x3a')]&&_0x310bda[_0x9b79('0x2d')][_0x9b79('0x3a')]===_0x9b79('0x4a')){_0x3c2761['$and']['push']({'uniqueid':_0x310bda[_0x9b79('0x4b')]['id']});}else{_0x3c2761[_0x9b79('0x5b')]['push']({'id':_0x310bda[_0x9b79('0x4b')]['id']});}return db[_0x9b79('0x27')][_0x9b79('0x44')]({'where':_0x3c2761,'attributes':['id','value'],'raw':!![]})['then'](handleEntityNotFound(_0x33afce,null))[_0x9b79('0x1f')](function(_0x20ff87){if(_0x20ff87){var _0x8b3d70=util['format'](_0x9b79('0x4d'),_0x20ff87[_0x9b79('0x4c')]);if(fs[_0x9b79('0x50')](_0x8b3d70)){_0x18f0f7=!![];return _0x41927e[_0x9b79('0x4e')](_0x8b3d70,_0x20ff87[_0x9b79('0x4c')],config[_0x9b79('0x4f')][_0x9b79('0x5c')])[_0x9b79('0x1f')](function(){return _0x20ff87;});}return _0x20ff87;}})['then'](function(_0x562f3e){if(_0x562f3e){if(!fs['existsSync'](_0x562f3e[_0x9b79('0x4c')])){throw new db[(_0x9b79('0x5d'))]['ValidationError'](_0x9b79('0x51'));}if(_0x562f3e[_0x9b79('0x52')]){return _0x33afce[_0x9b79('0x48')](_0x562f3e['value'],_0x562f3e[_0x9b79('0x52')]+path[_0x9b79('0x53')](_0x562f3e[_0x9b79('0x4c')]),function(){if(_0x18f0f7){fs[_0x9b79('0x54')](_0x562f3e[_0x9b79('0x4c')]);}});}else{return _0x33afce['download'](_0x562f3e['value'],function(_0x4538df){if(_0x18f0f7){fs['unlink'](_0x562f3e[_0x9b79('0x4c')]);}});}}})['catch'](handleError(_0x33afce,null));};exports[_0x9b79('0x20')]=function(_0x1d1288,_0x1fba28){return db['VoiceRecording'][_0x9b79('0x44')]({'where':{'id':_0x1d1288[_0x9b79('0x4b')]['id']}})[_0x9b79('0x1f')](function(_0x6e943c){if(!_0x6e943c)throw new ReferenceError('Entity\x20not\x20found');return _0x6e943c;})[_0x9b79('0x1f')](function(_0x661319){var _0x5e4d12=_0x661319[_0x9b79('0x4c')];logger['info'](_0x9b79('0x5e'),_0x5e4d12);if(!_[_0x9b79('0x5f')](_0x661319[_0x9b79('0x4c')])&&fs[_0x9b79('0x50')](_0x5e4d12)){logger[_0x9b79('0x60')]('File:\x20\x22'+_0x5e4d12+'\x22\x20trovato\x20eseguo\x20la\x20cancellazione');fs[_0x9b79('0x61')](_0x5e4d12);}_0x5e4d12=_0x5e4d12+_0x9b79('0x62');if(!_[_0x9b79('0x5f')](_0x661319[_0x9b79('0x4c')])&&fs[_0x9b79('0x50')](_0x5e4d12)){logger[_0x9b79('0x60')](_0x9b79('0x63')+_0x5e4d12+_0x9b79('0x64'));fs[_0x9b79('0x61')](_0x5e4d12);}return _0x661319;})[_0x9b79('0x1f')](function(_0xb5c234){if(!_0xb5c234)throw new InternalError();return _0xb5c234['destroy']();})['then'](function(){_0x1fba28[_0x9b79('0x15')](0xcc)[_0x9b79('0x16')]();})[_0x9b79('0x41')](handleError(_0x1fba28,null));};function getBucketslist(_0x3fb171,_0x1c02fd,_0x2a3f5d){return new Promise(function(_0x1e7d1c,_0x1e4737){var _0x237b5d=new AWS['S3']({'accessKeyId':_0x1c02fd,'secretAccessKey':_0x3fb171,'region':_0x2a3f5d});_0x237b5d[_0x9b79('0x65')]({},function(_0x2a2cf4,_0x3d87bc){if(_0x2a2cf4){return _0x1e4737(_0x2a2cf4);}else{return _0x1e7d1c(_0x3d87bc);}});});}function createBucket(_0x3c7413,_0x1871ae,_0x2b3556,_0x59d5dc){return new Promise(function(_0x20865d,_0x29ec52){var _0x1571f7=new AWS['S3']({'accessKeyId':_0x1871ae,'secretAccessKey':_0x3c7413,'region':_0x2b3556});_0x1571f7[_0x9b79('0x66')]({'Bucket':_0x59d5dc},function(_0x3b345a,_0x1f2007){if(_0x3b345a){return _0x29ec52(_0x3b345a);}else{return _0x20865d(_0x1f2007);}});});}function uploadFile(_0x1eff2d,_0x38ab36,_0x35264e,_0x2d95be,_0x4c9a8f,_0x575d17){return new Promise(function(_0x1cfd0d,_0x472ddc){var _0x3b9f7e=new AWS['S3']({'accessKeyId':_0x38ab36,'secretAccessKey':_0x1eff2d,'region':_0x35264e});_0x3b9f7e['upload']({'Bucket':_0x2d95be,'Key':_0x4c9a8f,'Body':_0x575d17},function(_0x5a0c10,_0x742208){if(_0x5a0c10){return _0x472ddc(_0x5a0c10);}else{return _0x1cfd0d(_0x742208);}});});}function startTranscribe(_0x45d2cb,_0x2fbd8e,_0x573e18,_0x3d9e45,_0x4df78d,_0x220e96){return new Promise(function(_0x55c283,_0x487a30){var _0x512ae9=new AWS['TranscribeService']({'accessKeyId':_0x2fbd8e,'secretAccessKey':_0x45d2cb,'region':_0x573e18});_0x512ae9[_0x9b79('0x67')]({'TranscriptionJobName':_0x3d9e45,'LanguageCode':_0x4df78d,'Media':{'MediaFileUri':_0x220e96}},function(_0x65a020,_0x371a0c){if(_0x65a020){return _0x487a30(_0x65a020);}else{return _0x55c283(_0x371a0c);}});});}function transcribe(_0x194d4a,_0x347f03,_0x4ef9d7,_0x3eed09,_0x4e9645,_0x387164,_0x56688d){return new Promise(function(_0x544bad,_0x377edc){var _0x55fe7e={};logger[_0x9b79('0x60')](util[_0x9b79('0x2c')](_0x9b79('0x68'),_0x194d4a,_0x4e9645));return uploadFile(_0x347f03,_0x4ef9d7,_0x3eed09,_0x4e9645,path[_0x9b79('0x69')](_0x387164),fs['readFileSync'](_0x387164))[_0x9b79('0x1f')](function(_0x2cecd6){logger[_0x9b79('0x60')](util['format']('[RUNTRANSCRIPT][%d]\x20Voice\x20recording\x20uploaded\x20in\x20bucket\x20%s\x20(%s)',_0x194d4a,_0x4e9645,_0x2cecd6[_0x9b79('0x6a')]));_0x55fe7e[_0x9b79('0x6b')]=_0x2cecd6['Bucket'];_0x55fe7e['location']=_0x2cecd6[_0x9b79('0x6a')];logger[_0x9b79('0x60')](util['format'](_0x9b79('0x6c'),_0x194d4a));return startTranscribe(_0x347f03,_0x4ef9d7,_0x3eed09,uuidv4(),_0x56688d,_0x2cecd6[_0x9b79('0x6a')]);})[_0x9b79('0x1f')](function(_0x459045){logger[_0x9b79('0x60')](util['format'](_0x9b79('0x6d'),_0x194d4a,_0x459045['TranscriptionJob'][_0x9b79('0x6e')]));_0x55fe7e[_0x9b79('0x6f')]=_0x459045['TranscriptionJob'][_0x9b79('0x6e')];_0x55fe7e[_0x9b79('0x70')]=_0x459045[_0x9b79('0x71')][_0x9b79('0x72')];return _0x544bad(_0x55fe7e);})[_0x9b79('0x41')](function(_0x56694c){return _0x377edc(_0x56694c);});});}exports[_0x9b79('0x73')]=function(_0x391582,_0x20e1d8,_0xe1aadb){var _0x1bf40b;var _0x41582b;var _0x38c509;var _0x5a7e5a=require('../../components/encryptor');return db['VoiceRecording']['findOne']({'where':{'id':_0x391582[_0x9b79('0x4b')]['id']}})['then'](function(_0x56bcd4){if(_0x56bcd4){var _0x1140c6=util[_0x9b79('0x2c')](_0x9b79('0x4d'),_0x56bcd4[_0x9b79('0x4c')]);if(fs['existsSync'](_0x1140c6)){cypher=!![];return _0x5a7e5a[_0x9b79('0x4e')](_0x1140c6,_0x56bcd4[_0x9b79('0x4c')],config[_0x9b79('0x4f')][_0x9b79('0x5c')])[_0x9b79('0x1f')](function(){return _0x56bcd4;});}return _0x56bcd4;}})[_0x9b79('0x1f')](function(_0x43de98){if(!_0x43de98){throw new db[(_0x9b79('0x5d'))][(_0x9b79('0x74'))](_0x9b79('0x75'));}_0x41582b=_0x43de98;return db['Setting'][_0x9b79('0x76')]({'where':{'id':0x1}});})[_0x9b79('0x1f')](handleEntityNotFound(_0x20e1d8,null))[_0x9b79('0x1f')](function(_0x56dee3){if(_0x56dee3){_0x1bf40b=_0x56dee3;if(!_0x1bf40b[_0x9b79('0x77')]||!_0x1bf40b[_0x9b79('0x78')]||!_0x1bf40b[_0x9b79('0x79')]||!_0x1bf40b[_0x9b79('0x7a')]||!_0x1bf40b[_0x9b79('0x6b')]){throw new db[(_0x9b79('0x5d'))][(_0x9b79('0x74'))](_0x9b79('0x7b'));}if(_0x391582[_0x9b79('0x46')][_0x9b79('0x7c')]&&(!_0x1bf40b[_0x9b79('0x7d')]||!_0x1bf40b['sentimentAccountId']||!_0x1bf40b[_0x9b79('0x7e')]||!_0x1bf40b['language']||!_0x1bf40b[_0x9b79('0x6b')])){throw new db[(_0x9b79('0x5d'))][(_0x9b79('0x74'))]('Sentiment\x20Analysis\x20not\x20configured');}return db[_0x9b79('0x7f')][_0x9b79('0x76')]({'where':{'id':_0x1bf40b['transcribeAccountId']}});}})[_0x9b79('0x1f')](function(_0x89f72d){if(!_0x89f72d){throw new db[(_0x9b79('0x5d'))][(_0x9b79('0x74'))](_0x9b79('0x80'));}if(!_0x89f72d[_0x9b79('0x81')]||!_0x89f72d[_0x9b79('0x82')]){throw new db['Sequelize'][(_0x9b79('0x74'))](_0x9b79('0x83'));}_0x38c509=_0x89f72d;return getBucketslist(_0x38c509['data1'],_0x38c509['data2'],_0x1bf40b[_0x9b79('0x79')]);})[_0x9b79('0x1f')](function(_0x464979){if(_0x464979&&_0x464979[_0x9b79('0x84')]){var _0x1d3cbc=_[_0x9b79('0x44')](_0x464979[_0x9b79('0x84')],function(_0x6e7372){return _0x6e7372[_0x9b79('0x85')]===_0x1bf40b[_0x9b79('0x6b')];});if(!_0x1d3cbc){logger['info'](util[_0x9b79('0x2c')](_0x9b79('0x86'),_0x391582[_0x9b79('0x4b')]['id'],_0x1bf40b[_0x9b79('0x6b')]));return createBucket(_0x38c509[_0x9b79('0x81')],_0x38c509['data2'],_0x1bf40b[_0x9b79('0x79')],_0x1bf40b['bucket']);}logger['info'](util[_0x9b79('0x2c')](_0x9b79('0x87'),_0x391582[_0x9b79('0x4b')]['id'],_0x1bf40b[_0x9b79('0x6b')]));return;}})[_0x9b79('0x1f')](function(_0x43e3a1){if(_0x41582b[_0x9b79('0x70')]===_0x9b79('0x88')){return transcribe(_0x391582[_0x9b79('0x4b')]['id'],_0x38c509['data1'],_0x38c509['data2'],_0x1bf40b[_0x9b79('0x79')],_0x1bf40b[_0x9b79('0x6b')],_0x41582b[_0x9b79('0x4c')],_0x1bf40b[_0x9b79('0x7a')]);}else{logger[_0x9b79('0x60')](util[_0x9b79('0x2c')](_0x9b79('0x89'),_0x391582[_0x9b79('0x4b')]['id']));return{'transcribeStatus':_0x9b79('0x8a')};}})[_0x9b79('0x1f')](function(_0x3cd4d4){if(_0x3cd4d4){_0x3cd4d4[_0x9b79('0x8b')]=_0x391582[_0x9b79('0x46')][_0x9b79('0x7c')];return _0x41582b[_0x9b79('0x8c')](_0x3cd4d4);}})[_0x9b79('0x1f')](respondWithResult(_0x20e1d8,null))[_0x9b79('0x41')](handleError(_0x20e1d8,null));};function writeFile(_0x44f177,_0x55da6f){return new Promise(function(_0x194b0a,_0x4b1be6){fs['writeFile'](_0x55da6f,_0x44f177,function(_0xf6ca9f,_0x1972b0){if(_0xf6ca9f){return _0x4b1be6(_0xf6ca9f);}else{return _0x194b0a(_0x1972b0);}});});}exports[_0x9b79('0x8d')]=function(_0x6382f2,_0x5137db,_0x311a01){return db['VoiceRecording'][_0x9b79('0x76')]({'where':{'id':_0x6382f2[_0x9b79('0x4b')]['id']}})[_0x9b79('0x1f')](handleEntityNotFound(_0x5137db))[_0x9b79('0x1f')](function(_0x11b250){if(_0x11b250&&_0x11b250[_0x9b79('0x8e')]){var _0x3cd943=_0x11b250[_0x9b79('0x8e')];var _0x8fe42a=config[_0x9b79('0x8f')]+_0x9b79('0x90')+_0x11b250['id']+_0x9b79('0x91');if(fs[_0x9b79('0x50')](_0x8fe42a)){return _0x8fe42a;}return writeFile(_0x3cd943,_0x8fe42a)[_0x9b79('0x1f')](function(){return _0x8fe42a;});}else{throw new db[(_0x9b79('0x5d'))][(_0x9b79('0x74'))](_0x9b79('0x92'));}})[_0x9b79('0x1f')](function(_0x239384){return _0x5137db['download'](_0x239384);})[_0x9b79('0x41')](handleError(_0x5137db));};