d9a78d02d5363af105d66aa31b645c59397ed0c1
[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 _0xbf47=['[RUNTRANSCRIPT][%d]\x20Transcript\x20action\x20already\x20requested','IN_PROGRESS','updateAttributes','downloadTranscribe','fileText','.txt','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','mustache','util','path','sox','ejs','fs-extra','lodash','crypto','jsforce','to-csv','querystring','papaparse','aws-sdk','uuid/v4','ioredis','../../components/auth/service','../../components/parsers/qs','../../config/license/hardware','../../config/logger','api','../../config/environment','../../mysqldb','status','json','undefined','limit','count','offset','Content-Range','apply','reject','save','update','then','destroy','end','sendStatus','error','stack','name','send','index','map','VoiceRecording','rawAttributes','type','key','differenceBy','format','query','keys','filters','intersection','model','attributes','fields','hasOwnProperty','nolimit','sort','where','pick','filter','VIRTUAL','merge','options','include','findAll','rows','catch','show','params','length','includeAll','find','create','body','describe','../../components/encryptor','uniqueid','value','%s.cypher','existsSync','decryptFile','secrets','recording','Sequelize','ValidationError','filename','extname','unlink','download','message','VoiceRecording\x20not\x20found','downloads','sequelize','MD5','col','token','$and','push','isNil','info','File:\x20\x22','unlinkSync','.cypher','\x22\x20trovato\x20eseguo\x20la\x20cancellazione','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)','Location','location','[RUNTRANSCRIPT][%d]\x20Sending\x20transcribe\x20request','TranscriptionJob','TranscriptionJobName','transcribeStatus','TranscriptionJobStatus','runTranscribe','findOne','Voice\x20Recording\x20not\x20found','transcribe','transcribeRegion','language','bucket','Transcribe\x20not\x20configured','runSentiment','Sentiment\x20Analysis\x20not\x20configured','CloudProvider','transcribeAccountId','data1','data2','Cloud\x20Provider\x20not\x20configured','Buckets','Name','[RUNTRANSCRIPT][%d]\x20Bucket\x20%s\x20not\x20available'];(function(_0x1ca9b0,_0x2ce5fa){var _0x387062=function(_0x395cd1){while(--_0x395cd1){_0x1ca9b0['push'](_0x1ca9b0['shift']());}};_0x387062(++_0x2ce5fa);}(_0xbf47,0x9b));var _0x7bf4=function(_0x494191,_0x35c2d8){_0x494191=_0x494191-0x0;var _0x1594dd=_0xbf47[_0x494191];return _0x1594dd;};'use strict';var emlformat=require(_0x7bf4('0x0'));var rimraf=require(_0x7bf4('0x1'));var zipdir=require(_0x7bf4('0x2'));var jsonpatch=require(_0x7bf4('0x3'));var rp=require(_0x7bf4('0x4'));var moment=require('moment');var BPromise=require('bluebird');var Mustache=require(_0x7bf4('0x5'));var util=require(_0x7bf4('0x6'));var path=require(_0x7bf4('0x7'));var sox=require(_0x7bf4('0x8'));var csv=require('to-csv');var ejs=require(_0x7bf4('0x9'));var fs=require('fs');var fs_extra=require(_0x7bf4('0xa'));var _=require(_0x7bf4('0xb'));var squel=require('squel');var crypto=require(_0x7bf4('0xc'));var jsforce=require(_0x7bf4('0xd'));var deskjs=require('desk.js');var toCsv=require(_0x7bf4('0xe'));var querystring=require(_0x7bf4('0xf'));var Papa=require(_0x7bf4('0x10'));var AWS=require(_0x7bf4('0x11'));var uuidv4=require(_0x7bf4('0x12'));var Redis=require(_0x7bf4('0x13'));var authService=require(_0x7bf4('0x14'));var qs=require(_0x7bf4('0x15'));var as=require('../../components/parsers/advancedSearch');var hardwareService=require(_0x7bf4('0x16'));var logger=require(_0x7bf4('0x17'))(_0x7bf4('0x18'));var utils=require('../../config/utils');var config=require(_0x7bf4('0x19'));var licenseUtil=require('../../config/license/util');var db=require(_0x7bf4('0x1a'))['db'];function respondWithStatusCode(_0x2b5340,_0x314b01){_0x314b01=_0x314b01||0xcc;return function(_0x37c50e){if(_0x37c50e){return _0x2b5340['sendStatus'](_0x314b01);}return _0x2b5340[_0x7bf4('0x1b')](_0x314b01)['end']();};}function respondWithResult(_0x3be99c,_0x19a850){_0x19a850=_0x19a850||0xc8;return function(_0x2b3c18){if(_0x2b3c18){return _0x3be99c[_0x7bf4('0x1b')](_0x19a850)[_0x7bf4('0x1c')](_0x2b3c18);}};}function respondWithFilteredResult(_0x5cf3d4,_0x883c28){return function(_0x28d513){if(_0x28d513){var _0x40e56e=typeof _0x883c28['offset']===_0x7bf4('0x1d')&&typeof _0x883c28[_0x7bf4('0x1e')]===_0x7bf4('0x1d');var _0x41b02d=_0x28d513[_0x7bf4('0x1f')];var _0x21bbb4=_0x40e56e?0x0:_0x883c28[_0x7bf4('0x20')];var _0x4784e4=_0x40e56e?_0x28d513[_0x7bf4('0x1f')]:_0x883c28[_0x7bf4('0x20')]+_0x883c28[_0x7bf4('0x1e')];var _0x55eeca;if(_0x4784e4>=_0x41b02d){_0x4784e4=_0x41b02d;_0x55eeca=0xc8;}else{_0x55eeca=0xce;}_0x5cf3d4['status'](_0x55eeca);return _0x5cf3d4['set'](_0x7bf4('0x21'),_0x21bbb4+'-'+_0x4784e4+'/'+_0x41b02d)[_0x7bf4('0x1c')](_0x28d513);}return null;};}function patchUpdates(_0x265415){return function(_0x2ce4f3){try{jsonpatch[_0x7bf4('0x22')](_0x2ce4f3,_0x265415,!![]);}catch(_0x555683){return BPromise[_0x7bf4('0x23')](_0x555683);}return _0x2ce4f3[_0x7bf4('0x24')]();};}function saveUpdates(_0x43eea5,_0x1fa103){return function(_0x173716){if(_0x173716){return _0x173716[_0x7bf4('0x25')](_0x43eea5)[_0x7bf4('0x26')](function(_0xfcebf4){return _0xfcebf4;});}return null;};}function removeEntity(_0x3abd7f,_0x1f12de){return function(_0x1a9528){if(_0x1a9528){return _0x1a9528[_0x7bf4('0x27')]()['then'](function(){_0x3abd7f[_0x7bf4('0x1b')](0xcc)[_0x7bf4('0x28')]();});}};}function handleEntityNotFound(_0x3aec71,_0x27c306){return function(_0xb34d1a){if(!_0xb34d1a){_0x3aec71[_0x7bf4('0x29')](0x194);}return _0xb34d1a;};}function handleError(_0x1be557,_0x3f6d07){_0x3f6d07=_0x3f6d07||0x1f4;return function(_0x397fe3){logger[_0x7bf4('0x2a')](_0x397fe3[_0x7bf4('0x2b')]);if(_0x397fe3[_0x7bf4('0x2c')]){delete _0x397fe3[_0x7bf4('0x2c')];}_0x1be557[_0x7bf4('0x1b')](_0x3f6d07)[_0x7bf4('0x2d')](_0x397fe3);};}exports[_0x7bf4('0x2e')]=function(_0x16e0de,_0x23d9d5){var _0x29647d={},_0xf95b11={},_0x2e304a={'count':0x0,'rows':[]};var _0x3baa28=_[_0x7bf4('0x2f')](db[_0x7bf4('0x30')][_0x7bf4('0x31')],function(_0x416574){return{'name':_0x416574['fieldName'],'type':_0x416574[_0x7bf4('0x32')][_0x7bf4('0x33')]};});_0xf95b11['model']=_[_0x7bf4('0x34')](_['map'](_0x3baa28,_0x7bf4('0x2c')),[_0x7bf4('0x35')]);_0xf95b11[_0x7bf4('0x36')]=_[_0x7bf4('0x37')](_0x16e0de[_0x7bf4('0x36')]);_0xf95b11[_0x7bf4('0x38')]=_[_0x7bf4('0x39')](_0xf95b11[_0x7bf4('0x3a')],_0xf95b11[_0x7bf4('0x36')]);_0x29647d[_0x7bf4('0x3b')]=_[_0x7bf4('0x39')](_0xf95b11['model'],qs[_0x7bf4('0x3c')](_0x16e0de[_0x7bf4('0x36')][_0x7bf4('0x3c')]));_0x29647d['attributes']=_0x29647d['attributes']['length']?_0x29647d['attributes']:_0xf95b11['model'];if(!_0x16e0de[_0x7bf4('0x36')][_0x7bf4('0x3d')](_0x7bf4('0x3e'))){_0x29647d['limit']=qs[_0x7bf4('0x1e')](_0x16e0de['query'][_0x7bf4('0x1e')]);_0x29647d[_0x7bf4('0x20')]=qs[_0x7bf4('0x20')](_0x16e0de[_0x7bf4('0x36')][_0x7bf4('0x20')]);}_0x29647d['order']=qs[_0x7bf4('0x3f')](_0x16e0de[_0x7bf4('0x36')][_0x7bf4('0x3f')]);_0x29647d[_0x7bf4('0x40')]=qs[_0x7bf4('0x38')](_[_0x7bf4('0x41')](_0x16e0de[_0x7bf4('0x36')],_0xf95b11['filters']),_0x3baa28);if(_0x16e0de['query'][_0x7bf4('0x42')]){_0x29647d[_0x7bf4('0x40')]=_['merge'](_0x29647d[_0x7bf4('0x40')],{'$or':_[_0x7bf4('0x2f')](_0x3baa28,function(_0x42ea2f){if(_0x42ea2f[_0x7bf4('0x32')]!==_0x7bf4('0x43')){var _0x317779={};_0x317779[_0x42ea2f[_0x7bf4('0x2c')]]={'$like':'%'+_0x16e0de[_0x7bf4('0x36')][_0x7bf4('0x42')]+'%'};return _0x317779;}})});}_0x29647d=_[_0x7bf4('0x44')]({},_0x29647d,_0x16e0de[_0x7bf4('0x45')]);var _0x163b90={'where':_0x29647d['where']};return db['VoiceRecording'][_0x7bf4('0x1f')](_0x163b90)[_0x7bf4('0x26')](function(_0x517b79){_0x2e304a[_0x7bf4('0x1f')]=_0x517b79;if(_0x16e0de[_0x7bf4('0x36')]['includeAll']){_0x29647d[_0x7bf4('0x46')]=[{'all':!![]}];}return db[_0x7bf4('0x30')][_0x7bf4('0x47')](_0x29647d);})[_0x7bf4('0x26')](function(_0x3a86c5){_0x2e304a[_0x7bf4('0x48')]=_0x3a86c5;return _0x2e304a;})[_0x7bf4('0x26')](respondWithFilteredResult(_0x23d9d5,_0x29647d))[_0x7bf4('0x49')](handleError(_0x23d9d5,null));};exports[_0x7bf4('0x4a')]=function(_0x1dce59,_0x8a458d){var _0x247fd5={'raw':![],'where':{'id':_0x1dce59[_0x7bf4('0x4b')]['id']}},_0x50f12f={};_0x50f12f['model']=_[_0x7bf4('0x37')](db[_0x7bf4('0x30')][_0x7bf4('0x31')]);_0x50f12f[_0x7bf4('0x36')]=_[_0x7bf4('0x37')](_0x1dce59['query']);_0x50f12f[_0x7bf4('0x38')]=_[_0x7bf4('0x39')](_0x50f12f[_0x7bf4('0x3a')],_0x50f12f[_0x7bf4('0x36')]);_0x247fd5[_0x7bf4('0x3b')]=_[_0x7bf4('0x39')](_0x50f12f[_0x7bf4('0x3a')],qs[_0x7bf4('0x3c')](_0x1dce59[_0x7bf4('0x36')]['fields']));_0x247fd5[_0x7bf4('0x3b')]=_0x247fd5[_0x7bf4('0x3b')][_0x7bf4('0x4c')]?_0x247fd5[_0x7bf4('0x3b')]:_0x50f12f[_0x7bf4('0x3a')];if(_0x1dce59[_0x7bf4('0x36')][_0x7bf4('0x4d')]){_0x247fd5[_0x7bf4('0x46')]=[{'all':!![]}];}_0x247fd5=_[_0x7bf4('0x44')]({},_0x247fd5,_0x1dce59[_0x7bf4('0x45')]);return db['VoiceRecording'][_0x7bf4('0x4e')](_0x247fd5)['then'](handleEntityNotFound(_0x8a458d,null))[_0x7bf4('0x26')](respondWithResult(_0x8a458d,null))['catch'](handleError(_0x8a458d,null));};exports['create']=function(_0x1c825b,_0x1b41df){return db[_0x7bf4('0x30')][_0x7bf4('0x4f')](_0x1c825b[_0x7bf4('0x50')],{})[_0x7bf4('0x26')](respondWithResult(_0x1b41df,0xc9))[_0x7bf4('0x49')](handleError(_0x1b41df,null));};exports[_0x7bf4('0x25')]=function(_0x402b8e,_0x3e3fbb){if(_0x402b8e[_0x7bf4('0x50')]['id']){delete _0x402b8e[_0x7bf4('0x50')]['id'];}return db[_0x7bf4('0x30')][_0x7bf4('0x4e')]({'where':{'id':_0x402b8e['params']['id']}})[_0x7bf4('0x26')](handleEntityNotFound(_0x3e3fbb,null))[_0x7bf4('0x26')](saveUpdates(_0x402b8e['body'],null))[_0x7bf4('0x26')](respondWithResult(_0x3e3fbb,null))[_0x7bf4('0x49')](handleError(_0x3e3fbb,null));};exports['describe']=function(_0xf0f863,_0x236555){return db[_0x7bf4('0x30')][_0x7bf4('0x51')]()[_0x7bf4('0x26')](respondWithResult(_0x236555,null))[_0x7bf4('0x49')](handleError(_0x236555,null));};exports['download']=function(_0x4b6993,_0x41cebb,_0x8e43d1){var _0x3c164f=require(_0x7bf4('0x52'));var _0x1adb18=![];var _0x4ee43c={};if(_0x4b6993[_0x7bf4('0x36')]['type']&&_0x4b6993[_0x7bf4('0x36')][_0x7bf4('0x32')]===_0x7bf4('0x53')){_0x4ee43c[_0x7bf4('0x53')]=_0x4b6993[_0x7bf4('0x4b')]['id'];}else{_0x4ee43c['id']=_0x4b6993['params']['id'];}return db[_0x7bf4('0x30')]['find']({'where':_0x4ee43c,'attributes':['id','value'],'raw':!![]})['then'](handleEntityNotFound(_0x41cebb,null))['then'](function(_0x584696){if(_0x584696){var _0xaaa87b=_0x584696[_0x7bf4('0x54')];var _0x211bab=util['format'](_0x7bf4('0x55'),_0xaaa87b);if(fs[_0x7bf4('0x56')](_0x211bab)){_0x1adb18=!![];return _0x3c164f[_0x7bf4('0x57')](_0x211bab,_0xaaa87b,config[_0x7bf4('0x58')][_0x7bf4('0x59')])[_0x7bf4('0x26')](function(){return _0x584696;});}return _0x584696;}})[_0x7bf4('0x26')](function(_0x24d821){if(_0x24d821){var _0x1d95be=_0x24d821['value'];if(!fs[_0x7bf4('0x56')](_0x1d95be)){throw new db[(_0x7bf4('0x5a'))][(_0x7bf4('0x5b'))]('VoiceRecording\x20not\x20found');}if(_0x24d821['filename']){return _0x41cebb['download'](_0x1d95be,_0x24d821[_0x7bf4('0x5c')]+path[_0x7bf4('0x5d')](_0x1d95be),function(){if(_0x1adb18){fs[_0x7bf4('0x5e')](_0x1d95be);}});}else{return _0x41cebb[_0x7bf4('0x5f')](_0x1d95be,function(_0x4f9540){if(_0x1adb18){fs[_0x7bf4('0x5e')](_0x1d95be);}});}}})[_0x7bf4('0x49')](function(_0x4a599f){if(_0x4a599f[_0x7bf4('0x60')]===_0x7bf4('0x61')){_0x41cebb[_0x7bf4('0x1b')](0x194)['send']('Not\x20found');}else{return handleError(_0x41cebb,null);}});};exports[_0x7bf4('0x62')]=function(_0x475563,_0x41dd41,_0x149c2b){var _0x2d5858=require(_0x7bf4('0x52'));var _0x367772=![];var _0x28b28f={'$and':[db['sequelize'][_0x7bf4('0x40')](db[_0x7bf4('0x63')]['fn'](_0x7bf4('0x64'),db[_0x7bf4('0x63')][_0x7bf4('0x65')](_0x7bf4('0x53'))),_0x475563[_0x7bf4('0x36')][_0x7bf4('0x66')])]};if(_0x475563[_0x7bf4('0x36')][_0x7bf4('0x32')]&&_0x475563[_0x7bf4('0x36')]['type']===_0x7bf4('0x53')){_0x28b28f[_0x7bf4('0x67')]['push']({'uniqueid':_0x475563['params']['id']});}else{_0x28b28f[_0x7bf4('0x67')][_0x7bf4('0x68')]({'id':_0x475563[_0x7bf4('0x4b')]['id']});}return db[_0x7bf4('0x30')][_0x7bf4('0x4e')]({'where':_0x28b28f,'attributes':['id','value'],'raw':!![]})[_0x7bf4('0x26')](handleEntityNotFound(_0x41dd41,null))['then'](function(_0xd9f0a5){if(_0xd9f0a5){var _0x150210=util[_0x7bf4('0x35')](_0x7bf4('0x55'),_0xd9f0a5[_0x7bf4('0x54')]);if(fs[_0x7bf4('0x56')](_0x150210)){_0x367772=!![];return _0x2d5858[_0x7bf4('0x57')](_0x150210,_0xd9f0a5[_0x7bf4('0x54')],config[_0x7bf4('0x58')][_0x7bf4('0x59')])[_0x7bf4('0x26')](function(){return _0xd9f0a5;});}return _0xd9f0a5;}})[_0x7bf4('0x26')](function(_0x394ca7){if(_0x394ca7){if(!fs['existsSync'](_0x394ca7[_0x7bf4('0x54')])){throw new db[(_0x7bf4('0x5a'))][(_0x7bf4('0x5b'))](_0x7bf4('0x61'));}if(_0x394ca7['filename']){return _0x41dd41[_0x7bf4('0x5f')](_0x394ca7['value'],_0x394ca7['filename']+path[_0x7bf4('0x5d')](_0x394ca7['value']),function(){if(_0x367772){fs[_0x7bf4('0x5e')](_0x394ca7['value']);}});}else{return _0x41dd41[_0x7bf4('0x5f')](_0x394ca7[_0x7bf4('0x54')],function(_0x1b7a0d){if(_0x367772){fs[_0x7bf4('0x5e')](_0x394ca7[_0x7bf4('0x54')]);}});}}})[_0x7bf4('0x49')](handleError(_0x41dd41,null));};exports[_0x7bf4('0x27')]=function(_0x609ced,_0x1aa06b){return db[_0x7bf4('0x30')][_0x7bf4('0x4e')]({'where':{'id':_0x609ced[_0x7bf4('0x4b')]['id']}})[_0x7bf4('0x26')](function(_0x5c570a){if(_[_0x7bf4('0x69')](_0x5c570a)){throw new ReferenceError('Entity\x20not\x20found');}return _0x5c570a;})[_0x7bf4('0x26')](function(_0x91c0a8){var _0x3208fe=_0x91c0a8[_0x7bf4('0x54')];logger[_0x7bf4('0x6a')]('cancellazione\x20fisica\x20documento\x20%s',_0x3208fe);if(!_[_0x7bf4('0x69')](_0x91c0a8['value'])&&fs[_0x7bf4('0x56')](_0x3208fe)){logger[_0x7bf4('0x6a')](_0x7bf4('0x6b')+_0x3208fe+'\x22\x20trovato\x20eseguo\x20la\x20cancellazione');fs[_0x7bf4('0x6c')](_0x3208fe);}_0x3208fe=_0x3208fe+_0x7bf4('0x6d');if(!_[_0x7bf4('0x69')](_0x91c0a8[_0x7bf4('0x54')])&&fs[_0x7bf4('0x56')](_0x3208fe)){logger[_0x7bf4('0x6a')]('File:\x20\x22'+_0x3208fe+_0x7bf4('0x6e'));fs[_0x7bf4('0x6c')](_0x3208fe);}return _0x91c0a8;})[_0x7bf4('0x26')](function(_0x33a61a){if(!_0x33a61a)throw new InternalError();return _0x33a61a[_0x7bf4('0x27')]();})['then'](function(){_0x1aa06b[_0x7bf4('0x1b')](0xcc)['end']();})['catch'](handleError(_0x1aa06b,null));};function getBucketslist(_0xb224a2,_0x39835b,_0x5d7e74){return new Promise(function(_0x541560,_0x18f1d7){var _0x593c40=new AWS['S3']({'accessKeyId':_0x39835b,'secretAccessKey':_0xb224a2,'region':_0x5d7e74});_0x593c40['listBuckets']({},function(_0x3a0445,_0x4a618b){if(_0x3a0445){return _0x18f1d7(_0x3a0445);}else{return _0x541560(_0x4a618b);}});});}function createBucket(_0x2fbcb0,_0x1fceae,_0x2a9df7,_0x13e717){return new Promise(function(_0x17bff0,_0x162851){var _0x405692=new AWS['S3']({'accessKeyId':_0x1fceae,'secretAccessKey':_0x2fbcb0,'region':_0x2a9df7});_0x405692['createBucket']({'Bucket':_0x13e717},function(_0x4338c4,_0x343e60){if(_0x4338c4){return _0x162851(_0x4338c4);}else{return _0x17bff0(_0x343e60);}});});}function uploadFile(_0x570b41,_0x17bfb0,_0x1728fb,_0x39a12e,_0x289493,_0x509247){return new Promise(function(_0x52c278,_0x55e9b0){var _0x8ddbc1=new AWS['S3']({'accessKeyId':_0x17bfb0,'secretAccessKey':_0x570b41,'region':_0x1728fb});_0x8ddbc1[_0x7bf4('0x6f')]({'Bucket':_0x39a12e,'Key':_0x289493,'Body':_0x509247},function(_0x54efdd,_0x30b0df){if(_0x54efdd){return _0x55e9b0(_0x54efdd);}else{return _0x52c278(_0x30b0df);}});});}function startTranscribe(_0x250950,_0x3b7aaa,_0x3d6fd5,_0x4b5b30,_0x14b0e7,_0x530054){return new Promise(function(_0x16f1ff,_0x57c483){var _0x5405e2=new AWS[(_0x7bf4('0x70'))]({'accessKeyId':_0x3b7aaa,'secretAccessKey':_0x250950,'region':_0x3d6fd5});_0x5405e2[_0x7bf4('0x71')]({'TranscriptionJobName':_0x4b5b30,'LanguageCode':_0x14b0e7,'Media':{'MediaFileUri':_0x530054}},function(_0x5650f2,_0x302a1b){if(_0x5650f2){return _0x57c483(_0x5650f2);}else{return _0x16f1ff(_0x302a1b);}});});}function transcribe(_0x12ce8c,_0x209a2a,_0x25b552,_0xc95e87,_0x53a236,_0x5bbfbf,_0x134a3c){return new Promise(function(_0x3f46ef,_0x242a9e){var _0x5cf808={};logger[_0x7bf4('0x6a')](util[_0x7bf4('0x35')](_0x7bf4('0x72'),_0x12ce8c,_0x53a236));return uploadFile(_0x209a2a,_0x25b552,_0xc95e87,_0x53a236,path[_0x7bf4('0x73')](_0x5bbfbf),fs[_0x7bf4('0x74')](_0x5bbfbf))[_0x7bf4('0x26')](function(_0x1c1a35){logger[_0x7bf4('0x6a')](util['format'](_0x7bf4('0x75'),_0x12ce8c,_0x53a236,_0x1c1a35[_0x7bf4('0x76')]));_0x5cf808['bucket']=_0x1c1a35['Bucket'];_0x5cf808[_0x7bf4('0x77')]=_0x1c1a35[_0x7bf4('0x76')];logger[_0x7bf4('0x6a')](util[_0x7bf4('0x35')](_0x7bf4('0x78'),_0x12ce8c));return startTranscribe(_0x209a2a,_0x25b552,_0xc95e87,uuidv4(),_0x134a3c,_0x1c1a35[_0x7bf4('0x76')]);})[_0x7bf4('0x26')](function(_0x4fa03d){logger[_0x7bf4('0x6a')](util['format']('[RUNTRANSCRIPT][%d]\x20Transcription\x20job\x20%s\x20created',_0x12ce8c,_0x4fa03d[_0x7bf4('0x79')][_0x7bf4('0x7a')]));_0x5cf808['transcribeName']=_0x4fa03d[_0x7bf4('0x79')][_0x7bf4('0x7a')];_0x5cf808[_0x7bf4('0x7b')]=_0x4fa03d[_0x7bf4('0x79')][_0x7bf4('0x7c')];return _0x3f46ef(_0x5cf808);})[_0x7bf4('0x49')](function(_0x272e68){return _0x242a9e(_0x272e68);});});}exports[_0x7bf4('0x7d')]=function(_0x12ca8c,_0xc8a7c5,_0x5463aa){var _0x517af0;var _0x341394;var _0x19214c;var _0x6bb2e6=require('../../components/encryptor');return db[_0x7bf4('0x30')][_0x7bf4('0x7e')]({'where':{'id':_0x12ca8c[_0x7bf4('0x4b')]['id']}})[_0x7bf4('0x26')](function(_0x4a7952){if(_0x4a7952){var _0x148139=util[_0x7bf4('0x35')]('%s.cypher',_0x4a7952['value']);if(fs['existsSync'](_0x148139)){cypher=!![];return _0x6bb2e6['decryptFile'](_0x148139,_0x4a7952['value'],config['secrets'][_0x7bf4('0x59')])[_0x7bf4('0x26')](function(){return _0x4a7952;});}return _0x4a7952;}})[_0x7bf4('0x26')](function(_0x5f3756){if(!_0x5f3756){throw new db[(_0x7bf4('0x5a'))]['ValidationError'](_0x7bf4('0x7f'));}_0x341394=_0x5f3756;return db['Setting'][_0x7bf4('0x7e')]({'where':{'id':0x1}});})[_0x7bf4('0x26')](handleEntityNotFound(_0xc8a7c5,null))[_0x7bf4('0x26')](function(_0x5eb8ed){if(_0x5eb8ed){_0x517af0=_0x5eb8ed;if(!_0x517af0[_0x7bf4('0x80')]||!_0x517af0['transcribeAccountId']||!_0x517af0[_0x7bf4('0x81')]||!_0x517af0[_0x7bf4('0x82')]||!_0x517af0[_0x7bf4('0x83')]){throw new db[(_0x7bf4('0x5a'))][(_0x7bf4('0x5b'))](_0x7bf4('0x84'));}if(_0x12ca8c[_0x7bf4('0x50')][_0x7bf4('0x85')]&&(!_0x517af0['sentiment']||!_0x517af0['sentimentAccountId']||!_0x517af0['sentimentRegion']||!_0x517af0[_0x7bf4('0x82')]||!_0x517af0[_0x7bf4('0x83')])){throw new db['Sequelize']['ValidationError'](_0x7bf4('0x86'));}return db[_0x7bf4('0x87')][_0x7bf4('0x7e')]({'where':{'id':_0x517af0[_0x7bf4('0x88')]}});}})[_0x7bf4('0x26')](function(_0x19b4f3){if(!_0x19b4f3){throw new db[(_0x7bf4('0x5a'))]['ValidationError']('Cloud\x20Provider\x20not\x20available');}if(!_0x19b4f3[_0x7bf4('0x89')]||!_0x19b4f3[_0x7bf4('0x8a')]){throw new db[(_0x7bf4('0x5a'))][(_0x7bf4('0x5b'))](_0x7bf4('0x8b'));}_0x19214c=_0x19b4f3;return getBucketslist(_0x19214c[_0x7bf4('0x89')],_0x19214c[_0x7bf4('0x8a')],_0x517af0[_0x7bf4('0x81')]);})[_0x7bf4('0x26')](function(_0x11beeb){if(_0x11beeb&&_0x11beeb[_0x7bf4('0x8c')]){var _0x427f02=_[_0x7bf4('0x4e')](_0x11beeb['Buckets'],function(_0xbc76d5){return _0xbc76d5[_0x7bf4('0x8d')]===_0x517af0[_0x7bf4('0x83')];});if(!_0x427f02){logger[_0x7bf4('0x6a')](util['format'](_0x7bf4('0x8e'),_0x12ca8c[_0x7bf4('0x4b')]['id'],_0x517af0[_0x7bf4('0x83')]));return createBucket(_0x19214c[_0x7bf4('0x89')],_0x19214c['data2'],_0x517af0[_0x7bf4('0x81')],_0x517af0[_0x7bf4('0x83')]);}logger[_0x7bf4('0x6a')](util['format']('[RUNTRANSCRIPT][%d]\x20Bucket\x20%s\x20available',_0x12ca8c[_0x7bf4('0x4b')]['id'],_0x517af0[_0x7bf4('0x83')]));return;}})[_0x7bf4('0x26')](function(_0x3bbf04){if(_0x341394[_0x7bf4('0x7b')]==='NEW'){return transcribe(_0x12ca8c['params']['id'],_0x19214c[_0x7bf4('0x89')],_0x19214c['data2'],_0x517af0[_0x7bf4('0x81')],_0x517af0[_0x7bf4('0x83')],_0x341394[_0x7bf4('0x54')],_0x517af0[_0x7bf4('0x82')]);}else{logger[_0x7bf4('0x6a')](util['format'](_0x7bf4('0x8f'),_0x12ca8c[_0x7bf4('0x4b')]['id']));return{'transcribeStatus':_0x7bf4('0x90')};}})[_0x7bf4('0x26')](function(_0x2c5ecc){if(_0x2c5ecc){_0x2c5ecc['tempSentiment']=_0x12ca8c[_0x7bf4('0x50')][_0x7bf4('0x85')];return _0x341394[_0x7bf4('0x91')](_0x2c5ecc);}})[_0x7bf4('0x26')](respondWithResult(_0xc8a7c5,null))['catch'](handleError(_0xc8a7c5,null));};function writeFile(_0x445d36,_0x3f7d56){return new Promise(function(_0x5ddff7,_0x5c9de7){fs['writeFile'](_0x3f7d56,_0x445d36,function(_0x48c42e,_0x52ef35){if(_0x48c42e){return _0x5c9de7(_0x48c42e);}else{return _0x5ddff7(_0x52ef35);}});});}exports[_0x7bf4('0x92')]=function(_0x4063aa,_0x4c1442,_0x1286f9){return db[_0x7bf4('0x30')][_0x7bf4('0x7e')]({'where':{'id':_0x4063aa['params']['id']}})[_0x7bf4('0x26')](handleEntityNotFound(_0x4c1442))[_0x7bf4('0x26')](function(_0x437d0e){if(_0x437d0e&&_0x437d0e[_0x7bf4('0x93')]){var _0x1fad85=_0x437d0e[_0x7bf4('0x93')];var _0x10b227=config['root']+'/server/files/transcribes/transcribe_'+_0x437d0e['id']+_0x7bf4('0x94');if(fs[_0x7bf4('0x56')](_0x10b227)){return _0x10b227;}return writeFile(_0x1fad85,_0x10b227)[_0x7bf4('0x26')](function(){return _0x10b227;});}else{throw new db[(_0x7bf4('0x5a'))][(_0x7bf4('0x5b'))]('Transcript\x20not\x20available');}})[_0x7bf4('0x26')](function(_0x119c75){return _0x4c1442[_0x7bf4('0x5f')](_0x119c75);})[_0x7bf4('0x49')](handleError(_0x4c1442));};