90ca57f5530b490fa35111ec8fa82f391319a407
[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 _0x054f=['[RUNTRANSCRIPT][%d]\x20Bucket\x20%s\x20not\x20available','[RUNTRANSCRIPT][%d]\x20Bucket\x20%s\x20available','transcribeStatus','IN_PROGRESS','tempSentiment','updateAttributes','writeFile','fileText','root','/server/files/transcribes/transcribe_','.txt','Transcript\x20not\x20available','rimraf','fast-json-patch','bluebird','mustache','util','path','sox','to-csv','ejs','fs-extra','squel','crypto','jsforce','desk.js','querystring','uuid/v4','ioredis','../../components/auth/service','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','sendStatus','status','json','undefined','limit','count','offset','Content-Range','apply','save','update','then','destroy','end','stack','name','send','index','map','VoiceRecording','rawAttributes','fieldName','key','model','query','keys','filters','attributes','fields','length','nolimit','order','sort','where','pick','merge','type','VIRTUAL','filter','options','includeAll','findAll','rows','catch','params','intersection','include','find','create','body','describe','download','../../components/encryptor','uniqueid','value','%s.cypher','existsSync','decryptFile','secrets','recording','Sequelize','filename','extname','unlink','message','VoiceRecording\x20not\x20found','sequelize','MD5','col','token','push','ValidationError','info','\x22\x20trovato\x20eseguo\x20la\x20cancellazione','unlinkSync','isNil','File:\x20\x22','listBuckets','createBucket','TranscribeService','format','basename','readFileSync','[RUNTRANSCRIPT][%d]\x20Voice\x20recording\x20uploaded\x20in\x20bucket\x20%s\x20(%s)','Location','bucket','Bucket','[RUNTRANSCRIPT][%d]\x20Transcription\x20job\x20%s\x20created','TranscriptionJob','TranscriptionJobName','transcribeName','runTranscribe','findOne','Voice\x20Recording\x20not\x20found','transcribe','transcribeAccountId','transcribeRegion','Transcribe\x20not\x20configured','sentiment','sentimentAccountId','sentimentRegion','language','Sentiment\x20Analysis\x20not\x20configured','CloudProvider','data1','data2','Cloud\x20Provider\x20not\x20configured','Name'];(function(_0x21b293,_0x352a44){var _0xd73e84=function(_0x16916b){while(--_0x16916b){_0x21b293['push'](_0x21b293['shift']());}};_0xd73e84(++_0x352a44);}(_0x054f,0x9d));var _0xf054=function(_0x5d08de,_0x44e601){_0x5d08de=_0x5d08de-0x0;var _0x5a2fae=_0x054f[_0x5d08de];return _0x5a2fae;};'use strict';var emlformat=require('eml-format');var rimraf=require(_0xf054('0x0'));var zipdir=require('zip-dir');var jsonpatch=require(_0xf054('0x1'));var rp=require('request-promise');var moment=require('moment');var BPromise=require(_0xf054('0x2'));var Mustache=require(_0xf054('0x3'));var util=require(_0xf054('0x4'));var path=require(_0xf054('0x5'));var sox=require(_0xf054('0x6'));var csv=require(_0xf054('0x7'));var ejs=require(_0xf054('0x8'));var fs=require('fs');var fs_extra=require(_0xf054('0x9'));var _=require('lodash');var squel=require(_0xf054('0xa'));var crypto=require(_0xf054('0xb'));var jsforce=require(_0xf054('0xc'));var deskjs=require(_0xf054('0xd'));var toCsv=require(_0xf054('0x7'));var querystring=require(_0xf054('0xe'));var Papa=require('papaparse');var AWS=require('aws-sdk');var uuidv4=require(_0xf054('0xf'));var Redis=require(_0xf054('0x10'));var authService=require(_0xf054('0x11'));var qs=require('../../components/parsers/qs');var as=require(_0xf054('0x12'));var hardwareService=require(_0xf054('0x13'));var logger=require(_0xf054('0x14'))('api');var utils=require(_0xf054('0x15'));var config=require(_0xf054('0x16'));var licenseUtil=require(_0xf054('0x17'));var db=require(_0xf054('0x18'))['db'];function respondWithStatusCode(_0x40e14b,_0x2eee94){_0x2eee94=_0x2eee94||0xcc;return function(_0x4c52e9){if(_0x4c52e9){return _0x40e14b[_0xf054('0x19')](_0x2eee94);}return _0x40e14b[_0xf054('0x1a')](_0x2eee94)['end']();};}function respondWithResult(_0x2dbf11,_0x27e4fb){_0x27e4fb=_0x27e4fb||0xc8;return function(_0x47e3f4){if(_0x47e3f4){return _0x2dbf11[_0xf054('0x1a')](_0x27e4fb)[_0xf054('0x1b')](_0x47e3f4);}};}function respondWithFilteredResult(_0x56fd0c,_0x1587de){return function(_0xd8ed90){if(_0xd8ed90){var _0x5f4b39=typeof _0x1587de['offset']===_0xf054('0x1c')&&typeof _0x1587de[_0xf054('0x1d')]===_0xf054('0x1c');var _0x49dd81=_0xd8ed90[_0xf054('0x1e')];var _0x1ea90c=_0x5f4b39?0x0:_0x1587de[_0xf054('0x1f')];var _0x306549=_0x5f4b39?_0xd8ed90['count']:_0x1587de[_0xf054('0x1f')]+_0x1587de[_0xf054('0x1d')];var _0x332d20;if(_0x306549>=_0x49dd81){_0x306549=_0x49dd81;_0x332d20=0xc8;}else{_0x332d20=0xce;}_0x56fd0c['status'](_0x332d20);return _0x56fd0c['set'](_0xf054('0x20'),_0x1ea90c+'-'+_0x306549+'/'+_0x49dd81)[_0xf054('0x1b')](_0xd8ed90);}return null;};}function patchUpdates(_0x47791a){return function(_0x7c083){try{jsonpatch[_0xf054('0x21')](_0x7c083,_0x47791a,!![]);}catch(_0x281a94){return BPromise['reject'](_0x281a94);}return _0x7c083[_0xf054('0x22')]();};}function saveUpdates(_0x2e00cb,_0x1e341b){return function(_0x1bf2d0){if(_0x1bf2d0){return _0x1bf2d0[_0xf054('0x23')](_0x2e00cb)[_0xf054('0x24')](function(_0x4c7349){return _0x4c7349;});}return null;};}function removeEntity(_0x598d4f,_0x5d4623){return function(_0x359d59){if(_0x359d59){return _0x359d59[_0xf054('0x25')]()[_0xf054('0x24')](function(){_0x598d4f[_0xf054('0x1a')](0xcc)[_0xf054('0x26')]();});}};}function handleEntityNotFound(_0x437b78,_0x10e631){return function(_0x15817f){if(!_0x15817f){_0x437b78[_0xf054('0x19')](0x194);}return _0x15817f;};}function handleError(_0x13a309,_0x1877de){_0x1877de=_0x1877de||0x1f4;return function(_0x569db1){logger['error'](_0x569db1[_0xf054('0x27')]);if(_0x569db1[_0xf054('0x28')]){delete _0x569db1['name'];}_0x13a309[_0xf054('0x1a')](_0x1877de)[_0xf054('0x29')](_0x569db1);};}exports[_0xf054('0x2a')]=function(_0x197b7d,_0x7c372c){var _0x2df765={},_0xa50096={},_0x16ca4b={'count':0x0,'rows':[]};var _0x4af5fe=_[_0xf054('0x2b')](db[_0xf054('0x2c')][_0xf054('0x2d')],function(_0x25cff6){return{'name':_0x25cff6[_0xf054('0x2e')],'type':_0x25cff6['type'][_0xf054('0x2f')]};});_0xa50096[_0xf054('0x30')]=_['differenceBy'](_['map'](_0x4af5fe,_0xf054('0x28')),['format']);_0xa50096[_0xf054('0x31')]=_[_0xf054('0x32')](_0x197b7d[_0xf054('0x31')]);_0xa50096[_0xf054('0x33')]=_['intersection'](_0xa50096[_0xf054('0x30')],_0xa50096['query']);_0x2df765[_0xf054('0x34')]=_['intersection'](_0xa50096[_0xf054('0x30')],qs['fields'](_0x197b7d[_0xf054('0x31')][_0xf054('0x35')]));_0x2df765[_0xf054('0x34')]=_0x2df765[_0xf054('0x34')][_0xf054('0x36')]?_0x2df765[_0xf054('0x34')]:_0xa50096[_0xf054('0x30')];if(!_0x197b7d['query']['hasOwnProperty'](_0xf054('0x37'))){_0x2df765[_0xf054('0x1d')]=qs['limit'](_0x197b7d[_0xf054('0x31')][_0xf054('0x1d')]);_0x2df765['offset']=qs[_0xf054('0x1f')](_0x197b7d[_0xf054('0x31')][_0xf054('0x1f')]);}_0x2df765[_0xf054('0x38')]=qs[_0xf054('0x39')](_0x197b7d[_0xf054('0x31')]['sort']);_0x2df765[_0xf054('0x3a')]=qs[_0xf054('0x33')](_[_0xf054('0x3b')](_0x197b7d[_0xf054('0x31')],_0xa50096[_0xf054('0x33')]),_0x4af5fe);if(_0x197b7d[_0xf054('0x31')]['filter']){_0x2df765[_0xf054('0x3a')]=_[_0xf054('0x3c')](_0x2df765['where'],{'$or':_[_0xf054('0x2b')](_0x4af5fe,function(_0x47c1c9){if(_0x47c1c9[_0xf054('0x3d')]!==_0xf054('0x3e')){var _0x5b6e2e={};_0x5b6e2e[_0x47c1c9[_0xf054('0x28')]]={'$like':'%'+_0x197b7d[_0xf054('0x31')][_0xf054('0x3f')]+'%'};return _0x5b6e2e;}})});}_0x2df765=_[_0xf054('0x3c')]({},_0x2df765,_0x197b7d[_0xf054('0x40')]);var _0x5b9e1d={'where':_0x2df765[_0xf054('0x3a')]};return db[_0xf054('0x2c')][_0xf054('0x1e')](_0x5b9e1d)[_0xf054('0x24')](function(_0x2265bf){_0x16ca4b[_0xf054('0x1e')]=_0x2265bf;if(_0x197b7d['query'][_0xf054('0x41')]){_0x2df765['include']=[{'all':!![]}];}return db['VoiceRecording'][_0xf054('0x42')](_0x2df765);})[_0xf054('0x24')](function(_0x2a1ff1){_0x16ca4b[_0xf054('0x43')]=_0x2a1ff1;return _0x16ca4b;})[_0xf054('0x24')](respondWithFilteredResult(_0x7c372c,_0x2df765))[_0xf054('0x44')](handleError(_0x7c372c,null));};exports['show']=function(_0x31c3cb,_0x292ff3){var _0x5989e5={'raw':![],'where':{'id':_0x31c3cb[_0xf054('0x45')]['id']}},_0x3e54e6={};_0x3e54e6['model']=_[_0xf054('0x32')](db[_0xf054('0x2c')][_0xf054('0x2d')]);_0x3e54e6['query']=_[_0xf054('0x32')](_0x31c3cb[_0xf054('0x31')]);_0x3e54e6['filters']=_[_0xf054('0x46')](_0x3e54e6['model'],_0x3e54e6[_0xf054('0x31')]);_0x5989e5['attributes']=_[_0xf054('0x46')](_0x3e54e6[_0xf054('0x30')],qs[_0xf054('0x35')](_0x31c3cb[_0xf054('0x31')][_0xf054('0x35')]));_0x5989e5[_0xf054('0x34')]=_0x5989e5[_0xf054('0x34')][_0xf054('0x36')]?_0x5989e5['attributes']:_0x3e54e6[_0xf054('0x30')];if(_0x31c3cb[_0xf054('0x31')][_0xf054('0x41')]){_0x5989e5[_0xf054('0x47')]=[{'all':!![]}];}_0x5989e5=_[_0xf054('0x3c')]({},_0x5989e5,_0x31c3cb[_0xf054('0x40')]);return db[_0xf054('0x2c')][_0xf054('0x48')](_0x5989e5)['then'](handleEntityNotFound(_0x292ff3,null))['then'](respondWithResult(_0x292ff3,null))[_0xf054('0x44')](handleError(_0x292ff3,null));};exports[_0xf054('0x49')]=function(_0x5a5ea0,_0x3ad366){return db[_0xf054('0x2c')][_0xf054('0x49')](_0x5a5ea0[_0xf054('0x4a')],{})[_0xf054('0x24')](respondWithResult(_0x3ad366,0xc9))[_0xf054('0x44')](handleError(_0x3ad366,null));};exports[_0xf054('0x23')]=function(_0x3aa7c4,_0x13e04e){if(_0x3aa7c4['body']['id']){delete _0x3aa7c4[_0xf054('0x4a')]['id'];}return db['VoiceRecording'][_0xf054('0x48')]({'where':{'id':_0x3aa7c4[_0xf054('0x45')]['id']}})['then'](handleEntityNotFound(_0x13e04e,null))[_0xf054('0x24')](saveUpdates(_0x3aa7c4['body'],null))[_0xf054('0x24')](respondWithResult(_0x13e04e,null))[_0xf054('0x44')](handleError(_0x13e04e,null));};exports[_0xf054('0x4b')]=function(_0x3a509b,_0x3d5eb5){return db[_0xf054('0x2c')]['describe']()[_0xf054('0x24')](respondWithResult(_0x3d5eb5,null))[_0xf054('0x44')](handleError(_0x3d5eb5,null));};exports[_0xf054('0x4c')]=function(_0x178bf5,_0x364469,_0x17fc5d){var _0x3bae3c=require(_0xf054('0x4d'));var _0x3ef352=![];var _0xda1b2a={};if(_0x178bf5[_0xf054('0x31')]['type']&&_0x178bf5[_0xf054('0x31')][_0xf054('0x3d')]===_0xf054('0x4e')){_0xda1b2a[_0xf054('0x4e')]=_0x178bf5[_0xf054('0x45')]['id'];}else{_0xda1b2a['id']=_0x178bf5[_0xf054('0x45')]['id'];}return db['VoiceRecording']['find']({'where':_0xda1b2a,'attributes':['id',_0xf054('0x4f')],'raw':!![]})['then'](handleEntityNotFound(_0x364469,null))['then'](function(_0x75f135){if(_0x75f135){var _0x546de2=_0x75f135[_0xf054('0x4f')];var _0x3f047a=util['format'](_0xf054('0x50'),_0x546de2);if(fs[_0xf054('0x51')](_0x3f047a)){_0x3ef352=!![];return _0x3bae3c[_0xf054('0x52')](_0x3f047a,_0x546de2,config[_0xf054('0x53')][_0xf054('0x54')])['then'](function(){return _0x75f135;});}return _0x75f135;}})[_0xf054('0x24')](function(_0x4a4116){if(_0x4a4116){var _0x1d68d2=_0x4a4116[_0xf054('0x4f')];if(!fs[_0xf054('0x51')](_0x1d68d2)){throw new db[(_0xf054('0x55'))]['ValidationError']('VoiceRecording\x20not\x20found');}if(_0x4a4116[_0xf054('0x56')]){return _0x364469[_0xf054('0x4c')](_0x1d68d2,_0x4a4116[_0xf054('0x56')]+path[_0xf054('0x57')](_0x1d68d2),function(){if(_0x3ef352){fs[_0xf054('0x58')](_0x1d68d2);}});}else{return _0x364469[_0xf054('0x4c')](_0x1d68d2,function(_0xf65447){if(_0x3ef352){fs[_0xf054('0x58')](_0x1d68d2);}});}}})['catch'](function(_0x523364){if(_0x523364[_0xf054('0x59')]===_0xf054('0x5a')){_0x364469['status'](0x194)['send']('Not\x20found');}else{return handleError(_0x364469,null);}});};exports['downloads']=function(_0x3b0c88,_0x1419c1,_0x5e6c7e){var _0x4d78c4=require('../../components/encryptor');var _0x45385c=![];var _0x2b31b5={'$and':[db[_0xf054('0x5b')][_0xf054('0x3a')](db[_0xf054('0x5b')]['fn'](_0xf054('0x5c'),db[_0xf054('0x5b')][_0xf054('0x5d')](_0xf054('0x4e'))),_0x3b0c88[_0xf054('0x31')][_0xf054('0x5e')])]};if(_0x3b0c88[_0xf054('0x31')][_0xf054('0x3d')]&&_0x3b0c88[_0xf054('0x31')][_0xf054('0x3d')]===_0xf054('0x4e')){_0x2b31b5['$and'][_0xf054('0x5f')]({'uniqueid':_0x3b0c88[_0xf054('0x45')]['id']});}else{_0x2b31b5['$and'][_0xf054('0x5f')]({'id':_0x3b0c88[_0xf054('0x45')]['id']});}return db[_0xf054('0x2c')][_0xf054('0x48')]({'where':_0x2b31b5,'attributes':['id',_0xf054('0x4f')],'raw':!![]})['then'](handleEntityNotFound(_0x1419c1,null))[_0xf054('0x24')](function(_0x4c2356){if(_0x4c2356){var _0x1a1efe=util['format'](_0xf054('0x50'),_0x4c2356[_0xf054('0x4f')]);if(fs[_0xf054('0x51')](_0x1a1efe)){_0x45385c=!![];return _0x4d78c4[_0xf054('0x52')](_0x1a1efe,_0x4c2356[_0xf054('0x4f')],config[_0xf054('0x53')][_0xf054('0x54')])[_0xf054('0x24')](function(){return _0x4c2356;});}return _0x4c2356;}})[_0xf054('0x24')](function(_0x4967d1){if(_0x4967d1){if(!fs[_0xf054('0x51')](_0x4967d1['value'])){throw new db[(_0xf054('0x55'))][(_0xf054('0x60'))](_0xf054('0x5a'));}if(_0x4967d1[_0xf054('0x56')]){return _0x1419c1[_0xf054('0x4c')](_0x4967d1['value'],_0x4967d1[_0xf054('0x56')]+path[_0xf054('0x57')](_0x4967d1[_0xf054('0x4f')]),function(){if(_0x45385c){fs[_0xf054('0x58')](_0x4967d1[_0xf054('0x4f')]);}});}else{return _0x1419c1[_0xf054('0x4c')](_0x4967d1[_0xf054('0x4f')],function(_0x13129e){if(_0x45385c){fs['unlink'](_0x4967d1[_0xf054('0x4f')]);}});}}})[_0xf054('0x44')](handleError(_0x1419c1,null));};exports[_0xf054('0x25')]=function(_0x331dde,_0x40c2e2){return db[_0xf054('0x2c')]['find']({'where':{'id':_0x331dde['params']['id']}})[_0xf054('0x24')](function(_0x55a077){if(_['isNil'](_0x55a077)){throw new ReferenceError('Entity\x20not\x20found');}return _0x55a077;})[_0xf054('0x24')](function(_0x3f67eb){var _0x349dde=_0x3f67eb[_0xf054('0x4f')];logger['info']('cancellazione\x20fisica\x20documento\x20%s',_0x349dde);if(!_['isNil'](_0x3f67eb[_0xf054('0x4f')])&&fs[_0xf054('0x51')](_0x349dde)){logger[_0xf054('0x61')]('File:\x20\x22'+_0x349dde+_0xf054('0x62'));fs[_0xf054('0x63')](_0x349dde);}_0x349dde=_0x349dde+'.cypher';if(!_[_0xf054('0x64')](_0x3f67eb['value'])&&fs[_0xf054('0x51')](_0x349dde)){logger['info'](_0xf054('0x65')+_0x349dde+_0xf054('0x62'));fs['unlinkSync'](_0x349dde);}return _0x3f67eb;})[_0xf054('0x24')](function(_0x56456f){if(!_0x56456f)throw new InternalError();return _0x56456f[_0xf054('0x25')]();})[_0xf054('0x24')](function(){_0x40c2e2[_0xf054('0x1a')](0xcc)['end']();})[_0xf054('0x44')](handleError(_0x40c2e2,null));};function getBucketslist(_0x29c1d0,_0x443611,_0x5d7f88){return new Promise(function(_0x27d7ab,_0x1af28e){var _0x32f5b6=new AWS['S3']({'accessKeyId':_0x443611,'secretAccessKey':_0x29c1d0,'region':_0x5d7f88});_0x32f5b6[_0xf054('0x66')]({},function(_0x39cda6,_0xb1f969){if(_0x39cda6){return _0x1af28e(_0x39cda6);}else{return _0x27d7ab(_0xb1f969);}});});}function createBucket(_0x129537,_0x1a5e08,_0x5b8cc6,_0x2133a5){return new Promise(function(_0x5bf143,_0x424836){var _0x52c102=new AWS['S3']({'accessKeyId':_0x1a5e08,'secretAccessKey':_0x129537,'region':_0x5b8cc6});_0x52c102[_0xf054('0x67')]({'Bucket':_0x2133a5},function(_0x28b49e,_0x57b6ad){if(_0x28b49e){return _0x424836(_0x28b49e);}else{return _0x5bf143(_0x57b6ad);}});});}function uploadFile(_0x1c0df8,_0x3e1691,_0x51be99,_0x8318d6,_0x3ca404,_0x1a1457){return new Promise(function(_0x9cc12f,_0x100816){var _0x28d6be=new AWS['S3']({'accessKeyId':_0x3e1691,'secretAccessKey':_0x1c0df8,'region':_0x51be99});_0x28d6be['upload']({'Bucket':_0x8318d6,'Key':_0x3ca404,'Body':_0x1a1457},function(_0x321e46,_0x1c9cc0){if(_0x321e46){return _0x100816(_0x321e46);}else{return _0x9cc12f(_0x1c9cc0);}});});}function startTranscribe(_0x5eed48,_0x1554f8,_0x8b0b83,_0x396432,_0x40de65,_0x3a7fee){return new Promise(function(_0x1fdf87,_0x5db0d8){var _0x2b45f7=new AWS[(_0xf054('0x68'))]({'accessKeyId':_0x1554f8,'secretAccessKey':_0x5eed48,'region':_0x8b0b83});_0x2b45f7['startTranscriptionJob']({'TranscriptionJobName':_0x396432,'LanguageCode':_0x40de65,'Media':{'MediaFileUri':_0x3a7fee}},function(_0x86dfaa,_0x358564){if(_0x86dfaa){return _0x5db0d8(_0x86dfaa);}else{return _0x1fdf87(_0x358564);}});});}function transcribe(_0x32ff8e,_0x50ea15,_0x761057,_0x3bd143,_0x5ef071,_0x45d560,_0x2bff62){return new Promise(function(_0x354204,_0x574606){var _0x3d5b39={};logger[_0xf054('0x61')](util[_0xf054('0x69')]('[RUNTRANSCRIPT][%d]\x20Starting\x20voice\x20recording\x20upload\x20in\x20bucket\x20%s',_0x32ff8e,_0x5ef071));return uploadFile(_0x50ea15,_0x761057,_0x3bd143,_0x5ef071,path[_0xf054('0x6a')](_0x45d560),fs[_0xf054('0x6b')](_0x45d560))[_0xf054('0x24')](function(_0x3d4687){logger[_0xf054('0x61')](util[_0xf054('0x69')](_0xf054('0x6c'),_0x32ff8e,_0x5ef071,_0x3d4687[_0xf054('0x6d')]));_0x3d5b39[_0xf054('0x6e')]=_0x3d4687[_0xf054('0x6f')];_0x3d5b39['location']=_0x3d4687[_0xf054('0x6d')];logger[_0xf054('0x61')](util[_0xf054('0x69')]('[RUNTRANSCRIPT][%d]\x20Sending\x20transcribe\x20request',_0x32ff8e));return startTranscribe(_0x50ea15,_0x761057,_0x3bd143,uuidv4(),_0x2bff62,_0x3d4687[_0xf054('0x6d')]);})[_0xf054('0x24')](function(_0x132df0){logger[_0xf054('0x61')](util[_0xf054('0x69')](_0xf054('0x70'),_0x32ff8e,_0x132df0[_0xf054('0x71')][_0xf054('0x72')]));_0x3d5b39[_0xf054('0x73')]=_0x132df0[_0xf054('0x71')][_0xf054('0x72')];_0x3d5b39['transcribeStatus']=_0x132df0['TranscriptionJob']['TranscriptionJobStatus'];return _0x354204(_0x3d5b39);})[_0xf054('0x44')](function(_0x149924){return _0x574606(_0x149924);});});}exports[_0xf054('0x74')]=function(_0x21bda6,_0x58eb6f,_0x34b96c){var _0x48634c;var _0x25746b;var _0x14b8ed;var _0x3a5637=require(_0xf054('0x4d'));return db[_0xf054('0x2c')][_0xf054('0x75')]({'where':{'id':_0x21bda6[_0xf054('0x45')]['id']}})['then'](function(_0x3fcf90){if(_0x3fcf90){var _0x13c485=util[_0xf054('0x69')](_0xf054('0x50'),_0x3fcf90[_0xf054('0x4f')]);if(fs['existsSync'](_0x13c485)){cypher=!![];return _0x3a5637[_0xf054('0x52')](_0x13c485,_0x3fcf90[_0xf054('0x4f')],config[_0xf054('0x53')][_0xf054('0x54')])[_0xf054('0x24')](function(){return _0x3fcf90;});}return _0x3fcf90;}})[_0xf054('0x24')](function(_0x23b6dd){if(!_0x23b6dd){throw new db['Sequelize'][(_0xf054('0x60'))](_0xf054('0x76'));}_0x25746b=_0x23b6dd;return db['Setting'][_0xf054('0x75')]({'where':{'id':0x1}});})[_0xf054('0x24')](handleEntityNotFound(_0x58eb6f,null))[_0xf054('0x24')](function(_0xa0119c){if(_0xa0119c){_0x48634c=_0xa0119c;if(!_0x48634c[_0xf054('0x77')]||!_0x48634c[_0xf054('0x78')]||!_0x48634c[_0xf054('0x79')]||!_0x48634c['language']||!_0x48634c[_0xf054('0x6e')]){throw new db[(_0xf054('0x55'))]['ValidationError'](_0xf054('0x7a'));}if(_0x21bda6['body']['runSentiment']&&(!_0x48634c[_0xf054('0x7b')]||!_0x48634c[_0xf054('0x7c')]||!_0x48634c[_0xf054('0x7d')]||!_0x48634c[_0xf054('0x7e')]||!_0x48634c['bucket'])){throw new db[(_0xf054('0x55'))][(_0xf054('0x60'))](_0xf054('0x7f'));}return db[_0xf054('0x80')]['findOne']({'where':{'id':_0x48634c['transcribeAccountId']}});}})[_0xf054('0x24')](function(_0xfdef1e){if(!_0xfdef1e){throw new db['Sequelize'][(_0xf054('0x60'))]('Cloud\x20Provider\x20not\x20available');}if(!_0xfdef1e[_0xf054('0x81')]||!_0xfdef1e[_0xf054('0x82')]){throw new db['Sequelize'][(_0xf054('0x60'))](_0xf054('0x83'));}_0x14b8ed=_0xfdef1e;return getBucketslist(_0x14b8ed[_0xf054('0x81')],_0x14b8ed['data2'],_0x48634c['transcribeRegion']);})[_0xf054('0x24')](function(_0x4fa971){if(_0x4fa971&&_0x4fa971['Buckets']){var _0x5251b3=_[_0xf054('0x48')](_0x4fa971['Buckets'],function(_0xd7f1d3){return _0xd7f1d3[_0xf054('0x84')]===_0x48634c[_0xf054('0x6e')];});if(!_0x5251b3){logger[_0xf054('0x61')](util[_0xf054('0x69')](_0xf054('0x85'),_0x21bda6[_0xf054('0x45')]['id'],_0x48634c['bucket']));return createBucket(_0x14b8ed[_0xf054('0x81')],_0x14b8ed['data2'],_0x48634c['transcribeRegion'],_0x48634c[_0xf054('0x6e')]);}logger[_0xf054('0x61')](util[_0xf054('0x69')](_0xf054('0x86'),_0x21bda6[_0xf054('0x45')]['id'],_0x48634c[_0xf054('0x6e')]));return;}})[_0xf054('0x24')](function(_0x540e7f){if(_0x25746b[_0xf054('0x87')]==='NEW'){return transcribe(_0x21bda6['params']['id'],_0x14b8ed[_0xf054('0x81')],_0x14b8ed[_0xf054('0x82')],_0x48634c[_0xf054('0x79')],_0x48634c[_0xf054('0x6e')],_0x25746b[_0xf054('0x4f')],_0x48634c['language']);}else{logger[_0xf054('0x61')](util[_0xf054('0x69')]('[RUNTRANSCRIPT][%d]\x20Transcript\x20action\x20already\x20requested',_0x21bda6[_0xf054('0x45')]['id']));return{'transcribeStatus':_0xf054('0x88')};}})['then'](function(_0x5e619b){if(_0x5e619b){_0x5e619b[_0xf054('0x89')]=_0x21bda6[_0xf054('0x4a')]['runSentiment'];return _0x25746b[_0xf054('0x8a')](_0x5e619b);}})['then'](respondWithResult(_0x58eb6f,null))[_0xf054('0x44')](handleError(_0x58eb6f,null));};function writeFile(_0x23f1d4,_0x58dd3f){return new Promise(function(_0xbf316b,_0x5c499b){fs[_0xf054('0x8b')](_0x58dd3f,_0x23f1d4,function(_0x5758d7,_0x4241a6){if(_0x5758d7){return _0x5c499b(_0x5758d7);}else{return _0xbf316b(_0x4241a6);}});});}exports['downloadTranscribe']=function(_0x5ac6f0,_0x3d2014,_0x2bb5f5){return db[_0xf054('0x2c')][_0xf054('0x75')]({'where':{'id':_0x5ac6f0['params']['id']}})[_0xf054('0x24')](handleEntityNotFound(_0x3d2014))[_0xf054('0x24')](function(_0xc4b86b){if(_0xc4b86b&&_0xc4b86b['fileText']){var _0x2d7a96=_0xc4b86b[_0xf054('0x8c')];var _0x1264e6=config[_0xf054('0x8d')]+_0xf054('0x8e')+_0xc4b86b['id']+_0xf054('0x8f');if(fs[_0xf054('0x51')](_0x1264e6)){return _0x1264e6;}return writeFile(_0x2d7a96,_0x1264e6)['then'](function(){return _0x1264e6;});}else{throw new db['Sequelize'][(_0xf054('0x60'))](_0xf054('0x90'));}})[_0xf054('0x24')](function(_0x5b9d2d){return _0x3d2014[_0xf054('0x4c')](_0x5b9d2d);})['catch'](handleError(_0x3d2014));};