Built motion from commit (unavailable).|2.5.1
[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 _0x53f7=['zip-dir','fast-json-patch','request-promise','bluebird','mustache','util','sox','to-csv','lodash','squel','crypto','jsforce','querystring','papaparse','aws-sdk','uuid/v4','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/logger','api','../../config/utils','../../config/environment','../../config/license/util','sendStatus','status','end','json','count','offset','limit','set','Content-Range','reject','save','update','then','stack','name','send','rawAttributes','fieldName','type','model','query','keys','filters','intersection','attributes','fields','length','hasOwnProperty','order','sort','where','pick','filter','VIRTUAL','merge','VoiceRecording','includeAll','include','findAll','catch','params','options','body','find','describe','uniqueid','value','%s.cypher','existsSync','decryptFile','secrets','recording','Sequelize','ValidationError','download','filename','extname','unlink','VoiceRecording\x20not\x20found','../../components/encryptor','sequelize','MD5','col','token','push','$and','format','destroy','Entity\x20not\x20found','info','cancellazione\x20fisica\x20documento\x20%s','isNil','File:\x20\x22','\x22\x20trovato\x20eseguo\x20la\x20cancellazione','.cypher','unlinkSync','listBuckets','createBucket','upload','TranscribeService','startTranscriptionJob','[RUNTRANSCRIPT][%d]\x20Starting\x20voice\x20recording\x20upload\x20in\x20bucket\x20%s','readFileSync','Location','bucket','location','[RUNTRANSCRIPT][%d]\x20Transcription\x20job\x20%s\x20created','TranscriptionJobName','transcribeName','TranscriptionJob','transcribeStatus','TranscriptionJobStatus','runTranscribe','findOne','Voice\x20Recording\x20not\x20found','Setting','transcribeAccountId','language','Transcribe\x20not\x20configured','runSentiment','sentiment','sentimentAccountId','sentimentRegion','Sentiment\x20Analysis\x20not\x20configured','CloudProvider','data1','data2','transcribeRegion','Buckets','Name','[RUNTRANSCRIPT][%d]\x20Bucket\x20%s\x20available','NEW','[RUNTRANSCRIPT][%d]\x20Transcript\x20action\x20already\x20requested','tempSentiment','updateAttributes','writeFile','downloadTranscribe','fileText','root','.txt','Transcript\x20not\x20available','html-pdf','rimraf'];(function(_0xf0adf6,_0x40bdee){var _0x567134=function(_0x510c2c){while(--_0x510c2c){_0xf0adf6['push'](_0xf0adf6['shift']());}};_0x567134(++_0x40bdee);}(_0x53f7,0x126));var _0x753f=function(_0x26d51f,_0x1de895){_0x26d51f=_0x26d51f-0x0;var _0x48305d=_0x53f7[_0x26d51f];return _0x48305d;};'use strict';var pdf=require(_0x753f('0x0'));var emlformat=require('eml-format');var rimraf=require(_0x753f('0x1'));var zipdir=require(_0x753f('0x2'));var jsonpatch=require(_0x753f('0x3'));var rp=require(_0x753f('0x4'));var moment=require('moment');var BPromise=require(_0x753f('0x5'));var Mustache=require(_0x753f('0x6'));var util=require(_0x753f('0x7'));var path=require('path');var sox=require(_0x753f('0x8'));var csv=require(_0x753f('0x9'));var ejs=require('ejs');var fs=require('fs');var _=require(_0x753f('0xa'));var squel=require(_0x753f('0xb'));var crypto=require(_0x753f('0xc'));var jsforce=require(_0x753f('0xd'));var deskjs=require('desk.js');var toCsv=require(_0x753f('0x9'));var querystring=require(_0x753f('0xe'));var Papa=require(_0x753f('0xf'));var AWS=require(_0x753f('0x10'));var uuidv4=require(_0x753f('0x11'));var Redis=require(_0x753f('0x12'));var authService=require(_0x753f('0x13'));var qs=require(_0x753f('0x14'));var as=require(_0x753f('0x15'));var hardwareService=require('../../config/license/hardware');var logger=require(_0x753f('0x16'))(_0x753f('0x17'));var utils=require(_0x753f('0x18'));var config=require(_0x753f('0x19'));var licenseUtil=require(_0x753f('0x1a'));var db=require('../../mysqldb')['db'];function respondWithStatusCode(_0x257f09,_0x49b351){_0x49b351=_0x49b351||0xcc;return function(_0x11883c){if(_0x11883c){return _0x257f09[_0x753f('0x1b')](_0x49b351);}return _0x257f09[_0x753f('0x1c')](_0x49b351)[_0x753f('0x1d')]();};}function respondWithResult(_0xe091d7,_0x516e0a){_0x516e0a=_0x516e0a||0xc8;return function(_0x36f8f9){if(_0x36f8f9){return _0xe091d7[_0x753f('0x1c')](_0x516e0a)[_0x753f('0x1e')](_0x36f8f9);}};}function respondWithFilteredResult(_0x3e4187,_0x1ed5e0){return function(_0x5d0be8){if(_0x5d0be8){var _0x262604=_0x5d0be8[_0x753f('0x1f')],_0x340f22=_0x1ed5e0[_0x753f('0x20')],_0x441940=_0x1ed5e0[_0x753f('0x20')]+_0x1ed5e0[_0x753f('0x21')],_0x589783;if(_0x441940>=_0x262604){_0x441940=_0x262604;_0x589783=0xc8;}else{_0x589783=0xce;}_0x3e4187[_0x753f('0x1c')](_0x589783);return _0x3e4187[_0x753f('0x22')](_0x753f('0x23'),_0x340f22+'-'+_0x441940+'/'+_0x262604)[_0x753f('0x1e')](_0x5d0be8);}return null;};}function patchUpdates(_0x5752f2){return function(_0x227b1b){try{jsonpatch['apply'](_0x227b1b,_0x5752f2,!![]);}catch(_0x4c5dfd){return BPromise[_0x753f('0x24')](_0x4c5dfd);}return _0x227b1b[_0x753f('0x25')]();};}function saveUpdates(_0x17fb76,_0x582337){return function(_0x52c731){if(_0x52c731){return _0x52c731[_0x753f('0x26')](_0x17fb76)[_0x753f('0x27')](function(_0x36c46c){return _0x36c46c;});}return null;};}function removeEntity(_0x19e57,_0xbc3e81){return function(_0x42249c){if(_0x42249c){return _0x42249c['destroy']()[_0x753f('0x27')](function(){_0x19e57['status'](0xcc)[_0x753f('0x1d')]();});}};}function handleEntityNotFound(_0x44afe7,_0x1fae4e){return function(_0x23b130){if(!_0x23b130){_0x44afe7[_0x753f('0x1b')](0x194);}return _0x23b130;};}function handleError(_0x228f7a,_0x146709){_0x146709=_0x146709||0x1f4;return function(_0x4de458){logger['error'](_0x4de458[_0x753f('0x28')]);if(_0x4de458[_0x753f('0x29')]){delete _0x4de458[_0x753f('0x29')];}_0x228f7a['status'](_0x146709)[_0x753f('0x2a')](_0x4de458);};}exports['index']=function(_0x3e9ef9,_0x2a5be7){var _0x154068={},_0x333a70={},_0x5be59c={'count':0x0,'rows':[]};var _0x32acb2=_['map'](db['VoiceRecording'][_0x753f('0x2b')],function(_0x31895d){return{'name':_0x31895d[_0x753f('0x2c')],'type':_0x31895d[_0x753f('0x2d')]['key']};});_0x333a70[_0x753f('0x2e')]=_['differenceBy'](_['map'](_0x32acb2,_0x753f('0x29')),['format']);_0x333a70[_0x753f('0x2f')]=_[_0x753f('0x30')](_0x3e9ef9[_0x753f('0x2f')]);_0x333a70[_0x753f('0x31')]=_[_0x753f('0x32')](_0x333a70[_0x753f('0x2e')],_0x333a70[_0x753f('0x2f')]);_0x154068[_0x753f('0x33')]=_['intersection'](_0x333a70[_0x753f('0x2e')],qs[_0x753f('0x34')](_0x3e9ef9[_0x753f('0x2f')][_0x753f('0x34')]));_0x154068[_0x753f('0x33')]=_0x154068[_0x753f('0x33')][_0x753f('0x35')]?_0x154068[_0x753f('0x33')]:_0x333a70[_0x753f('0x2e')];if(!_0x3e9ef9[_0x753f('0x2f')][_0x753f('0x36')]('nolimit')){_0x154068[_0x753f('0x21')]=qs['limit'](_0x3e9ef9[_0x753f('0x2f')][_0x753f('0x21')]);_0x154068[_0x753f('0x20')]=qs['offset'](_0x3e9ef9[_0x753f('0x2f')][_0x753f('0x20')]);}_0x154068[_0x753f('0x37')]=qs[_0x753f('0x38')](_0x3e9ef9['query'][_0x753f('0x38')]);_0x154068[_0x753f('0x39')]=qs[_0x753f('0x31')](_[_0x753f('0x3a')](_0x3e9ef9['query'],_0x333a70[_0x753f('0x31')]),_0x32acb2);if(_0x3e9ef9['query'][_0x753f('0x3b')]){_0x154068[_0x753f('0x39')]=_['merge'](_0x154068[_0x753f('0x39')],{'$or':_['map'](_0x32acb2,function(_0xb96cfd){if(_0xb96cfd[_0x753f('0x2d')]!==_0x753f('0x3c')){var _0x41a049={};_0x41a049[_0xb96cfd[_0x753f('0x29')]]={'$like':'%'+_0x3e9ef9['query'][_0x753f('0x3b')]+'%'};return _0x41a049;}})});}_0x154068=_[_0x753f('0x3d')]({},_0x154068,_0x3e9ef9['options']);var _0x557b8d={'where':_0x154068[_0x753f('0x39')]};return db[_0x753f('0x3e')][_0x753f('0x1f')](_0x557b8d)['then'](function(_0x39e9a6){_0x5be59c[_0x753f('0x1f')]=_0x39e9a6;if(_0x3e9ef9[_0x753f('0x2f')][_0x753f('0x3f')]){_0x154068[_0x753f('0x40')]=[{'all':!![]}];}return db[_0x753f('0x3e')][_0x753f('0x41')](_0x154068);})[_0x753f('0x27')](function(_0x24c650){_0x5be59c['rows']=_0x24c650;return _0x5be59c;})[_0x753f('0x27')](respondWithFilteredResult(_0x2a5be7,_0x154068))[_0x753f('0x42')](handleError(_0x2a5be7,null));};exports['show']=function(_0x210db7,_0x46a5b7){var _0x47a6c9={'raw':![],'where':{'id':_0x210db7[_0x753f('0x43')]['id']}},_0x19d73a={};_0x19d73a[_0x753f('0x2e')]=_[_0x753f('0x30')](db['VoiceRecording'][_0x753f('0x2b')]);_0x19d73a[_0x753f('0x2f')]=_[_0x753f('0x30')](_0x210db7[_0x753f('0x2f')]);_0x19d73a['filters']=_['intersection'](_0x19d73a[_0x753f('0x2e')],_0x19d73a[_0x753f('0x2f')]);_0x47a6c9[_0x753f('0x33')]=_[_0x753f('0x32')](_0x19d73a[_0x753f('0x2e')],qs[_0x753f('0x34')](_0x210db7[_0x753f('0x2f')][_0x753f('0x34')]));_0x47a6c9[_0x753f('0x33')]=_0x47a6c9[_0x753f('0x33')]['length']?_0x47a6c9[_0x753f('0x33')]:_0x19d73a[_0x753f('0x2e')];if(_0x210db7[_0x753f('0x2f')]['includeAll']){_0x47a6c9[_0x753f('0x40')]=[{'all':!![]}];}_0x47a6c9=_[_0x753f('0x3d')]({},_0x47a6c9,_0x210db7[_0x753f('0x44')]);return db[_0x753f('0x3e')]['find'](_0x47a6c9)[_0x753f('0x27')](handleEntityNotFound(_0x46a5b7,null))[_0x753f('0x27')](respondWithResult(_0x46a5b7,null))[_0x753f('0x42')](handleError(_0x46a5b7,null));};exports['create']=function(_0x6328bd,_0x2ae022){return db['VoiceRecording']['create'](_0x6328bd[_0x753f('0x45')],{})[_0x753f('0x27')](respondWithResult(_0x2ae022,0xc9))['catch'](handleError(_0x2ae022,null));};exports[_0x753f('0x26')]=function(_0x3a944d,_0x5b24a3){if(_0x3a944d[_0x753f('0x45')]['id']){delete _0x3a944d[_0x753f('0x45')]['id'];}return db[_0x753f('0x3e')][_0x753f('0x46')]({'where':{'id':_0x3a944d[_0x753f('0x43')]['id']}})[_0x753f('0x27')](handleEntityNotFound(_0x5b24a3,null))[_0x753f('0x27')](saveUpdates(_0x3a944d[_0x753f('0x45')],null))[_0x753f('0x27')](respondWithResult(_0x5b24a3,null))[_0x753f('0x42')](handleError(_0x5b24a3,null));};exports[_0x753f('0x47')]=function(_0x1b839e,_0x44e2b3){return db['VoiceRecording'][_0x753f('0x47')]()[_0x753f('0x27')](respondWithResult(_0x44e2b3,null))['catch'](handleError(_0x44e2b3,null));};exports['download']=function(_0xaddf01,_0x2f58d6,_0x8a178f){var _0x285d36=require('../../components/encryptor');var _0x5bb120=![];var _0x3e4680={};if(_0xaddf01[_0x753f('0x2f')]['type']&&_0xaddf01[_0x753f('0x2f')][_0x753f('0x2d')]===_0x753f('0x48')){_0x3e4680[_0x753f('0x48')]=_0xaddf01[_0x753f('0x43')]['id'];}else{_0x3e4680['id']=_0xaddf01['params']['id'];}return db[_0x753f('0x3e')][_0x753f('0x46')]({'where':_0x3e4680,'attributes':['id',_0x753f('0x49')],'raw':!![]})[_0x753f('0x27')](handleEntityNotFound(_0x2f58d6,null))[_0x753f('0x27')](function(_0x38c6b7){if(_0x38c6b7){var _0xc94220=_0x38c6b7['value'];var _0x39226a=util['format'](_0x753f('0x4a'),_0xc94220);if(fs[_0x753f('0x4b')](_0x39226a)){_0x5bb120=!![];return _0x285d36[_0x753f('0x4c')](_0x39226a,_0xc94220,config[_0x753f('0x4d')][_0x753f('0x4e')])[_0x753f('0x27')](function(){return _0x38c6b7;});}return _0x38c6b7;}})['then'](function(_0x2014c7){if(_0x2014c7){var _0x583e4f=_0x2014c7[_0x753f('0x49')];if(!fs[_0x753f('0x4b')](_0x583e4f)){throw new db[(_0x753f('0x4f'))][(_0x753f('0x50'))]('VoiceRecording\x20not\x20found');}if(_0x2014c7['filename']){return _0x2f58d6[_0x753f('0x51')](_0x583e4f,_0x2014c7[_0x753f('0x52')]+path[_0x753f('0x53')](_0x583e4f),function(){if(_0x5bb120){fs[_0x753f('0x54')](_0x583e4f);}});}else{return _0x2f58d6[_0x753f('0x51')](_0x583e4f,function(_0x30cae2){if(_0x5bb120){fs[_0x753f('0x54')](_0x583e4f);}});}}})[_0x753f('0x42')](function(_0x47622c){if(_0x47622c['message']===_0x753f('0x55')){_0x2f58d6[_0x753f('0x1c')](0x194)['send']('Not\x20found');}else{return handleError(_0x2f58d6,null);}});};exports['downloads']=function(_0x50bb8b,_0xb4202c,_0x63dba){var _0x1f2fcf=require(_0x753f('0x56'));var _0x310553=![];var _0x122df3={'$and':[db[_0x753f('0x57')][_0x753f('0x39')](db[_0x753f('0x57')]['fn'](_0x753f('0x58'),db['sequelize'][_0x753f('0x59')]('uniqueid')),_0x50bb8b[_0x753f('0x2f')][_0x753f('0x5a')])]};if(_0x50bb8b[_0x753f('0x2f')]['type']&&_0x50bb8b[_0x753f('0x2f')][_0x753f('0x2d')]===_0x753f('0x48')){_0x122df3['$and'][_0x753f('0x5b')]({'uniqueid':_0x50bb8b['params']['id']});}else{_0x122df3[_0x753f('0x5c')][_0x753f('0x5b')]({'id':_0x50bb8b['params']['id']});}return db[_0x753f('0x3e')][_0x753f('0x46')]({'where':_0x122df3,'attributes':['id',_0x753f('0x49')],'raw':!![]})[_0x753f('0x27')](handleEntityNotFound(_0xb4202c,null))[_0x753f('0x27')](function(_0x2f5a3f){if(_0x2f5a3f){var _0x3bc97d=util[_0x753f('0x5d')](_0x753f('0x4a'),_0x2f5a3f[_0x753f('0x49')]);if(fs[_0x753f('0x4b')](_0x3bc97d)){_0x310553=!![];return _0x1f2fcf[_0x753f('0x4c')](_0x3bc97d,_0x2f5a3f[_0x753f('0x49')],config['secrets'][_0x753f('0x4e')])[_0x753f('0x27')](function(){return _0x2f5a3f;});}return _0x2f5a3f;}})[_0x753f('0x27')](function(_0x16f279){if(_0x16f279){if(!fs[_0x753f('0x4b')](_0x16f279[_0x753f('0x49')])){throw new db['Sequelize'][(_0x753f('0x50'))](_0x753f('0x55'));}if(_0x16f279['filename']){return _0xb4202c['download'](_0x16f279[_0x753f('0x49')],_0x16f279[_0x753f('0x52')]+path[_0x753f('0x53')](_0x16f279[_0x753f('0x49')]),function(){if(_0x310553){fs['unlink'](_0x16f279[_0x753f('0x49')]);}});}else{return _0xb4202c[_0x753f('0x51')](_0x16f279['value'],function(_0x39f3b3){if(_0x310553){fs[_0x753f('0x54')](_0x16f279[_0x753f('0x49')]);}});}}})[_0x753f('0x42')](handleError(_0xb4202c,null));};exports[_0x753f('0x5e')]=function(_0x475e48,_0x30062e){return db[_0x753f('0x3e')]['find']({'where':{'id':_0x475e48[_0x753f('0x43')]['id']}})['then'](function(_0x1f47fa){if(!_0x1f47fa)throw new ReferenceError(_0x753f('0x5f'));return _0x1f47fa;})['then'](function(_0x3327f3){var _0x152991=_0x3327f3[_0x753f('0x49')];logger[_0x753f('0x60')](_0x753f('0x61'),_0x152991);if(!_[_0x753f('0x62')](_0x3327f3[_0x753f('0x49')])&&fs[_0x753f('0x4b')](_0x152991)){logger[_0x753f('0x60')](_0x753f('0x63')+_0x152991+_0x753f('0x64'));fs['unlinkSync'](_0x152991);}_0x152991=_0x152991+_0x753f('0x65');if(!_[_0x753f('0x62')](_0x3327f3[_0x753f('0x49')])&&fs[_0x753f('0x4b')](_0x152991)){logger[_0x753f('0x60')](_0x753f('0x63')+_0x152991+_0x753f('0x64'));fs[_0x753f('0x66')](_0x152991);}return _0x3327f3;})[_0x753f('0x27')](function(_0x5d60b4){if(!_0x5d60b4)throw new InternalError();return _0x5d60b4['destroy']();})[_0x753f('0x27')](function(){_0x30062e[_0x753f('0x1c')](0xcc)[_0x753f('0x1d')]();})[_0x753f('0x42')](handleError(_0x30062e,null));};function getBucketslist(_0x1e420a,_0x245805,_0x359ee0){return new Promise(function(_0x24f8bd,_0x83dd68){var _0x2c21c4=new AWS['S3']({'accessKeyId':_0x245805,'secretAccessKey':_0x1e420a,'region':_0x359ee0});_0x2c21c4[_0x753f('0x67')]({},function(_0x50b600,_0x5c3a03){if(_0x50b600){return _0x83dd68(_0x50b600);}else{return _0x24f8bd(_0x5c3a03);}});});}function createBucket(_0x905140,_0xdb938,_0x405110,_0x4a7c2e){return new Promise(function(_0x7309d,_0x496ecd){var _0x33faad=new AWS['S3']({'accessKeyId':_0xdb938,'secretAccessKey':_0x905140,'region':_0x405110});_0x33faad[_0x753f('0x68')]({'Bucket':_0x4a7c2e},function(_0x381f98,_0x5aded1){if(_0x381f98){return _0x496ecd(_0x381f98);}else{return _0x7309d(_0x5aded1);}});});}function uploadFile(_0x519669,_0x36878c,_0x163ecd,_0x4b5e9e,_0x12bbf8,_0x99de87){return new Promise(function(_0xdb969e,_0x469a7c){var _0x5deda3=new AWS['S3']({'accessKeyId':_0x36878c,'secretAccessKey':_0x519669,'region':_0x163ecd});_0x5deda3[_0x753f('0x69')]({'Bucket':_0x4b5e9e,'Key':_0x12bbf8,'Body':_0x99de87},function(_0x273848,_0xdae0b4){if(_0x273848){return _0x469a7c(_0x273848);}else{return _0xdb969e(_0xdae0b4);}});});}function startTranscribe(_0x536580,_0x1b535c,_0x296335,_0x3be97f,_0x322ded,_0x3fc653){return new Promise(function(_0x5733a9,_0x277143){var _0x5ec237=new AWS[(_0x753f('0x6a'))]({'accessKeyId':_0x1b535c,'secretAccessKey':_0x536580,'region':_0x296335});_0x5ec237[_0x753f('0x6b')]({'TranscriptionJobName':_0x3be97f,'LanguageCode':_0x322ded,'Media':{'MediaFileUri':_0x3fc653}},function(_0x357cfc,_0x2ab33d){if(_0x357cfc){return _0x277143(_0x357cfc);}else{return _0x5733a9(_0x2ab33d);}});});}function transcribe(_0x463ab0,_0x10ded9,_0x46a926,_0x38f8a5,_0xaa7dd,_0x5497a9,_0x3749b2){return new Promise(function(_0x235d1b,_0xf9a931){var _0x40d646={};logger['info'](util['format'](_0x753f('0x6c'),_0x463ab0,_0xaa7dd));return uploadFile(_0x10ded9,_0x46a926,_0x38f8a5,_0xaa7dd,path['basename'](_0x5497a9),fs[_0x753f('0x6d')](_0x5497a9))[_0x753f('0x27')](function(_0x65929c){logger[_0x753f('0x60')](util['format']('[RUNTRANSCRIPT][%d]\x20Voice\x20recording\x20uploaded\x20in\x20bucket\x20%s\x20(%s)',_0x463ab0,_0xaa7dd,_0x65929c[_0x753f('0x6e')]));_0x40d646[_0x753f('0x6f')]=_0x65929c['Bucket'];_0x40d646[_0x753f('0x70')]=_0x65929c['Location'];logger['info'](util[_0x753f('0x5d')]('[RUNTRANSCRIPT][%d]\x20Sending\x20transcribe\x20request',_0x463ab0));return startTranscribe(_0x10ded9,_0x46a926,_0x38f8a5,uuidv4(),_0x3749b2,_0x65929c[_0x753f('0x6e')]);})[_0x753f('0x27')](function(_0x44a44d){logger[_0x753f('0x60')](util['format'](_0x753f('0x71'),_0x463ab0,_0x44a44d['TranscriptionJob'][_0x753f('0x72')]));_0x40d646[_0x753f('0x73')]=_0x44a44d[_0x753f('0x74')]['TranscriptionJobName'];_0x40d646[_0x753f('0x75')]=_0x44a44d[_0x753f('0x74')][_0x753f('0x76')];return _0x235d1b(_0x40d646);})[_0x753f('0x42')](function(_0x489145){return _0xf9a931(_0x489145);});});}exports[_0x753f('0x77')]=function(_0x46f086,_0x20a94f,_0x57a645){var _0x6c81ab;var _0x3b0221;var _0x13081f;var _0x1ca36e=require(_0x753f('0x56'));return db[_0x753f('0x3e')][_0x753f('0x78')]({'where':{'id':_0x46f086[_0x753f('0x43')]['id']}})[_0x753f('0x27')](function(_0x3c5e4f){if(_0x3c5e4f){var _0xb23d63=util[_0x753f('0x5d')](_0x753f('0x4a'),_0x3c5e4f[_0x753f('0x49')]);if(fs['existsSync'](_0xb23d63)){cypher=!![];return _0x1ca36e[_0x753f('0x4c')](_0xb23d63,_0x3c5e4f[_0x753f('0x49')],config[_0x753f('0x4d')][_0x753f('0x4e')])[_0x753f('0x27')](function(){return _0x3c5e4f;});}return _0x3c5e4f;}})[_0x753f('0x27')](function(_0x59a33e){if(!_0x59a33e){throw new db['Sequelize'][(_0x753f('0x50'))](_0x753f('0x79'));}_0x3b0221=_0x59a33e;return db[_0x753f('0x7a')][_0x753f('0x78')]({'where':{'id':0x1}});})[_0x753f('0x27')](handleEntityNotFound(_0x20a94f,null))[_0x753f('0x27')](function(_0x116df2){if(_0x116df2){_0x6c81ab=_0x116df2;if(!_0x6c81ab['transcribe']||!_0x6c81ab[_0x753f('0x7b')]||!_0x6c81ab['transcribeRegion']||!_0x6c81ab[_0x753f('0x7c')]||!_0x6c81ab['bucket']){throw new db[(_0x753f('0x4f'))][(_0x753f('0x50'))](_0x753f('0x7d'));}if(_0x46f086['body'][_0x753f('0x7e')]&&(!_0x6c81ab[_0x753f('0x7f')]||!_0x6c81ab[_0x753f('0x80')]||!_0x6c81ab[_0x753f('0x81')]||!_0x6c81ab[_0x753f('0x7c')]||!_0x6c81ab[_0x753f('0x6f')])){throw new db[(_0x753f('0x4f'))][(_0x753f('0x50'))](_0x753f('0x82'));}return db[_0x753f('0x83')]['findOne']({'where':{'id':_0x6c81ab['transcribeAccountId']}});}})[_0x753f('0x27')](function(_0xcfae09){if(!_0xcfae09){throw new db[(_0x753f('0x4f'))]['ValidationError']('Cloud\x20Provider\x20not\x20available');}if(!_0xcfae09[_0x753f('0x84')]||!_0xcfae09[_0x753f('0x85')]){throw new db[(_0x753f('0x4f'))][(_0x753f('0x50'))]('Cloud\x20Provider\x20not\x20configured');}_0x13081f=_0xcfae09;return getBucketslist(_0x13081f[_0x753f('0x84')],_0x13081f[_0x753f('0x85')],_0x6c81ab[_0x753f('0x86')]);})[_0x753f('0x27')](function(_0x31ea53){if(_0x31ea53&&_0x31ea53[_0x753f('0x87')]){var _0x5e9c85=_[_0x753f('0x46')](_0x31ea53[_0x753f('0x87')],function(_0x34649d){return _0x34649d[_0x753f('0x88')]===_0x6c81ab['bucket'];});if(!_0x5e9c85){logger[_0x753f('0x60')](util[_0x753f('0x5d')]('[RUNTRANSCRIPT][%d]\x20Bucket\x20%s\x20not\x20available',_0x46f086[_0x753f('0x43')]['id'],_0x6c81ab['bucket']));return createBucket(_0x13081f[_0x753f('0x84')],_0x13081f[_0x753f('0x85')],_0x6c81ab[_0x753f('0x86')],_0x6c81ab[_0x753f('0x6f')]);}logger[_0x753f('0x60')](util[_0x753f('0x5d')](_0x753f('0x89'),_0x46f086[_0x753f('0x43')]['id'],_0x6c81ab[_0x753f('0x6f')]));return;}})[_0x753f('0x27')](function(_0x13376a){if(_0x3b0221['transcribeStatus']===_0x753f('0x8a')){return transcribe(_0x46f086[_0x753f('0x43')]['id'],_0x13081f[_0x753f('0x84')],_0x13081f[_0x753f('0x85')],_0x6c81ab[_0x753f('0x86')],_0x6c81ab[_0x753f('0x6f')],_0x3b0221[_0x753f('0x49')],_0x6c81ab[_0x753f('0x7c')]);}else{logger[_0x753f('0x60')](util[_0x753f('0x5d')](_0x753f('0x8b'),_0x46f086['params']['id']));return{'transcribeStatus':'IN_PROGRESS'};}})[_0x753f('0x27')](function(_0xcc01aa){if(_0xcc01aa){_0xcc01aa[_0x753f('0x8c')]=_0x46f086[_0x753f('0x45')][_0x753f('0x7e')];return _0x3b0221[_0x753f('0x8d')](_0xcc01aa);}})[_0x753f('0x27')](respondWithResult(_0x20a94f,null))['catch'](handleError(_0x20a94f,null));};function writeFile(_0x4a820d,_0x380bd5){return new Promise(function(_0x741357,_0x4e5367){fs[_0x753f('0x8e')](_0x380bd5,_0x4a820d,function(_0x1161d2,_0x37a15c){if(_0x1161d2){return _0x4e5367(_0x1161d2);}else{return _0x741357(_0x37a15c);}});});}exports[_0x753f('0x8f')]=function(_0x1b08a4,_0x28d08d,_0x481de4){return db[_0x753f('0x3e')][_0x753f('0x78')]({'where':{'id':_0x1b08a4[_0x753f('0x43')]['id']}})[_0x753f('0x27')](handleEntityNotFound(_0x28d08d))[_0x753f('0x27')](function(_0x3bd440){if(_0x3bd440&&_0x3bd440[_0x753f('0x90')]){var _0x186d4e=_0x3bd440['fileText'];var _0x4ac370=config[_0x753f('0x91')]+'/server/files/transcribes/transcribe_'+_0x3bd440['id']+_0x753f('0x92');if(fs[_0x753f('0x4b')](_0x4ac370)){return _0x4ac370;}return writeFile(_0x186d4e,_0x4ac370)['then'](function(){return _0x4ac370;});}else{throw new db[(_0x753f('0x4f'))][(_0x753f('0x50'))](_0x753f('0x93'));}})[_0x753f('0x27')](function(_0x3f6468){return _0x28d08d[_0x753f('0x51')](_0x3f6468);})[_0x753f('0x42')](handleError(_0x28d08d));};