Built motion from commit b5413ace.|2.6.9
[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 _0xb5fa=['Setting','transcribe','transcribeAccountId','transcribeRegion','Transcribe\x20not\x20configured','runSentiment','sentiment','sentimentAccountId','sentimentRegion','language','Sentiment\x20Analysis\x20not\x20configured','CloudProvider','Cloud\x20Provider\x20not\x20available','data1','data2','Cloud\x20Provider\x20not\x20configured','Buckets','Name','[RUNTRANSCRIPT][%d]\x20Bucket\x20%s\x20available','[RUNTRANSCRIPT][%d]\x20Transcript\x20action\x20already\x20requested','IN_PROGRESS','updateAttributes','downloadTranscribe','fileText','root','/server/files/transcribes/transcribe_','Transcript\x20not\x20available','eml-format','zip-dir','fast-json-patch','request-promise','moment','bluebird','mustache','util','path','sox','to-csv','fs-extra','lodash','squel','crypto','jsforce','querystring','papaparse','aws-sdk','uuid/v4','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','../../config/license/util','sendStatus','end','offset','undefined','limit','count','status','set','json','reject','save','update','then','destroy','error','stack','index','map','rawAttributes','fieldName','type','key','model','differenceBy','name','query','filters','intersection','attributes','fields','length','hasOwnProperty','nolimit','sort','where','filter','merge','options','VoiceRecording','include','findAll','rows','catch','show','keys','find','create','body','params','describe','uniqueid','value','format','%s.cypher','decryptFile','secrets','recording','existsSync','Sequelize','ValidationError','VoiceRecording\x20not\x20found','filename','download','extname','unlink','message','send','Not\x20found','downloads','../../components/encryptor','sequelize','MD5','col','token','$and','push','isNil','Entity\x20not\x20found','info','cancellazione\x20fisica\x20documento\x20%s','File:\x20\x22','\x22\x20trovato\x20eseguo\x20la\x20cancellazione','.cypher','unlinkSync','upload','TranscribeService','startTranscriptionJob','[RUNTRANSCRIPT][%d]\x20Starting\x20voice\x20recording\x20upload\x20in\x20bucket\x20%s','basename','readFileSync','[RUNTRANSCRIPT][%d]\x20Voice\x20recording\x20uploaded\x20in\x20bucket\x20%s\x20(%s)','bucket','Bucket','location','Location','[RUNTRANSCRIPT][%d]\x20Sending\x20transcribe\x20request','TranscriptionJob','TranscriptionJobName','transcribeName','transcribeStatus','TranscriptionJobStatus','runTranscribe','findOne','Voice\x20Recording\x20not\x20found'];(function(_0x57936e,_0x590f5b){var _0x441ac3=function(_0x36de9b){while(--_0x36de9b){_0x57936e['push'](_0x57936e['shift']());}};_0x441ac3(++_0x590f5b);}(_0xb5fa,0x15d));var _0xab5f=function(_0x4d3071,_0x35eed6){_0x4d3071=_0x4d3071-0x0;var _0x16a0a0=_0xb5fa[_0x4d3071];return _0x16a0a0;};'use strict';var emlformat=require(_0xab5f('0x0'));var rimraf=require('rimraf');var zipdir=require(_0xab5f('0x1'));var jsonpatch=require(_0xab5f('0x2'));var rp=require(_0xab5f('0x3'));var moment=require(_0xab5f('0x4'));var BPromise=require(_0xab5f('0x5'));var Mustache=require(_0xab5f('0x6'));var util=require(_0xab5f('0x7'));var path=require(_0xab5f('0x8'));var sox=require(_0xab5f('0x9'));var csv=require(_0xab5f('0xa'));var ejs=require('ejs');var fs=require('fs');var fs_extra=require(_0xab5f('0xb'));var _=require(_0xab5f('0xc'));var squel=require(_0xab5f('0xd'));var crypto=require(_0xab5f('0xe'));var jsforce=require(_0xab5f('0xf'));var deskjs=require('desk.js');var toCsv=require('to-csv');var querystring=require(_0xab5f('0x10'));var Papa=require(_0xab5f('0x11'));var AWS=require(_0xab5f('0x12'));var uuidv4=require(_0xab5f('0x13'));var Redis=require(_0xab5f('0x14'));var authService=require(_0xab5f('0x15'));var qs=require(_0xab5f('0x16'));var as=require(_0xab5f('0x17'));var hardwareService=require(_0xab5f('0x18'));var logger=require(_0xab5f('0x19'))(_0xab5f('0x1a'));var utils=require(_0xab5f('0x1b'));var config=require(_0xab5f('0x1c'));var licenseUtil=require(_0xab5f('0x1d'));var db=require('../../mysqldb')['db'];function respondWithStatusCode(_0x55f6bc,_0x340b64){_0x340b64=_0x340b64||0xcc;return function(_0x68d71e){if(_0x68d71e){return _0x55f6bc[_0xab5f('0x1e')](_0x340b64);}return _0x55f6bc['status'](_0x340b64)[_0xab5f('0x1f')]();};}function respondWithResult(_0x275fd1,_0x1d74a8){_0x1d74a8=_0x1d74a8||0xc8;return function(_0x2f4521){if(_0x2f4521){return _0x275fd1['status'](_0x1d74a8)['json'](_0x2f4521);}};}function respondWithFilteredResult(_0x530258,_0x940260){return function(_0x58fa94){if(_0x58fa94){var _0xa01246=typeof _0x940260[_0xab5f('0x20')]===_0xab5f('0x21')&&typeof _0x940260[_0xab5f('0x22')]===_0xab5f('0x21');var _0x4dc4ec=_0x58fa94[_0xab5f('0x23')];var _0x3569b7=_0xa01246?0x0:_0x940260[_0xab5f('0x20')];var _0xcfaf6c=_0xa01246?_0x58fa94['count']:_0x940260[_0xab5f('0x20')]+_0x940260['limit'];var _0x2fd8a4;if(_0xcfaf6c>=_0x4dc4ec){_0xcfaf6c=_0x4dc4ec;_0x2fd8a4=0xc8;}else{_0x2fd8a4=0xce;}_0x530258[_0xab5f('0x24')](_0x2fd8a4);return _0x530258[_0xab5f('0x25')]('Content-Range',_0x3569b7+'-'+_0xcfaf6c+'/'+_0x4dc4ec)[_0xab5f('0x26')](_0x58fa94);}return null;};}function patchUpdates(_0x4a90a1){return function(_0x4e1213){try{jsonpatch['apply'](_0x4e1213,_0x4a90a1,!![]);}catch(_0x4f9e09){return BPromise[_0xab5f('0x27')](_0x4f9e09);}return _0x4e1213[_0xab5f('0x28')]();};}function saveUpdates(_0x5cc020,_0x5f329e){return function(_0x32a076){if(_0x32a076){return _0x32a076[_0xab5f('0x29')](_0x5cc020)[_0xab5f('0x2a')](function(_0x37e22e){return _0x37e22e;});}return null;};}function removeEntity(_0x261ed0,_0x372c57){return function(_0x37a6d4){if(_0x37a6d4){return _0x37a6d4[_0xab5f('0x2b')]()[_0xab5f('0x2a')](function(){_0x261ed0[_0xab5f('0x24')](0xcc)[_0xab5f('0x1f')]();});}};}function handleEntityNotFound(_0x559e3f,_0x189319){return function(_0xc915b2){if(!_0xc915b2){_0x559e3f['sendStatus'](0x194);}return _0xc915b2;};}function handleError(_0x501769,_0x2a7805){_0x2a7805=_0x2a7805||0x1f4;return function(_0x55e2aa){logger[_0xab5f('0x2c')](_0x55e2aa[_0xab5f('0x2d')]);if(_0x55e2aa['name']){delete _0x55e2aa['name'];}_0x501769[_0xab5f('0x24')](_0x2a7805)['send'](_0x55e2aa);};}exports[_0xab5f('0x2e')]=function(_0x2b5605,_0x5f57d9){var _0x2ca740={},_0x5e443b={},_0x5d29e6={'count':0x0,'rows':[]};var _0x24b4c6=_[_0xab5f('0x2f')](db['VoiceRecording'][_0xab5f('0x30')],function(_0x5c8ed0){return{'name':_0x5c8ed0[_0xab5f('0x31')],'type':_0x5c8ed0[_0xab5f('0x32')][_0xab5f('0x33')]};});_0x5e443b[_0xab5f('0x34')]=_[_0xab5f('0x35')](_['map'](_0x24b4c6,_0xab5f('0x36')),['format']);_0x5e443b[_0xab5f('0x37')]=_['keys'](_0x2b5605[_0xab5f('0x37')]);_0x5e443b[_0xab5f('0x38')]=_[_0xab5f('0x39')](_0x5e443b[_0xab5f('0x34')],_0x5e443b[_0xab5f('0x37')]);_0x2ca740[_0xab5f('0x3a')]=_[_0xab5f('0x39')](_0x5e443b[_0xab5f('0x34')],qs[_0xab5f('0x3b')](_0x2b5605[_0xab5f('0x37')]['fields']));_0x2ca740[_0xab5f('0x3a')]=_0x2ca740[_0xab5f('0x3a')][_0xab5f('0x3c')]?_0x2ca740[_0xab5f('0x3a')]:_0x5e443b[_0xab5f('0x34')];if(!_0x2b5605[_0xab5f('0x37')][_0xab5f('0x3d')](_0xab5f('0x3e'))){_0x2ca740[_0xab5f('0x22')]=qs[_0xab5f('0x22')](_0x2b5605['query'][_0xab5f('0x22')]);_0x2ca740[_0xab5f('0x20')]=qs[_0xab5f('0x20')](_0x2b5605['query']['offset']);}_0x2ca740['order']=qs[_0xab5f('0x3f')](_0x2b5605[_0xab5f('0x37')][_0xab5f('0x3f')]);_0x2ca740[_0xab5f('0x40')]=qs['filters'](_['pick'](_0x2b5605[_0xab5f('0x37')],_0x5e443b['filters']),_0x24b4c6);if(_0x2b5605['query'][_0xab5f('0x41')]){_0x2ca740['where']=_[_0xab5f('0x42')](_0x2ca740[_0xab5f('0x40')],{'$or':_['map'](_0x24b4c6,function(_0x2f7570){if(_0x2f7570['type']!=='VIRTUAL'){var _0x1c3512={};_0x1c3512[_0x2f7570[_0xab5f('0x36')]]={'$like':'%'+_0x2b5605[_0xab5f('0x37')][_0xab5f('0x41')]+'%'};return _0x1c3512;}})});}_0x2ca740=_[_0xab5f('0x42')]({},_0x2ca740,_0x2b5605[_0xab5f('0x43')]);var _0x25a147={'where':_0x2ca740[_0xab5f('0x40')]};return db[_0xab5f('0x44')]['count'](_0x25a147)['then'](function(_0x3a486f){_0x5d29e6[_0xab5f('0x23')]=_0x3a486f;if(_0x2b5605[_0xab5f('0x37')]['includeAll']){_0x2ca740[_0xab5f('0x45')]=[{'all':!![]}];}return db[_0xab5f('0x44')][_0xab5f('0x46')](_0x2ca740);})[_0xab5f('0x2a')](function(_0x2ecbc7){_0x5d29e6[_0xab5f('0x47')]=_0x2ecbc7;return _0x5d29e6;})['then'](respondWithFilteredResult(_0x5f57d9,_0x2ca740))[_0xab5f('0x48')](handleError(_0x5f57d9,null));};exports[_0xab5f('0x49')]=function(_0x4aae89,_0x56c2ff){var _0x54912a={'raw':![],'where':{'id':_0x4aae89['params']['id']}},_0x2646e7={};_0x2646e7[_0xab5f('0x34')]=_[_0xab5f('0x4a')](db[_0xab5f('0x44')][_0xab5f('0x30')]);_0x2646e7['query']=_[_0xab5f('0x4a')](_0x4aae89[_0xab5f('0x37')]);_0x2646e7[_0xab5f('0x38')]=_[_0xab5f('0x39')](_0x2646e7[_0xab5f('0x34')],_0x2646e7[_0xab5f('0x37')]);_0x54912a[_0xab5f('0x3a')]=_[_0xab5f('0x39')](_0x2646e7[_0xab5f('0x34')],qs['fields'](_0x4aae89['query'][_0xab5f('0x3b')]));_0x54912a['attributes']=_0x54912a[_0xab5f('0x3a')][_0xab5f('0x3c')]?_0x54912a[_0xab5f('0x3a')]:_0x2646e7['model'];if(_0x4aae89[_0xab5f('0x37')]['includeAll']){_0x54912a[_0xab5f('0x45')]=[{'all':!![]}];}_0x54912a=_['merge']({},_0x54912a,_0x4aae89[_0xab5f('0x43')]);return db[_0xab5f('0x44')][_0xab5f('0x4b')](_0x54912a)[_0xab5f('0x2a')](handleEntityNotFound(_0x56c2ff,null))[_0xab5f('0x2a')](respondWithResult(_0x56c2ff,null))[_0xab5f('0x48')](handleError(_0x56c2ff,null));};exports['create']=function(_0x3897b4,_0x5d3341){return db[_0xab5f('0x44')][_0xab5f('0x4c')](_0x3897b4[_0xab5f('0x4d')],{})['then'](respondWithResult(_0x5d3341,0xc9))[_0xab5f('0x48')](handleError(_0x5d3341,null));};exports[_0xab5f('0x29')]=function(_0x49260c,_0x321738){if(_0x49260c[_0xab5f('0x4d')]['id']){delete _0x49260c[_0xab5f('0x4d')]['id'];}return db[_0xab5f('0x44')][_0xab5f('0x4b')]({'where':{'id':_0x49260c[_0xab5f('0x4e')]['id']}})[_0xab5f('0x2a')](handleEntityNotFound(_0x321738,null))[_0xab5f('0x2a')](saveUpdates(_0x49260c[_0xab5f('0x4d')],null))[_0xab5f('0x2a')](respondWithResult(_0x321738,null))[_0xab5f('0x48')](handleError(_0x321738,null));};exports[_0xab5f('0x4f')]=function(_0x1d6b00,_0x1346d3){return db['VoiceRecording'][_0xab5f('0x4f')]()[_0xab5f('0x2a')](respondWithResult(_0x1346d3,null))[_0xab5f('0x48')](handleError(_0x1346d3,null));};exports['download']=function(_0x3c01ab,_0x427ae8,_0x5ef0ca){var _0x312e47=require('../../components/encryptor');var _0x499ac8=![];var _0x2b2816={};if(_0x3c01ab[_0xab5f('0x37')][_0xab5f('0x32')]&&_0x3c01ab[_0xab5f('0x37')][_0xab5f('0x32')]===_0xab5f('0x50')){_0x2b2816['uniqueid']=_0x3c01ab[_0xab5f('0x4e')]['id'];}else{_0x2b2816['id']=_0x3c01ab['params']['id'];}return db[_0xab5f('0x44')][_0xab5f('0x4b')]({'where':_0x2b2816,'attributes':['id',_0xab5f('0x51')],'raw':!![]})[_0xab5f('0x2a')](handleEntityNotFound(_0x427ae8,null))[_0xab5f('0x2a')](function(_0x17b9f6){if(_0x17b9f6){var _0x3d195b=_0x17b9f6[_0xab5f('0x51')];var _0x427b86=util[_0xab5f('0x52')](_0xab5f('0x53'),_0x3d195b);if(fs['existsSync'](_0x427b86)){_0x499ac8=!![];return _0x312e47[_0xab5f('0x54')](_0x427b86,_0x3d195b,config[_0xab5f('0x55')][_0xab5f('0x56')])['then'](function(){return _0x17b9f6;});}return _0x17b9f6;}})[_0xab5f('0x2a')](function(_0x49838c){if(_0x49838c){var _0x81801b=_0x49838c[_0xab5f('0x51')];if(!fs[_0xab5f('0x57')](_0x81801b)){throw new db[(_0xab5f('0x58'))][(_0xab5f('0x59'))](_0xab5f('0x5a'));}if(_0x49838c[_0xab5f('0x5b')]){return _0x427ae8[_0xab5f('0x5c')](_0x81801b,_0x49838c[_0xab5f('0x5b')]+path[_0xab5f('0x5d')](_0x81801b),function(){if(_0x499ac8){fs[_0xab5f('0x5e')](_0x81801b);}});}else{return _0x427ae8['download'](_0x81801b,function(_0x129235){if(_0x499ac8){fs['unlink'](_0x81801b);}});}}})[_0xab5f('0x48')](function(_0x2b9d96){if(_0x2b9d96[_0xab5f('0x5f')]===_0xab5f('0x5a')){_0x427ae8[_0xab5f('0x24')](0x194)[_0xab5f('0x60')](_0xab5f('0x61'));}else{return handleError(_0x427ae8,null);}});};exports[_0xab5f('0x62')]=function(_0x3679f0,_0xd6c17,_0x102667){var _0x619fb7=require(_0xab5f('0x63'));var _0x2d4e32=![];var _0x535e69={'$and':[db[_0xab5f('0x64')][_0xab5f('0x40')](db[_0xab5f('0x64')]['fn'](_0xab5f('0x65'),db[_0xab5f('0x64')][_0xab5f('0x66')](_0xab5f('0x50'))),_0x3679f0[_0xab5f('0x37')][_0xab5f('0x67')])]};if(_0x3679f0[_0xab5f('0x37')][_0xab5f('0x32')]&&_0x3679f0[_0xab5f('0x37')][_0xab5f('0x32')]===_0xab5f('0x50')){_0x535e69[_0xab5f('0x68')][_0xab5f('0x69')]({'uniqueid':_0x3679f0[_0xab5f('0x4e')]['id']});}else{_0x535e69[_0xab5f('0x68')][_0xab5f('0x69')]({'id':_0x3679f0[_0xab5f('0x4e')]['id']});}return db[_0xab5f('0x44')][_0xab5f('0x4b')]({'where':_0x535e69,'attributes':['id',_0xab5f('0x51')],'raw':!![]})[_0xab5f('0x2a')](handleEntityNotFound(_0xd6c17,null))['then'](function(_0x9a33b6){if(_0x9a33b6){var _0x5c8822=util[_0xab5f('0x52')](_0xab5f('0x53'),_0x9a33b6[_0xab5f('0x51')]);if(fs[_0xab5f('0x57')](_0x5c8822)){_0x2d4e32=!![];return _0x619fb7['decryptFile'](_0x5c8822,_0x9a33b6[_0xab5f('0x51')],config[_0xab5f('0x55')][_0xab5f('0x56')])['then'](function(){return _0x9a33b6;});}return _0x9a33b6;}})[_0xab5f('0x2a')](function(_0xc4f73a){if(_0xc4f73a){if(!fs[_0xab5f('0x57')](_0xc4f73a[_0xab5f('0x51')])){throw new db[(_0xab5f('0x58'))][(_0xab5f('0x59'))]('VoiceRecording\x20not\x20found');}if(_0xc4f73a[_0xab5f('0x5b')]){return _0xd6c17[_0xab5f('0x5c')](_0xc4f73a[_0xab5f('0x51')],_0xc4f73a[_0xab5f('0x5b')]+path[_0xab5f('0x5d')](_0xc4f73a['value']),function(){if(_0x2d4e32){fs[_0xab5f('0x5e')](_0xc4f73a[_0xab5f('0x51')]);}});}else{return _0xd6c17['download'](_0xc4f73a[_0xab5f('0x51')],function(_0x2171d7){if(_0x2d4e32){fs[_0xab5f('0x5e')](_0xc4f73a[_0xab5f('0x51')]);}});}}})['catch'](handleError(_0xd6c17,null));};exports[_0xab5f('0x2b')]=function(_0x5b4ade,_0x5c5a88){return db[_0xab5f('0x44')]['find']({'where':{'id':_0x5b4ade[_0xab5f('0x4e')]['id']}})[_0xab5f('0x2a')](function(_0xd3c60f){if(_[_0xab5f('0x6a')](_0xd3c60f)){throw new ReferenceError(_0xab5f('0x6b'));}return _0xd3c60f;})[_0xab5f('0x2a')](function(_0x1f1bda){var _0x51a731=_0x1f1bda[_0xab5f('0x51')];logger[_0xab5f('0x6c')](_0xab5f('0x6d'),_0x51a731);if(!_['isNil'](_0x1f1bda[_0xab5f('0x51')])&&fs[_0xab5f('0x57')](_0x51a731)){logger[_0xab5f('0x6c')](_0xab5f('0x6e')+_0x51a731+_0xab5f('0x6f'));fs['unlinkSync'](_0x51a731);}_0x51a731=_0x51a731+_0xab5f('0x70');if(!_['isNil'](_0x1f1bda['value'])&&fs[_0xab5f('0x57')](_0x51a731)){logger[_0xab5f('0x6c')](_0xab5f('0x6e')+_0x51a731+_0xab5f('0x6f'));fs[_0xab5f('0x71')](_0x51a731);}return _0x1f1bda;})[_0xab5f('0x2a')](function(_0x2d4df0){if(!_0x2d4df0)throw new InternalError();return _0x2d4df0['destroy']();})['then'](function(){_0x5c5a88['status'](0xcc)[_0xab5f('0x1f')]();})[_0xab5f('0x48')](handleError(_0x5c5a88,null));};function getBucketslist(_0x33c58d,_0x39c8f3,_0x185e5f){return new Promise(function(_0x1a5bce,_0xc5285d){var _0x2d877d=new AWS['S3']({'accessKeyId':_0x39c8f3,'secretAccessKey':_0x33c58d,'region':_0x185e5f});_0x2d877d['listBuckets']({},function(_0x419380,_0x17e541){if(_0x419380){return _0xc5285d(_0x419380);}else{return _0x1a5bce(_0x17e541);}});});}function createBucket(_0x19d715,_0x10722e,_0x1ffc68,_0x30ac48){return new Promise(function(_0x1acd3a,_0x22cc3c){var _0x5a5c96=new AWS['S3']({'accessKeyId':_0x10722e,'secretAccessKey':_0x19d715,'region':_0x1ffc68});_0x5a5c96['createBucket']({'Bucket':_0x30ac48},function(_0x571bbb,_0x14ae73){if(_0x571bbb){return _0x22cc3c(_0x571bbb);}else{return _0x1acd3a(_0x14ae73);}});});}function uploadFile(_0x518855,_0x19b723,_0x1e212b,_0x43f9a4,_0x24a6f6,_0x3699a4){return new Promise(function(_0x6dd270,_0x4b6843){var _0x44603a=new AWS['S3']({'accessKeyId':_0x19b723,'secretAccessKey':_0x518855,'region':_0x1e212b});_0x44603a[_0xab5f('0x72')]({'Bucket':_0x43f9a4,'Key':_0x24a6f6,'Body':_0x3699a4},function(_0x3cf8a5,_0x4c7ae2){if(_0x3cf8a5){return _0x4b6843(_0x3cf8a5);}else{return _0x6dd270(_0x4c7ae2);}});});}function startTranscribe(_0x2c4fab,_0x265d9a,_0x440b27,_0x2a6a19,_0x2c5a90,_0x127382){return new Promise(function(_0x3ffab7,_0x5d38a8){var _0x3128fd=new AWS[(_0xab5f('0x73'))]({'accessKeyId':_0x265d9a,'secretAccessKey':_0x2c4fab,'region':_0x440b27});_0x3128fd[_0xab5f('0x74')]({'TranscriptionJobName':_0x2a6a19,'LanguageCode':_0x2c5a90,'Media':{'MediaFileUri':_0x127382}},function(_0x281783,_0x37aac3){if(_0x281783){return _0x5d38a8(_0x281783);}else{return _0x3ffab7(_0x37aac3);}});});}function transcribe(_0x2e7ed0,_0x1ea5db,_0x2c3056,_0x1c0966,_0x4058bd,_0x2a2370,_0xa2a2bc){return new Promise(function(_0x4d663d,_0x359f8f){var _0x3816ba={};logger['info'](util[_0xab5f('0x52')](_0xab5f('0x75'),_0x2e7ed0,_0x4058bd));return uploadFile(_0x1ea5db,_0x2c3056,_0x1c0966,_0x4058bd,path[_0xab5f('0x76')](_0x2a2370),fs[_0xab5f('0x77')](_0x2a2370))[_0xab5f('0x2a')](function(_0x72af17){logger['info'](util[_0xab5f('0x52')](_0xab5f('0x78'),_0x2e7ed0,_0x4058bd,_0x72af17['Location']));_0x3816ba[_0xab5f('0x79')]=_0x72af17[_0xab5f('0x7a')];_0x3816ba[_0xab5f('0x7b')]=_0x72af17[_0xab5f('0x7c')];logger['info'](util[_0xab5f('0x52')](_0xab5f('0x7d'),_0x2e7ed0));return startTranscribe(_0x1ea5db,_0x2c3056,_0x1c0966,uuidv4(),_0xa2a2bc,_0x72af17['Location']);})[_0xab5f('0x2a')](function(_0x5e4ac3){logger['info'](util[_0xab5f('0x52')]('[RUNTRANSCRIPT][%d]\x20Transcription\x20job\x20%s\x20created',_0x2e7ed0,_0x5e4ac3[_0xab5f('0x7e')][_0xab5f('0x7f')]));_0x3816ba[_0xab5f('0x80')]=_0x5e4ac3[_0xab5f('0x7e')][_0xab5f('0x7f')];_0x3816ba[_0xab5f('0x81')]=_0x5e4ac3[_0xab5f('0x7e')][_0xab5f('0x82')];return _0x4d663d(_0x3816ba);})[_0xab5f('0x48')](function(_0x274d75){return _0x359f8f(_0x274d75);});});}exports[_0xab5f('0x83')]=function(_0x25255a,_0x40c69f,_0x5770a9){var _0x1cd0d3;var _0x530d06;var _0x3e3328;var _0x22e26b=require(_0xab5f('0x63'));return db['VoiceRecording'][_0xab5f('0x84')]({'where':{'id':_0x25255a[_0xab5f('0x4e')]['id']}})['then'](function(_0x323177){if(_0x323177){var _0x3208d0=util[_0xab5f('0x52')](_0xab5f('0x53'),_0x323177[_0xab5f('0x51')]);if(fs['existsSync'](_0x3208d0)){cypher=!![];return _0x22e26b[_0xab5f('0x54')](_0x3208d0,_0x323177['value'],config[_0xab5f('0x55')][_0xab5f('0x56')])[_0xab5f('0x2a')](function(){return _0x323177;});}return _0x323177;}})[_0xab5f('0x2a')](function(_0xf4bea0){if(!_0xf4bea0){throw new db[(_0xab5f('0x58'))][(_0xab5f('0x59'))](_0xab5f('0x85'));}_0x530d06=_0xf4bea0;return db[_0xab5f('0x86')][_0xab5f('0x84')]({'where':{'id':0x1}});})[_0xab5f('0x2a')](handleEntityNotFound(_0x40c69f,null))['then'](function(_0x2927eb){if(_0x2927eb){_0x1cd0d3=_0x2927eb;if(!_0x1cd0d3[_0xab5f('0x87')]||!_0x1cd0d3[_0xab5f('0x88')]||!_0x1cd0d3[_0xab5f('0x89')]||!_0x1cd0d3['language']||!_0x1cd0d3[_0xab5f('0x79')]){throw new db['Sequelize'][(_0xab5f('0x59'))](_0xab5f('0x8a'));}if(_0x25255a[_0xab5f('0x4d')][_0xab5f('0x8b')]&&(!_0x1cd0d3[_0xab5f('0x8c')]||!_0x1cd0d3[_0xab5f('0x8d')]||!_0x1cd0d3[_0xab5f('0x8e')]||!_0x1cd0d3[_0xab5f('0x8f')]||!_0x1cd0d3['bucket'])){throw new db['Sequelize'][(_0xab5f('0x59'))](_0xab5f('0x90'));}return db[_0xab5f('0x91')][_0xab5f('0x84')]({'where':{'id':_0x1cd0d3['transcribeAccountId']}});}})['then'](function(_0x32542b){if(!_0x32542b){throw new db[(_0xab5f('0x58'))][(_0xab5f('0x59'))](_0xab5f('0x92'));}if(!_0x32542b[_0xab5f('0x93')]||!_0x32542b[_0xab5f('0x94')]){throw new db[(_0xab5f('0x58'))]['ValidationError'](_0xab5f('0x95'));}_0x3e3328=_0x32542b;return getBucketslist(_0x3e3328[_0xab5f('0x93')],_0x3e3328[_0xab5f('0x94')],_0x1cd0d3['transcribeRegion']);})['then'](function(_0x9223b2){if(_0x9223b2&&_0x9223b2['Buckets']){var _0x40a04b=_[_0xab5f('0x4b')](_0x9223b2[_0xab5f('0x96')],function(_0x1bdca3){return _0x1bdca3[_0xab5f('0x97')]===_0x1cd0d3[_0xab5f('0x79')];});if(!_0x40a04b){logger[_0xab5f('0x6c')](util[_0xab5f('0x52')]('[RUNTRANSCRIPT][%d]\x20Bucket\x20%s\x20not\x20available',_0x25255a['params']['id'],_0x1cd0d3[_0xab5f('0x79')]));return createBucket(_0x3e3328[_0xab5f('0x93')],_0x3e3328[_0xab5f('0x94')],_0x1cd0d3[_0xab5f('0x89')],_0x1cd0d3['bucket']);}logger['info'](util[_0xab5f('0x52')](_0xab5f('0x98'),_0x25255a['params']['id'],_0x1cd0d3[_0xab5f('0x79')]));return;}})['then'](function(_0x24c2c2){if(_0x530d06[_0xab5f('0x81')]==='NEW'){return transcribe(_0x25255a[_0xab5f('0x4e')]['id'],_0x3e3328[_0xab5f('0x93')],_0x3e3328[_0xab5f('0x94')],_0x1cd0d3['transcribeRegion'],_0x1cd0d3[_0xab5f('0x79')],_0x530d06[_0xab5f('0x51')],_0x1cd0d3['language']);}else{logger[_0xab5f('0x6c')](util[_0xab5f('0x52')](_0xab5f('0x99'),_0x25255a[_0xab5f('0x4e')]['id']));return{'transcribeStatus':_0xab5f('0x9a')};}})[_0xab5f('0x2a')](function(_0x2bf85){if(_0x2bf85){_0x2bf85['tempSentiment']=_0x25255a[_0xab5f('0x4d')][_0xab5f('0x8b')];return _0x530d06[_0xab5f('0x9b')](_0x2bf85);}})[_0xab5f('0x2a')](respondWithResult(_0x40c69f,null))[_0xab5f('0x48')](handleError(_0x40c69f,null));};function writeFile(_0x2fc40b,_0x97657e){return new Promise(function(_0x45b5b5,_0x1bc8ec){fs['writeFile'](_0x97657e,_0x2fc40b,function(_0x2df457,_0xe92a9c){if(_0x2df457){return _0x1bc8ec(_0x2df457);}else{return _0x45b5b5(_0xe92a9c);}});});}exports[_0xab5f('0x9c')]=function(_0x161252,_0x492c68,_0x390108){return db[_0xab5f('0x44')]['findOne']({'where':{'id':_0x161252[_0xab5f('0x4e')]['id']}})[_0xab5f('0x2a')](handleEntityNotFound(_0x492c68))[_0xab5f('0x2a')](function(_0x3c196e){if(_0x3c196e&&_0x3c196e['fileText']){var _0x2efbec=_0x3c196e[_0xab5f('0x9d')];var _0x6a5d96=config[_0xab5f('0x9e')]+_0xab5f('0x9f')+_0x3c196e['id']+'.txt';if(fs[_0xab5f('0x57')](_0x6a5d96)){return _0x6a5d96;}return writeFile(_0x2efbec,_0x6a5d96)[_0xab5f('0x2a')](function(){return _0x6a5d96;});}else{throw new db[(_0xab5f('0x58'))][(_0xab5f('0x59'))](_0xab5f('0xa0'));}})[_0xab5f('0x2a')](function(_0x2867ee){return _0x492c68[_0xab5f('0x5c')](_0x2867ee);})['catch'](handleError(_0x492c68));};