Built motion from commit (unavailable).|2.5.26
[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 _0xbf4c=['include','findAll','rows','catch','params','options','find','create','body','describe','download','../../components/encryptor','uniqueid','value','%s.cypher','existsSync','decryptFile','secrets','Sequelize','ValidationError','filename','extname','unlink','message','downloads','sequelize','col','token','$and','push','recording','VoiceRecording\x20not\x20found','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','[RUNTRANSCRIPT][%d]\x20Voice\x20recording\x20uploaded\x20in\x20bucket\x20%s\x20(%s)','Location','bucket','Bucket','location','[RUNTRANSCRIPT][%d]\x20Sending\x20transcribe\x20request','[RUNTRANSCRIPT][%d]\x20Transcription\x20job\x20%s\x20created','TranscriptionJob','TranscriptionJobName','transcribeName','runTranscribe','findOne','Voice\x20Recording\x20not\x20found','Setting','transcribe','transcribeAccountId','Transcribe\x20not\x20configured','sentimentAccountId','sentimentRegion','language','Sentiment\x20Analysis\x20not\x20configured','CloudProvider','Cloud\x20Provider\x20not\x20available','data2','Cloud\x20Provider\x20not\x20configured','data1','transcribeRegion','Buckets','Name','[RUNTRANSCRIPT][%d]\x20Bucket\x20%s\x20available','transcribeStatus','NEW','[RUNTRANSCRIPT][%d]\x20Transcript\x20action\x20already\x20requested','tempSentiment','updateAttributes','writeFile','downloadTranscribe','fileText','/server/files/transcribes/transcribe_','.txt','Transcript\x20not\x20available','eml-format','zip-dir','request-promise','moment','bluebird','mustache','sox','to-csv','ejs','lodash','squel','crypto','jsforce','desk.js','papaparse','uuid/v4','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','../../config/environment','../../config/license/util','../../mysqldb','sendStatus','status','end','json','count','offset','limit','Content-Range','apply','reject','save','update','destroy','then','error','stack','name','send','map','VoiceRecording','rawAttributes','fieldName','type','key','model','differenceBy','format','query','keys','filters','intersection','attributes','fields','length','order','sort','where','pick','filter','VIRTUAL','merge','includeAll'];(function(_0x297fd3,_0x115406){var _0x2af381=function(_0x1dd31b){while(--_0x1dd31b){_0x297fd3['push'](_0x297fd3['shift']());}};_0x2af381(++_0x115406);}(_0xbf4c,0xf2));var _0xcbf4=function(_0x3c302e,_0x2a353c){_0x3c302e=_0x3c302e-0x0;var _0x7bf43c=_0xbf4c[_0x3c302e];return _0x7bf43c;};'use strict';var emlformat=require(_0xcbf4('0x0'));var rimraf=require('rimraf');var zipdir=require(_0xcbf4('0x1'));var jsonpatch=require('fast-json-patch');var rp=require(_0xcbf4('0x2'));var moment=require(_0xcbf4('0x3'));var BPromise=require(_0xcbf4('0x4'));var Mustache=require(_0xcbf4('0x5'));var util=require('util');var path=require('path');var sox=require(_0xcbf4('0x6'));var csv=require(_0xcbf4('0x7'));var ejs=require(_0xcbf4('0x8'));var fs=require('fs');var fs_extra=require('fs-extra');var _=require(_0xcbf4('0x9'));var squel=require(_0xcbf4('0xa'));var crypto=require(_0xcbf4('0xb'));var jsforce=require(_0xcbf4('0xc'));var deskjs=require(_0xcbf4('0xd'));var toCsv=require(_0xcbf4('0x7'));var querystring=require('querystring');var Papa=require(_0xcbf4('0xe'));var AWS=require('aws-sdk');var uuidv4=require(_0xcbf4('0xf'));var Redis=require('ioredis');var authService=require(_0xcbf4('0x10'));var qs=require(_0xcbf4('0x11'));var as=require(_0xcbf4('0x12'));var hardwareService=require(_0xcbf4('0x13'));var logger=require(_0xcbf4('0x14'))('api');var utils=require('../../config/utils');var config=require(_0xcbf4('0x15'));var licenseUtil=require(_0xcbf4('0x16'));var db=require(_0xcbf4('0x17'))['db'];function respondWithStatusCode(_0x26657b,_0x194271){_0x194271=_0x194271||0xcc;return function(_0x4811c6){if(_0x4811c6){return _0x26657b[_0xcbf4('0x18')](_0x194271);}return _0x26657b[_0xcbf4('0x19')](_0x194271)[_0xcbf4('0x1a')]();};}function respondWithResult(_0xbdba3c,_0x18b0ac){_0x18b0ac=_0x18b0ac||0xc8;return function(_0x486b12){if(_0x486b12){return _0xbdba3c[_0xcbf4('0x19')](_0x18b0ac)[_0xcbf4('0x1b')](_0x486b12);}};}function respondWithFilteredResult(_0x2a444a,_0x3aed83){return function(_0x2e2d8e){if(_0x2e2d8e){var _0x37a013=_0x2e2d8e[_0xcbf4('0x1c')],_0x1eeb04=_0x3aed83[_0xcbf4('0x1d')],_0x544b9c=_0x3aed83[_0xcbf4('0x1d')]+_0x3aed83[_0xcbf4('0x1e')],_0x3a4642;if(_0x544b9c>=_0x37a013){_0x544b9c=_0x37a013;_0x3a4642=0xc8;}else{_0x3a4642=0xce;}_0x2a444a[_0xcbf4('0x19')](_0x3a4642);return _0x2a444a['set'](_0xcbf4('0x1f'),_0x1eeb04+'-'+_0x544b9c+'/'+_0x37a013)[_0xcbf4('0x1b')](_0x2e2d8e);}return null;};}function patchUpdates(_0x8c371d){return function(_0x574a64){try{jsonpatch[_0xcbf4('0x20')](_0x574a64,_0x8c371d,!![]);}catch(_0x5081ee){return BPromise[_0xcbf4('0x21')](_0x5081ee);}return _0x574a64[_0xcbf4('0x22')]();};}function saveUpdates(_0x2de2de,_0x43eb6d){return function(_0x1f6d57){if(_0x1f6d57){return _0x1f6d57[_0xcbf4('0x23')](_0x2de2de)['then'](function(_0x24874a){return _0x24874a;});}return null;};}function removeEntity(_0x4ffe7e,_0x1dfc13){return function(_0x11ab4e){if(_0x11ab4e){return _0x11ab4e[_0xcbf4('0x24')]()[_0xcbf4('0x25')](function(){_0x4ffe7e[_0xcbf4('0x19')](0xcc)[_0xcbf4('0x1a')]();});}};}function handleEntityNotFound(_0x578190,_0x20bf7c){return function(_0xdf68e5){if(!_0xdf68e5){_0x578190[_0xcbf4('0x18')](0x194);}return _0xdf68e5;};}function handleError(_0x4b6bf4,_0x222a53){_0x222a53=_0x222a53||0x1f4;return function(_0x36a76f){logger[_0xcbf4('0x26')](_0x36a76f[_0xcbf4('0x27')]);if(_0x36a76f[_0xcbf4('0x28')]){delete _0x36a76f[_0xcbf4('0x28')];}_0x4b6bf4[_0xcbf4('0x19')](_0x222a53)[_0xcbf4('0x29')](_0x36a76f);};}exports['index']=function(_0x561d05,_0x47ad3b){var _0x5add34={},_0x18292b={},_0x1cc7f2={'count':0x0,'rows':[]};var _0x389747=_[_0xcbf4('0x2a')](db[_0xcbf4('0x2b')][_0xcbf4('0x2c')],function(_0x18de87){return{'name':_0x18de87[_0xcbf4('0x2d')],'type':_0x18de87[_0xcbf4('0x2e')][_0xcbf4('0x2f')]};});_0x18292b[_0xcbf4('0x30')]=_[_0xcbf4('0x31')](_['map'](_0x389747,_0xcbf4('0x28')),[_0xcbf4('0x32')]);_0x18292b[_0xcbf4('0x33')]=_[_0xcbf4('0x34')](_0x561d05[_0xcbf4('0x33')]);_0x18292b[_0xcbf4('0x35')]=_[_0xcbf4('0x36')](_0x18292b[_0xcbf4('0x30')],_0x18292b[_0xcbf4('0x33')]);_0x5add34[_0xcbf4('0x37')]=_[_0xcbf4('0x36')](_0x18292b[_0xcbf4('0x30')],qs[_0xcbf4('0x38')](_0x561d05['query'][_0xcbf4('0x38')]));_0x5add34[_0xcbf4('0x37')]=_0x5add34['attributes'][_0xcbf4('0x39')]?_0x5add34[_0xcbf4('0x37')]:_0x18292b[_0xcbf4('0x30')];if(!_0x561d05[_0xcbf4('0x33')]['hasOwnProperty']('nolimit')){_0x5add34[_0xcbf4('0x1e')]=qs['limit'](_0x561d05[_0xcbf4('0x33')]['limit']);_0x5add34[_0xcbf4('0x1d')]=qs['offset'](_0x561d05[_0xcbf4('0x33')][_0xcbf4('0x1d')]);}_0x5add34[_0xcbf4('0x3a')]=qs[_0xcbf4('0x3b')](_0x561d05[_0xcbf4('0x33')]['sort']);_0x5add34[_0xcbf4('0x3c')]=qs[_0xcbf4('0x35')](_[_0xcbf4('0x3d')](_0x561d05['query'],_0x18292b[_0xcbf4('0x35')]),_0x389747);if(_0x561d05['query'][_0xcbf4('0x3e')]){_0x5add34['where']=_['merge'](_0x5add34['where'],{'$or':_[_0xcbf4('0x2a')](_0x389747,function(_0x5c0b83){if(_0x5c0b83['type']!==_0xcbf4('0x3f')){var _0x3585eb={};_0x3585eb[_0x5c0b83[_0xcbf4('0x28')]]={'$like':'%'+_0x561d05['query']['filter']+'%'};return _0x3585eb;}})});}_0x5add34=_[_0xcbf4('0x40')]({},_0x5add34,_0x561d05['options']);var _0x25b4d8={'where':_0x5add34[_0xcbf4('0x3c')]};return db[_0xcbf4('0x2b')]['count'](_0x25b4d8)[_0xcbf4('0x25')](function(_0x68937a){_0x1cc7f2[_0xcbf4('0x1c')]=_0x68937a;if(_0x561d05[_0xcbf4('0x33')][_0xcbf4('0x41')]){_0x5add34[_0xcbf4('0x42')]=[{'all':!![]}];}return db[_0xcbf4('0x2b')][_0xcbf4('0x43')](_0x5add34);})[_0xcbf4('0x25')](function(_0x59f882){_0x1cc7f2[_0xcbf4('0x44')]=_0x59f882;return _0x1cc7f2;})[_0xcbf4('0x25')](respondWithFilteredResult(_0x47ad3b,_0x5add34))[_0xcbf4('0x45')](handleError(_0x47ad3b,null));};exports['show']=function(_0x53879d,_0x54b19b){var _0x4a4d3a={'raw':![],'where':{'id':_0x53879d[_0xcbf4('0x46')]['id']}},_0x9fb395={};_0x9fb395[_0xcbf4('0x30')]=_[_0xcbf4('0x34')](db[_0xcbf4('0x2b')]['rawAttributes']);_0x9fb395[_0xcbf4('0x33')]=_[_0xcbf4('0x34')](_0x53879d['query']);_0x9fb395[_0xcbf4('0x35')]=_[_0xcbf4('0x36')](_0x9fb395['model'],_0x9fb395['query']);_0x4a4d3a[_0xcbf4('0x37')]=_[_0xcbf4('0x36')](_0x9fb395[_0xcbf4('0x30')],qs[_0xcbf4('0x38')](_0x53879d[_0xcbf4('0x33')][_0xcbf4('0x38')]));_0x4a4d3a[_0xcbf4('0x37')]=_0x4a4d3a['attributes']['length']?_0x4a4d3a[_0xcbf4('0x37')]:_0x9fb395[_0xcbf4('0x30')];if(_0x53879d['query'][_0xcbf4('0x41')]){_0x4a4d3a['include']=[{'all':!![]}];}_0x4a4d3a=_[_0xcbf4('0x40')]({},_0x4a4d3a,_0x53879d[_0xcbf4('0x47')]);return db[_0xcbf4('0x2b')][_0xcbf4('0x48')](_0x4a4d3a)['then'](handleEntityNotFound(_0x54b19b,null))[_0xcbf4('0x25')](respondWithResult(_0x54b19b,null))[_0xcbf4('0x45')](handleError(_0x54b19b,null));};exports[_0xcbf4('0x49')]=function(_0x59b514,_0xffbf10){return db[_0xcbf4('0x2b')][_0xcbf4('0x49')](_0x59b514[_0xcbf4('0x4a')],{})['then'](respondWithResult(_0xffbf10,0xc9))[_0xcbf4('0x45')](handleError(_0xffbf10,null));};exports['update']=function(_0x10a5bd,_0x57d460){if(_0x10a5bd[_0xcbf4('0x4a')]['id']){delete _0x10a5bd[_0xcbf4('0x4a')]['id'];}return db[_0xcbf4('0x2b')][_0xcbf4('0x48')]({'where':{'id':_0x10a5bd[_0xcbf4('0x46')]['id']}})['then'](handleEntityNotFound(_0x57d460,null))[_0xcbf4('0x25')](saveUpdates(_0x10a5bd[_0xcbf4('0x4a')],null))[_0xcbf4('0x25')](respondWithResult(_0x57d460,null))[_0xcbf4('0x45')](handleError(_0x57d460,null));};exports[_0xcbf4('0x4b')]=function(_0x17107d,_0x4fb4ee){return db[_0xcbf4('0x2b')][_0xcbf4('0x4b')]()[_0xcbf4('0x25')](respondWithResult(_0x4fb4ee,null))[_0xcbf4('0x45')](handleError(_0x4fb4ee,null));};exports[_0xcbf4('0x4c')]=function(_0x24236e,_0x5d9220,_0x47f619){var _0xc4c60a=require(_0xcbf4('0x4d'));var _0x498f2f=![];var _0x31707a={};if(_0x24236e[_0xcbf4('0x33')][_0xcbf4('0x2e')]&&_0x24236e['query'][_0xcbf4('0x2e')]===_0xcbf4('0x4e')){_0x31707a['uniqueid']=_0x24236e[_0xcbf4('0x46')]['id'];}else{_0x31707a['id']=_0x24236e['params']['id'];}return db[_0xcbf4('0x2b')][_0xcbf4('0x48')]({'where':_0x31707a,'attributes':['id',_0xcbf4('0x4f')],'raw':!![]})[_0xcbf4('0x25')](handleEntityNotFound(_0x5d9220,null))[_0xcbf4('0x25')](function(_0x3660a9){if(_0x3660a9){var _0x5ab494=_0x3660a9['value'];var _0x27ca12=util[_0xcbf4('0x32')](_0xcbf4('0x50'),_0x5ab494);if(fs[_0xcbf4('0x51')](_0x27ca12)){_0x498f2f=!![];return _0xc4c60a[_0xcbf4('0x52')](_0x27ca12,_0x5ab494,config[_0xcbf4('0x53')]['recording'])[_0xcbf4('0x25')](function(){return _0x3660a9;});}return _0x3660a9;}})[_0xcbf4('0x25')](function(_0xc428e0){if(_0xc428e0){var _0x10da1b=_0xc428e0['value'];if(!fs[_0xcbf4('0x51')](_0x10da1b)){throw new db[(_0xcbf4('0x54'))][(_0xcbf4('0x55'))]('VoiceRecording\x20not\x20found');}if(_0xc428e0[_0xcbf4('0x56')]){return _0x5d9220[_0xcbf4('0x4c')](_0x10da1b,_0xc428e0['filename']+path[_0xcbf4('0x57')](_0x10da1b),function(){if(_0x498f2f){fs[_0xcbf4('0x58')](_0x10da1b);}});}else{return _0x5d9220[_0xcbf4('0x4c')](_0x10da1b,function(_0x54638a){if(_0x498f2f){fs['unlink'](_0x10da1b);}});}}})['catch'](function(_0x409549){if(_0x409549[_0xcbf4('0x59')]==='VoiceRecording\x20not\x20found'){_0x5d9220['status'](0x194)[_0xcbf4('0x29')]('Not\x20found');}else{return handleError(_0x5d9220,null);}});};exports[_0xcbf4('0x5a')]=function(_0x5885d6,_0x5d0d2f,_0x1525d7){var _0x388e36=require(_0xcbf4('0x4d'));var _0x37636a=![];var _0x3a95e2={'$and':[db[_0xcbf4('0x5b')][_0xcbf4('0x3c')](db[_0xcbf4('0x5b')]['fn']('MD5',db[_0xcbf4('0x5b')][_0xcbf4('0x5c')](_0xcbf4('0x4e'))),_0x5885d6[_0xcbf4('0x33')][_0xcbf4('0x5d')])]};if(_0x5885d6[_0xcbf4('0x33')][_0xcbf4('0x2e')]&&_0x5885d6[_0xcbf4('0x33')]['type']==='uniqueid'){_0x3a95e2[_0xcbf4('0x5e')][_0xcbf4('0x5f')]({'uniqueid':_0x5885d6[_0xcbf4('0x46')]['id']});}else{_0x3a95e2[_0xcbf4('0x5e')]['push']({'id':_0x5885d6[_0xcbf4('0x46')]['id']});}return db[_0xcbf4('0x2b')]['find']({'where':_0x3a95e2,'attributes':['id','value'],'raw':!![]})[_0xcbf4('0x25')](handleEntityNotFound(_0x5d0d2f,null))[_0xcbf4('0x25')](function(_0x107fcd){if(_0x107fcd){var _0x52797b=util['format'](_0xcbf4('0x50'),_0x107fcd[_0xcbf4('0x4f')]);if(fs[_0xcbf4('0x51')](_0x52797b)){_0x37636a=!![];return _0x388e36['decryptFile'](_0x52797b,_0x107fcd[_0xcbf4('0x4f')],config[_0xcbf4('0x53')][_0xcbf4('0x60')])['then'](function(){return _0x107fcd;});}return _0x107fcd;}})['then'](function(_0x595dd1){if(_0x595dd1){if(!fs[_0xcbf4('0x51')](_0x595dd1['value'])){throw new db[(_0xcbf4('0x54'))][(_0xcbf4('0x55'))](_0xcbf4('0x61'));}if(_0x595dd1[_0xcbf4('0x56')]){return _0x5d0d2f[_0xcbf4('0x4c')](_0x595dd1[_0xcbf4('0x4f')],_0x595dd1[_0xcbf4('0x56')]+path[_0xcbf4('0x57')](_0x595dd1[_0xcbf4('0x4f')]),function(){if(_0x37636a){fs[_0xcbf4('0x58')](_0x595dd1[_0xcbf4('0x4f')]);}});}else{return _0x5d0d2f[_0xcbf4('0x4c')](_0x595dd1[_0xcbf4('0x4f')],function(_0x206758){if(_0x37636a){fs['unlink'](_0x595dd1[_0xcbf4('0x4f')]);}});}}})['catch'](handleError(_0x5d0d2f,null));};exports[_0xcbf4('0x24')]=function(_0x4ddc87,_0x47f295){return db['VoiceRecording'][_0xcbf4('0x48')]({'where':{'id':_0x4ddc87[_0xcbf4('0x46')]['id']}})[_0xcbf4('0x25')](function(_0x395308){if(!_0x395308)throw new ReferenceError(_0xcbf4('0x62'));return _0x395308;})['then'](function(_0x5c2f83){var _0x37d0ff=_0x5c2f83[_0xcbf4('0x4f')];logger[_0xcbf4('0x63')](_0xcbf4('0x64'),_0x37d0ff);if(!_[_0xcbf4('0x65')](_0x5c2f83['value'])&&fs[_0xcbf4('0x51')](_0x37d0ff)){logger[_0xcbf4('0x63')](_0xcbf4('0x66')+_0x37d0ff+_0xcbf4('0x67'));fs['unlinkSync'](_0x37d0ff);}_0x37d0ff=_0x37d0ff+_0xcbf4('0x68');if(!_[_0xcbf4('0x65')](_0x5c2f83[_0xcbf4('0x4f')])&&fs[_0xcbf4('0x51')](_0x37d0ff)){logger[_0xcbf4('0x63')]('File:\x20\x22'+_0x37d0ff+_0xcbf4('0x67'));fs[_0xcbf4('0x69')](_0x37d0ff);}return _0x5c2f83;})['then'](function(_0x2d756d){if(!_0x2d756d)throw new InternalError();return _0x2d756d['destroy']();})[_0xcbf4('0x25')](function(){_0x47f295[_0xcbf4('0x19')](0xcc)[_0xcbf4('0x1a')]();})[_0xcbf4('0x45')](handleError(_0x47f295,null));};function getBucketslist(_0x21be4d,_0x2ce763,_0x40d6b8){return new Promise(function(_0x8d50a9,_0x56ca39){var _0x238b3e=new AWS['S3']({'accessKeyId':_0x2ce763,'secretAccessKey':_0x21be4d,'region':_0x40d6b8});_0x238b3e[_0xcbf4('0x6a')]({},function(_0x5b6f86,_0x570868){if(_0x5b6f86){return _0x56ca39(_0x5b6f86);}else{return _0x8d50a9(_0x570868);}});});}function createBucket(_0x42127c,_0x50e543,_0x30dae1,_0x22e0fb){return new Promise(function(_0x3f9eaa,_0x583334){var _0x463d55=new AWS['S3']({'accessKeyId':_0x50e543,'secretAccessKey':_0x42127c,'region':_0x30dae1});_0x463d55[_0xcbf4('0x6b')]({'Bucket':_0x22e0fb},function(_0x16ac30,_0x470384){if(_0x16ac30){return _0x583334(_0x16ac30);}else{return _0x3f9eaa(_0x470384);}});});}function uploadFile(_0x5e9f1b,_0x4f2673,_0xa4d101,_0x2d31be,_0x46ee12,_0x26be43){return new Promise(function(_0x44e450,_0x1ed488){var _0x360d00=new AWS['S3']({'accessKeyId':_0x4f2673,'secretAccessKey':_0x5e9f1b,'region':_0xa4d101});_0x360d00[_0xcbf4('0x6c')]({'Bucket':_0x2d31be,'Key':_0x46ee12,'Body':_0x26be43},function(_0xf50fd4,_0xdd68a3){if(_0xf50fd4){return _0x1ed488(_0xf50fd4);}else{return _0x44e450(_0xdd68a3);}});});}function startTranscribe(_0x52168e,_0x1ae7c6,_0x481cf1,_0x5bfb3f,_0x302eea,_0x20ee75){return new Promise(function(_0x2e5dee,_0x54cb52){var _0x468b96=new AWS[(_0xcbf4('0x6d'))]({'accessKeyId':_0x1ae7c6,'secretAccessKey':_0x52168e,'region':_0x481cf1});_0x468b96[_0xcbf4('0x6e')]({'TranscriptionJobName':_0x5bfb3f,'LanguageCode':_0x302eea,'Media':{'MediaFileUri':_0x20ee75}},function(_0x15876b,_0x6b8239){if(_0x15876b){return _0x54cb52(_0x15876b);}else{return _0x2e5dee(_0x6b8239);}});});}function transcribe(_0x4c9d31,_0x20e034,_0x591b51,_0x2d9d1f,_0x545a1c,_0x50c39c,_0x20d315){return new Promise(function(_0x4b557a,_0x122be3){var _0xe14235={};logger[_0xcbf4('0x63')](util[_0xcbf4('0x32')](_0xcbf4('0x6f'),_0x4c9d31,_0x545a1c));return uploadFile(_0x20e034,_0x591b51,_0x2d9d1f,_0x545a1c,path['basename'](_0x50c39c),fs[_0xcbf4('0x70')](_0x50c39c))['then'](function(_0x156f7c){logger[_0xcbf4('0x63')](util[_0xcbf4('0x32')](_0xcbf4('0x71'),_0x4c9d31,_0x545a1c,_0x156f7c[_0xcbf4('0x72')]));_0xe14235[_0xcbf4('0x73')]=_0x156f7c[_0xcbf4('0x74')];_0xe14235[_0xcbf4('0x75')]=_0x156f7c[_0xcbf4('0x72')];logger[_0xcbf4('0x63')](util[_0xcbf4('0x32')](_0xcbf4('0x76'),_0x4c9d31));return startTranscribe(_0x20e034,_0x591b51,_0x2d9d1f,uuidv4(),_0x20d315,_0x156f7c[_0xcbf4('0x72')]);})[_0xcbf4('0x25')](function(_0x42dc64){logger[_0xcbf4('0x63')](util[_0xcbf4('0x32')](_0xcbf4('0x77'),_0x4c9d31,_0x42dc64[_0xcbf4('0x78')][_0xcbf4('0x79')]));_0xe14235[_0xcbf4('0x7a')]=_0x42dc64[_0xcbf4('0x78')][_0xcbf4('0x79')];_0xe14235['transcribeStatus']=_0x42dc64[_0xcbf4('0x78')]['TranscriptionJobStatus'];return _0x4b557a(_0xe14235);})[_0xcbf4('0x45')](function(_0x32c2ea){return _0x122be3(_0x32c2ea);});});}exports[_0xcbf4('0x7b')]=function(_0xb9a7a2,_0x55f7fb,_0x309c60){var _0x197351;var _0x3fd6b7;var _0x52b8fd;var _0x5249fd=require('../../components/encryptor');return db[_0xcbf4('0x2b')][_0xcbf4('0x7c')]({'where':{'id':_0xb9a7a2['params']['id']}})[_0xcbf4('0x25')](function(_0x228af4){if(_0x228af4){var _0xcc5c1d=util['format'](_0xcbf4('0x50'),_0x228af4[_0xcbf4('0x4f')]);if(fs[_0xcbf4('0x51')](_0xcc5c1d)){cypher=!![];return _0x5249fd[_0xcbf4('0x52')](_0xcc5c1d,_0x228af4[_0xcbf4('0x4f')],config[_0xcbf4('0x53')][_0xcbf4('0x60')])['then'](function(){return _0x228af4;});}return _0x228af4;}})['then'](function(_0x19fd3b){if(!_0x19fd3b){throw new db[(_0xcbf4('0x54'))][(_0xcbf4('0x55'))](_0xcbf4('0x7d'));}_0x3fd6b7=_0x19fd3b;return db[_0xcbf4('0x7e')][_0xcbf4('0x7c')]({'where':{'id':0x1}});})['then'](handleEntityNotFound(_0x55f7fb,null))[_0xcbf4('0x25')](function(_0x46e599){if(_0x46e599){_0x197351=_0x46e599;if(!_0x197351[_0xcbf4('0x7f')]||!_0x197351[_0xcbf4('0x80')]||!_0x197351['transcribeRegion']||!_0x197351['language']||!_0x197351[_0xcbf4('0x73')]){throw new db[(_0xcbf4('0x54'))][(_0xcbf4('0x55'))](_0xcbf4('0x81'));}if(_0xb9a7a2[_0xcbf4('0x4a')]['runSentiment']&&(!_0x197351['sentiment']||!_0x197351[_0xcbf4('0x82')]||!_0x197351[_0xcbf4('0x83')]||!_0x197351[_0xcbf4('0x84')]||!_0x197351['bucket'])){throw new db[(_0xcbf4('0x54'))][(_0xcbf4('0x55'))](_0xcbf4('0x85'));}return db[_0xcbf4('0x86')][_0xcbf4('0x7c')]({'where':{'id':_0x197351[_0xcbf4('0x80')]}});}})[_0xcbf4('0x25')](function(_0x17d69e){if(!_0x17d69e){throw new db[(_0xcbf4('0x54'))][(_0xcbf4('0x55'))](_0xcbf4('0x87'));}if(!_0x17d69e['data1']||!_0x17d69e[_0xcbf4('0x88')]){throw new db[(_0xcbf4('0x54'))][(_0xcbf4('0x55'))](_0xcbf4('0x89'));}_0x52b8fd=_0x17d69e;return getBucketslist(_0x52b8fd[_0xcbf4('0x8a')],_0x52b8fd['data2'],_0x197351[_0xcbf4('0x8b')]);})[_0xcbf4('0x25')](function(_0x34fd3e){if(_0x34fd3e&&_0x34fd3e['Buckets']){var _0x2f92b5=_[_0xcbf4('0x48')](_0x34fd3e[_0xcbf4('0x8c')],function(_0x4cec2c){return _0x4cec2c[_0xcbf4('0x8d')]===_0x197351[_0xcbf4('0x73')];});if(!_0x2f92b5){logger[_0xcbf4('0x63')](util[_0xcbf4('0x32')]('[RUNTRANSCRIPT][%d]\x20Bucket\x20%s\x20not\x20available',_0xb9a7a2[_0xcbf4('0x46')]['id'],_0x197351[_0xcbf4('0x73')]));return createBucket(_0x52b8fd['data1'],_0x52b8fd[_0xcbf4('0x88')],_0x197351['transcribeRegion'],_0x197351[_0xcbf4('0x73')]);}logger[_0xcbf4('0x63')](util['format'](_0xcbf4('0x8e'),_0xb9a7a2['params']['id'],_0x197351[_0xcbf4('0x73')]));return;}})[_0xcbf4('0x25')](function(_0x102822){if(_0x3fd6b7[_0xcbf4('0x8f')]===_0xcbf4('0x90')){return transcribe(_0xb9a7a2['params']['id'],_0x52b8fd[_0xcbf4('0x8a')],_0x52b8fd[_0xcbf4('0x88')],_0x197351[_0xcbf4('0x8b')],_0x197351['bucket'],_0x3fd6b7[_0xcbf4('0x4f')],_0x197351[_0xcbf4('0x84')]);}else{logger[_0xcbf4('0x63')](util['format'](_0xcbf4('0x91'),_0xb9a7a2[_0xcbf4('0x46')]['id']));return{'transcribeStatus':'IN_PROGRESS'};}})[_0xcbf4('0x25')](function(_0x17f196){if(_0x17f196){_0x17f196[_0xcbf4('0x92')]=_0xb9a7a2[_0xcbf4('0x4a')]['runSentiment'];return _0x3fd6b7[_0xcbf4('0x93')](_0x17f196);}})[_0xcbf4('0x25')](respondWithResult(_0x55f7fb,null))[_0xcbf4('0x45')](handleError(_0x55f7fb,null));};function writeFile(_0x1bcd7d,_0x13e563){return new Promise(function(_0x4f1c04,_0x3632c4){fs[_0xcbf4('0x94')](_0x13e563,_0x1bcd7d,function(_0x247072,_0x220542){if(_0x247072){return _0x3632c4(_0x247072);}else{return _0x4f1c04(_0x220542);}});});}exports[_0xcbf4('0x95')]=function(_0x46d1e8,_0x3a930e,_0x541e7a){return db[_0xcbf4('0x2b')][_0xcbf4('0x7c')]({'where':{'id':_0x46d1e8[_0xcbf4('0x46')]['id']}})[_0xcbf4('0x25')](handleEntityNotFound(_0x3a930e))[_0xcbf4('0x25')](function(_0x2cce43){if(_0x2cce43&&_0x2cce43['fileText']){var _0xc48f0b=_0x2cce43[_0xcbf4('0x96')];var _0x878564=config['root']+_0xcbf4('0x97')+_0x2cce43['id']+_0xcbf4('0x98');if(fs[_0xcbf4('0x51')](_0x878564)){return _0x878564;}return writeFile(_0xc48f0b,_0x878564)['then'](function(){return _0x878564;});}else{throw new db[(_0xcbf4('0x54'))][(_0xcbf4('0x55'))](_0xcbf4('0x99'));}})[_0xcbf4('0x25')](function(_0x2c0519){return _0x3a930e[_0xcbf4('0x4c')](_0x2c0519);})[_0xcbf4('0x45')](handleError(_0x3a930e));};