d78739dc8cc9a5f38ef4e7fffd65b2808a7f61f2
[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 _0x70c2=['bluebird','path','sox','to-csv','fs-extra','crypto','jsforce','desk.js','querystring','papaparse','aws-sdk','uuid/v4','ioredis','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/environment','../../config/license/util','../../mysqldb','sendStatus','status','end','json','offset','undefined','limit','count','Content-Range','apply','reject','save','update','destroy','then','error','stack','name','send','index','map','rawAttributes','fieldName','key','model','differenceBy','format','query','keys','filters','intersection','attributes','fields','hasOwnProperty','nolimit','order','where','pick','filter','merge','VIRTUAL','includeAll','include','VoiceRecording','findAll','rows','catch','params','length','options','find','create','body','describe','../../components/encryptor','type','value','%s.cypher','existsSync','decryptFile','Sequelize','VoiceRecording\x20not\x20found','filename','extname','download','unlink','message','Not\x20found','sequelize','MD5','col','uniqueid','token','$and','push','recording','ValidationError','isNil','Entity\x20not\x20found','info','cancellazione\x20fisica\x20documento\x20%s','File:\x20\x22','\x22\x20trovato\x20eseguo\x20la\x20cancellazione','unlinkSync','listBuckets','createBucket','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','bucket','location','[RUNTRANSCRIPT][%d]\x20Transcription\x20job\x20%s\x20created','TranscriptionJob','TranscriptionJobName','transcribeName','transcribeStatus','runTranscribe','findOne','secrets','Voice\x20Recording\x20not\x20found','Setting','transcribe','transcribeAccountId','transcribeRegion','language','Transcribe\x20not\x20configured','runSentiment','sentimentAccountId','Sentiment\x20Analysis\x20not\x20configured','CloudProvider','data1','data2','Buckets','Name','[RUNTRANSCRIPT][%d]\x20Bucket\x20%s\x20not\x20available','IN_PROGRESS','downloadTranscribe','fileText','root','/server/files/transcribes/transcribe_','.txt','eml-format','rimraf','zip-dir','request-promise','moment'];(function(_0x411add,_0x1aed38){var _0x238242=function(_0x4a1cd5){while(--_0x4a1cd5){_0x411add['push'](_0x411add['shift']());}};_0x238242(++_0x1aed38);}(_0x70c2,0x125));var _0x270c=function(_0x485904,_0x5a9e00){_0x485904=_0x485904-0x0;var _0x21f73f=_0x70c2[_0x485904];return _0x21f73f;};'use strict';var emlformat=require(_0x270c('0x0'));var rimraf=require(_0x270c('0x1'));var zipdir=require(_0x270c('0x2'));var jsonpatch=require('fast-json-patch');var rp=require(_0x270c('0x3'));var moment=require(_0x270c('0x4'));var BPromise=require(_0x270c('0x5'));var Mustache=require('mustache');var util=require('util');var path=require(_0x270c('0x6'));var sox=require(_0x270c('0x7'));var csv=require(_0x270c('0x8'));var ejs=require('ejs');var fs=require('fs');var fs_extra=require(_0x270c('0x9'));var _=require('lodash');var squel=require('squel');var crypto=require(_0x270c('0xa'));var jsforce=require(_0x270c('0xb'));var deskjs=require(_0x270c('0xc'));var toCsv=require(_0x270c('0x8'));var querystring=require(_0x270c('0xd'));var Papa=require(_0x270c('0xe'));var AWS=require(_0x270c('0xf'));var uuidv4=require(_0x270c('0x10'));var Redis=require(_0x270c('0x11'));var authService=require('../../components/auth/service');var qs=require(_0x270c('0x12'));var as=require(_0x270c('0x13'));var hardwareService=require('../../config/license/hardware');var logger=require('../../config/logger')('api');var utils=require('../../config/utils');var config=require(_0x270c('0x14'));var licenseUtil=require(_0x270c('0x15'));var db=require(_0x270c('0x16'))['db'];function respondWithStatusCode(_0x492407,_0x9ff1cb){_0x9ff1cb=_0x9ff1cb||0xcc;return function(_0x19d621){if(_0x19d621){return _0x492407[_0x270c('0x17')](_0x9ff1cb);}return _0x492407[_0x270c('0x18')](_0x9ff1cb)[_0x270c('0x19')]();};}function respondWithResult(_0x251fee,_0x20184f){_0x20184f=_0x20184f||0xc8;return function(_0x36b03a){if(_0x36b03a){return _0x251fee[_0x270c('0x18')](_0x20184f)[_0x270c('0x1a')](_0x36b03a);}};}function respondWithFilteredResult(_0x46717a,_0xb96ba8){return function(_0x329d57){if(_0x329d57){var _0x2ba56e=typeof _0xb96ba8[_0x270c('0x1b')]===_0x270c('0x1c')&&typeof _0xb96ba8[_0x270c('0x1d')]==='undefined';var _0x529874=_0x329d57[_0x270c('0x1e')];var _0x6d762a=_0x2ba56e?0x0:_0xb96ba8[_0x270c('0x1b')];var _0x1d2518=_0x2ba56e?_0x329d57[_0x270c('0x1e')]:_0xb96ba8[_0x270c('0x1b')]+_0xb96ba8[_0x270c('0x1d')];var _0x5973c2;if(_0x1d2518>=_0x529874){_0x1d2518=_0x529874;_0x5973c2=0xc8;}else{_0x5973c2=0xce;}_0x46717a['status'](_0x5973c2);return _0x46717a['set'](_0x270c('0x1f'),_0x6d762a+'-'+_0x1d2518+'/'+_0x529874)[_0x270c('0x1a')](_0x329d57);}return null;};}function patchUpdates(_0x3ed137){return function(_0x123cd9){try{jsonpatch[_0x270c('0x20')](_0x123cd9,_0x3ed137,!![]);}catch(_0x4bdfe8){return BPromise[_0x270c('0x21')](_0x4bdfe8);}return _0x123cd9[_0x270c('0x22')]();};}function saveUpdates(_0x1bb609,_0x485121){return function(_0x2a9e07){if(_0x2a9e07){return _0x2a9e07[_0x270c('0x23')](_0x1bb609)['then'](function(_0x2fe93d){return _0x2fe93d;});}return null;};}function removeEntity(_0x5a5abf,_0x9ab873){return function(_0x1991cb){if(_0x1991cb){return _0x1991cb[_0x270c('0x24')]()[_0x270c('0x25')](function(){_0x5a5abf[_0x270c('0x18')](0xcc)[_0x270c('0x19')]();});}};}function handleEntityNotFound(_0x361686,_0x41ab15){return function(_0x4d11a1){if(!_0x4d11a1){_0x361686['sendStatus'](0x194);}return _0x4d11a1;};}function handleError(_0x512a82,_0x4a697c){_0x4a697c=_0x4a697c||0x1f4;return function(_0x35a5be){logger[_0x270c('0x26')](_0x35a5be[_0x270c('0x27')]);if(_0x35a5be[_0x270c('0x28')]){delete _0x35a5be[_0x270c('0x28')];}_0x512a82['status'](_0x4a697c)[_0x270c('0x29')](_0x35a5be);};}exports[_0x270c('0x2a')]=function(_0x431c17,_0x313d0f){var _0x5f1715={},_0x138a1d={},_0xa6c825={'count':0x0,'rows':[]};var _0x255f31=_[_0x270c('0x2b')](db['VoiceRecording'][_0x270c('0x2c')],function(_0x9fdf2f){return{'name':_0x9fdf2f[_0x270c('0x2d')],'type':_0x9fdf2f['type'][_0x270c('0x2e')]};});_0x138a1d[_0x270c('0x2f')]=_[_0x270c('0x30')](_['map'](_0x255f31,_0x270c('0x28')),[_0x270c('0x31')]);_0x138a1d[_0x270c('0x32')]=_[_0x270c('0x33')](_0x431c17[_0x270c('0x32')]);_0x138a1d[_0x270c('0x34')]=_[_0x270c('0x35')](_0x138a1d['model'],_0x138a1d[_0x270c('0x32')]);_0x5f1715[_0x270c('0x36')]=_[_0x270c('0x35')](_0x138a1d[_0x270c('0x2f')],qs[_0x270c('0x37')](_0x431c17[_0x270c('0x32')]['fields']));_0x5f1715['attributes']=_0x5f1715[_0x270c('0x36')]['length']?_0x5f1715[_0x270c('0x36')]:_0x138a1d[_0x270c('0x2f')];if(!_0x431c17[_0x270c('0x32')][_0x270c('0x38')](_0x270c('0x39'))){_0x5f1715['limit']=qs[_0x270c('0x1d')](_0x431c17['query']['limit']);_0x5f1715['offset']=qs[_0x270c('0x1b')](_0x431c17[_0x270c('0x32')][_0x270c('0x1b')]);}_0x5f1715[_0x270c('0x3a')]=qs['sort'](_0x431c17[_0x270c('0x32')]['sort']);_0x5f1715[_0x270c('0x3b')]=qs[_0x270c('0x34')](_[_0x270c('0x3c')](_0x431c17[_0x270c('0x32')],_0x138a1d[_0x270c('0x34')]),_0x255f31);if(_0x431c17[_0x270c('0x32')][_0x270c('0x3d')]){_0x5f1715['where']=_[_0x270c('0x3e')](_0x5f1715[_0x270c('0x3b')],{'$or':_[_0x270c('0x2b')](_0x255f31,function(_0x24cf7e){if(_0x24cf7e['type']!==_0x270c('0x3f')){var _0x5c1933={};_0x5c1933[_0x24cf7e['name']]={'$like':'%'+_0x431c17[_0x270c('0x32')]['filter']+'%'};return _0x5c1933;}})});}_0x5f1715=_['merge']({},_0x5f1715,_0x431c17['options']);var _0x14b6da={'where':_0x5f1715[_0x270c('0x3b')]};return db['VoiceRecording'][_0x270c('0x1e')](_0x14b6da)[_0x270c('0x25')](function(_0x2aa14d){_0xa6c825[_0x270c('0x1e')]=_0x2aa14d;if(_0x431c17[_0x270c('0x32')][_0x270c('0x40')]){_0x5f1715[_0x270c('0x41')]=[{'all':!![]}];}return db[_0x270c('0x42')][_0x270c('0x43')](_0x5f1715);})[_0x270c('0x25')](function(_0x3abb90){_0xa6c825[_0x270c('0x44')]=_0x3abb90;return _0xa6c825;})[_0x270c('0x25')](respondWithFilteredResult(_0x313d0f,_0x5f1715))[_0x270c('0x45')](handleError(_0x313d0f,null));};exports['show']=function(_0x1fd983,_0x5b513c){var _0x4515c7={'raw':![],'where':{'id':_0x1fd983[_0x270c('0x46')]['id']}},_0x2facf6={};_0x2facf6[_0x270c('0x2f')]=_[_0x270c('0x33')](db[_0x270c('0x42')][_0x270c('0x2c')]);_0x2facf6[_0x270c('0x32')]=_['keys'](_0x1fd983[_0x270c('0x32')]);_0x2facf6[_0x270c('0x34')]=_[_0x270c('0x35')](_0x2facf6[_0x270c('0x2f')],_0x2facf6[_0x270c('0x32')]);_0x4515c7[_0x270c('0x36')]=_[_0x270c('0x35')](_0x2facf6[_0x270c('0x2f')],qs[_0x270c('0x37')](_0x1fd983['query']['fields']));_0x4515c7[_0x270c('0x36')]=_0x4515c7['attributes'][_0x270c('0x47')]?_0x4515c7[_0x270c('0x36')]:_0x2facf6[_0x270c('0x2f')];if(_0x1fd983[_0x270c('0x32')]['includeAll']){_0x4515c7[_0x270c('0x41')]=[{'all':!![]}];}_0x4515c7=_[_0x270c('0x3e')]({},_0x4515c7,_0x1fd983[_0x270c('0x48')]);return db['VoiceRecording'][_0x270c('0x49')](_0x4515c7)[_0x270c('0x25')](handleEntityNotFound(_0x5b513c,null))[_0x270c('0x25')](respondWithResult(_0x5b513c,null))[_0x270c('0x45')](handleError(_0x5b513c,null));};exports[_0x270c('0x4a')]=function(_0x435b62,_0x2da64e){return db[_0x270c('0x42')][_0x270c('0x4a')](_0x435b62[_0x270c('0x4b')],{})['then'](respondWithResult(_0x2da64e,0xc9))[_0x270c('0x45')](handleError(_0x2da64e,null));};exports['update']=function(_0x375c24,_0x3fb140){if(_0x375c24[_0x270c('0x4b')]['id']){delete _0x375c24['body']['id'];}return db[_0x270c('0x42')]['find']({'where':{'id':_0x375c24[_0x270c('0x46')]['id']}})[_0x270c('0x25')](handleEntityNotFound(_0x3fb140,null))[_0x270c('0x25')](saveUpdates(_0x375c24[_0x270c('0x4b')],null))[_0x270c('0x25')](respondWithResult(_0x3fb140,null))[_0x270c('0x45')](handleError(_0x3fb140,null));};exports[_0x270c('0x4c')]=function(_0x24546a,_0x1bc9bc){return db[_0x270c('0x42')][_0x270c('0x4c')]()[_0x270c('0x25')](respondWithResult(_0x1bc9bc,null))[_0x270c('0x45')](handleError(_0x1bc9bc,null));};exports['download']=function(_0x5194c5,_0x4e934c,_0x2fff94){var _0x137748=require(_0x270c('0x4d'));var _0x290f38=![];var _0x1e2e11={};if(_0x5194c5['query']['type']&&_0x5194c5[_0x270c('0x32')][_0x270c('0x4e')]==='uniqueid'){_0x1e2e11['uniqueid']=_0x5194c5[_0x270c('0x46')]['id'];}else{_0x1e2e11['id']=_0x5194c5['params']['id'];}return db['VoiceRecording'][_0x270c('0x49')]({'where':_0x1e2e11,'attributes':['id',_0x270c('0x4f')],'raw':!![]})[_0x270c('0x25')](handleEntityNotFound(_0x4e934c,null))['then'](function(_0x3315bc){if(_0x3315bc){var _0x3c8a52=_0x3315bc[_0x270c('0x4f')];var _0x450dd1=util[_0x270c('0x31')](_0x270c('0x50'),_0x3c8a52);if(fs[_0x270c('0x51')](_0x450dd1)){_0x290f38=!![];return _0x137748[_0x270c('0x52')](_0x450dd1,_0x3c8a52,config['secrets']['recording'])[_0x270c('0x25')](function(){return _0x3315bc;});}return _0x3315bc;}})['then'](function(_0x10aa3d){if(_0x10aa3d){var _0x4b3357=_0x10aa3d['value'];if(!fs[_0x270c('0x51')](_0x4b3357)){throw new db[(_0x270c('0x53'))]['ValidationError'](_0x270c('0x54'));}if(_0x10aa3d[_0x270c('0x55')]){return _0x4e934c['download'](_0x4b3357,_0x10aa3d[_0x270c('0x55')]+path[_0x270c('0x56')](_0x4b3357),function(){if(_0x290f38){fs['unlink'](_0x4b3357);}});}else{return _0x4e934c[_0x270c('0x57')](_0x4b3357,function(_0x40d9ed){if(_0x290f38){fs[_0x270c('0x58')](_0x4b3357);}});}}})['catch'](function(_0x4859d5){if(_0x4859d5[_0x270c('0x59')]===_0x270c('0x54')){_0x4e934c[_0x270c('0x18')](0x194)['send'](_0x270c('0x5a'));}else{return handleError(_0x4e934c,null);}});};exports['downloads']=function(_0x4bd3e5,_0x46dcc2,_0x588012){var _0x79c484=require(_0x270c('0x4d'));var _0x3070dd=![];var _0x41b63c={'$and':[db[_0x270c('0x5b')][_0x270c('0x3b')](db['sequelize']['fn'](_0x270c('0x5c'),db[_0x270c('0x5b')][_0x270c('0x5d')](_0x270c('0x5e'))),_0x4bd3e5['query'][_0x270c('0x5f')])]};if(_0x4bd3e5[_0x270c('0x32')]['type']&&_0x4bd3e5['query']['type']===_0x270c('0x5e')){_0x41b63c[_0x270c('0x60')][_0x270c('0x61')]({'uniqueid':_0x4bd3e5[_0x270c('0x46')]['id']});}else{_0x41b63c['$and'][_0x270c('0x61')]({'id':_0x4bd3e5[_0x270c('0x46')]['id']});}return db[_0x270c('0x42')][_0x270c('0x49')]({'where':_0x41b63c,'attributes':['id',_0x270c('0x4f')],'raw':!![]})[_0x270c('0x25')](handleEntityNotFound(_0x46dcc2,null))[_0x270c('0x25')](function(_0x39ba36){if(_0x39ba36){var _0x51fc77=util[_0x270c('0x31')](_0x270c('0x50'),_0x39ba36[_0x270c('0x4f')]);if(fs[_0x270c('0x51')](_0x51fc77)){_0x3070dd=!![];return _0x79c484[_0x270c('0x52')](_0x51fc77,_0x39ba36[_0x270c('0x4f')],config['secrets'][_0x270c('0x62')])[_0x270c('0x25')](function(){return _0x39ba36;});}return _0x39ba36;}})['then'](function(_0x16b6b4){if(_0x16b6b4){if(!fs[_0x270c('0x51')](_0x16b6b4[_0x270c('0x4f')])){throw new db['Sequelize'][(_0x270c('0x63'))]('VoiceRecording\x20not\x20found');}if(_0x16b6b4['filename']){return _0x46dcc2[_0x270c('0x57')](_0x16b6b4[_0x270c('0x4f')],_0x16b6b4[_0x270c('0x55')]+path['extname'](_0x16b6b4[_0x270c('0x4f')]),function(){if(_0x3070dd){fs[_0x270c('0x58')](_0x16b6b4[_0x270c('0x4f')]);}});}else{return _0x46dcc2[_0x270c('0x57')](_0x16b6b4[_0x270c('0x4f')],function(_0x2453db){if(_0x3070dd){fs[_0x270c('0x58')](_0x16b6b4[_0x270c('0x4f')]);}});}}})[_0x270c('0x45')](handleError(_0x46dcc2,null));};exports[_0x270c('0x24')]=function(_0x53fc7a,_0x5b8347){return db[_0x270c('0x42')][_0x270c('0x49')]({'where':{'id':_0x53fc7a[_0x270c('0x46')]['id']}})[_0x270c('0x25')](function(_0x53fed6){if(_[_0x270c('0x64')](_0x53fed6)){throw new ReferenceError(_0x270c('0x65'));}return _0x53fed6;})['then'](function(_0x508101){var _0x2229ef=_0x508101[_0x270c('0x4f')];logger[_0x270c('0x66')](_0x270c('0x67'),_0x2229ef);if(!_[_0x270c('0x64')](_0x508101[_0x270c('0x4f')])&&fs[_0x270c('0x51')](_0x2229ef)){logger[_0x270c('0x66')](_0x270c('0x68')+_0x2229ef+_0x270c('0x69'));fs[_0x270c('0x6a')](_0x2229ef);}_0x2229ef=_0x2229ef+'.cypher';if(!_['isNil'](_0x508101[_0x270c('0x4f')])&&fs[_0x270c('0x51')](_0x2229ef)){logger['info'](_0x270c('0x68')+_0x2229ef+'\x22\x20trovato\x20eseguo\x20la\x20cancellazione');fs[_0x270c('0x6a')](_0x2229ef);}return _0x508101;})[_0x270c('0x25')](function(_0x1d6b66){if(!_0x1d6b66)throw new InternalError();return _0x1d6b66[_0x270c('0x24')]();})[_0x270c('0x25')](function(){_0x5b8347[_0x270c('0x18')](0xcc)[_0x270c('0x19')]();})['catch'](handleError(_0x5b8347,null));};function getBucketslist(_0x47890e,_0x573cf8,_0x496e4d){return new Promise(function(_0x154283,_0x18f50a){var _0x34a587=new AWS['S3']({'accessKeyId':_0x573cf8,'secretAccessKey':_0x47890e,'region':_0x496e4d});_0x34a587[_0x270c('0x6b')]({},function(_0x1e1bba,_0x54ead9){if(_0x1e1bba){return _0x18f50a(_0x1e1bba);}else{return _0x154283(_0x54ead9);}});});}function createBucket(_0xe0a137,_0x37bc2c,_0xf230cc,_0x493058){return new Promise(function(_0x5207f3,_0x257670){var _0x2053e1=new AWS['S3']({'accessKeyId':_0x37bc2c,'secretAccessKey':_0xe0a137,'region':_0xf230cc});_0x2053e1[_0x270c('0x6c')]({'Bucket':_0x493058},function(_0x26b458,_0xd25ed2){if(_0x26b458){return _0x257670(_0x26b458);}else{return _0x5207f3(_0xd25ed2);}});});}function uploadFile(_0x43f311,_0x1a8f11,_0x190eb4,_0x16df96,_0xb539f4,_0x52bb8e){return new Promise(function(_0x56cc68,_0x4253c7){var _0x51a641=new AWS['S3']({'accessKeyId':_0x1a8f11,'secretAccessKey':_0x43f311,'region':_0x190eb4});_0x51a641[_0x270c('0x6d')]({'Bucket':_0x16df96,'Key':_0xb539f4,'Body':_0x52bb8e},function(_0x1226ae,_0x4cff24){if(_0x1226ae){return _0x4253c7(_0x1226ae);}else{return _0x56cc68(_0x4cff24);}});});}function startTranscribe(_0x1c6427,_0x3c5888,_0xb83670,_0x442952,_0x1b6b22,_0x170d3f){return new Promise(function(_0x13fad6,_0x1c9804){var _0x4292e8=new AWS[(_0x270c('0x6e'))]({'accessKeyId':_0x3c5888,'secretAccessKey':_0x1c6427,'region':_0xb83670});_0x4292e8[_0x270c('0x6f')]({'TranscriptionJobName':_0x442952,'LanguageCode':_0x1b6b22,'Media':{'MediaFileUri':_0x170d3f}},function(_0x5193dd,_0x584fd4){if(_0x5193dd){return _0x1c9804(_0x5193dd);}else{return _0x13fad6(_0x584fd4);}});});}function transcribe(_0x17c5a1,_0x4caccf,_0x5f305c,_0x336f76,_0x5c71c5,_0xcfecea,_0x2192e3){return new Promise(function(_0x1e7612,_0x3fea2e){var _0x2b8ef0={};logger[_0x270c('0x66')](util['format'](_0x270c('0x70'),_0x17c5a1,_0x5c71c5));return uploadFile(_0x4caccf,_0x5f305c,_0x336f76,_0x5c71c5,path[_0x270c('0x71')](_0xcfecea),fs[_0x270c('0x72')](_0xcfecea))[_0x270c('0x25')](function(_0x14aea5){logger[_0x270c('0x66')](util[_0x270c('0x31')](_0x270c('0x73'),_0x17c5a1,_0x5c71c5,_0x14aea5[_0x270c('0x74')]));_0x2b8ef0[_0x270c('0x75')]=_0x14aea5['Bucket'];_0x2b8ef0[_0x270c('0x76')]=_0x14aea5[_0x270c('0x74')];logger[_0x270c('0x66')](util[_0x270c('0x31')]('[RUNTRANSCRIPT][%d]\x20Sending\x20transcribe\x20request',_0x17c5a1));return startTranscribe(_0x4caccf,_0x5f305c,_0x336f76,uuidv4(),_0x2192e3,_0x14aea5[_0x270c('0x74')]);})[_0x270c('0x25')](function(_0x43ac4b){logger[_0x270c('0x66')](util['format'](_0x270c('0x77'),_0x17c5a1,_0x43ac4b[_0x270c('0x78')][_0x270c('0x79')]));_0x2b8ef0[_0x270c('0x7a')]=_0x43ac4b[_0x270c('0x78')]['TranscriptionJobName'];_0x2b8ef0[_0x270c('0x7b')]=_0x43ac4b['TranscriptionJob']['TranscriptionJobStatus'];return _0x1e7612(_0x2b8ef0);})[_0x270c('0x45')](function(_0x58bfea){return _0x3fea2e(_0x58bfea);});});}exports[_0x270c('0x7c')]=function(_0x32493a,_0xdfd5d3,_0x5a8bb2){var _0x356611;var _0x449f3f;var _0x46253a;var _0x52bbf5=require('../../components/encryptor');return db[_0x270c('0x42')][_0x270c('0x7d')]({'where':{'id':_0x32493a[_0x270c('0x46')]['id']}})['then'](function(_0x3f0e00){if(_0x3f0e00){var _0x485a03=util[_0x270c('0x31')](_0x270c('0x50'),_0x3f0e00['value']);if(fs[_0x270c('0x51')](_0x485a03)){cypher=!![];return _0x52bbf5[_0x270c('0x52')](_0x485a03,_0x3f0e00[_0x270c('0x4f')],config[_0x270c('0x7e')]['recording'])[_0x270c('0x25')](function(){return _0x3f0e00;});}return _0x3f0e00;}})['then'](function(_0x18764d){if(!_0x18764d){throw new db['Sequelize']['ValidationError'](_0x270c('0x7f'));}_0x449f3f=_0x18764d;return db[_0x270c('0x80')]['findOne']({'where':{'id':0x1}});})[_0x270c('0x25')](handleEntityNotFound(_0xdfd5d3,null))[_0x270c('0x25')](function(_0x3906a8){if(_0x3906a8){_0x356611=_0x3906a8;if(!_0x356611[_0x270c('0x81')]||!_0x356611[_0x270c('0x82')]||!_0x356611[_0x270c('0x83')]||!_0x356611[_0x270c('0x84')]||!_0x356611['bucket']){throw new db[(_0x270c('0x53'))]['ValidationError'](_0x270c('0x85'));}if(_0x32493a[_0x270c('0x4b')][_0x270c('0x86')]&&(!_0x356611['sentiment']||!_0x356611[_0x270c('0x87')]||!_0x356611['sentimentRegion']||!_0x356611[_0x270c('0x84')]||!_0x356611[_0x270c('0x75')])){throw new db[(_0x270c('0x53'))][(_0x270c('0x63'))](_0x270c('0x88'));}return db[_0x270c('0x89')][_0x270c('0x7d')]({'where':{'id':_0x356611[_0x270c('0x82')]}});}})[_0x270c('0x25')](function(_0x4764d0){if(!_0x4764d0){throw new db[(_0x270c('0x53'))][(_0x270c('0x63'))]('Cloud\x20Provider\x20not\x20available');}if(!_0x4764d0[_0x270c('0x8a')]||!_0x4764d0['data2']){throw new db[(_0x270c('0x53'))][(_0x270c('0x63'))]('Cloud\x20Provider\x20not\x20configured');}_0x46253a=_0x4764d0;return getBucketslist(_0x46253a[_0x270c('0x8a')],_0x46253a[_0x270c('0x8b')],_0x356611['transcribeRegion']);})[_0x270c('0x25')](function(_0x2ce69a){if(_0x2ce69a&&_0x2ce69a[_0x270c('0x8c')]){var _0x47c9ee=_[_0x270c('0x49')](_0x2ce69a[_0x270c('0x8c')],function(_0x522dd8){return _0x522dd8[_0x270c('0x8d')]===_0x356611[_0x270c('0x75')];});if(!_0x47c9ee){logger[_0x270c('0x66')](util[_0x270c('0x31')](_0x270c('0x8e'),_0x32493a[_0x270c('0x46')]['id'],_0x356611[_0x270c('0x75')]));return createBucket(_0x46253a[_0x270c('0x8a')],_0x46253a[_0x270c('0x8b')],_0x356611['transcribeRegion'],_0x356611[_0x270c('0x75')]);}logger[_0x270c('0x66')](util[_0x270c('0x31')]('[RUNTRANSCRIPT][%d]\x20Bucket\x20%s\x20available',_0x32493a[_0x270c('0x46')]['id'],_0x356611[_0x270c('0x75')]));return;}})['then'](function(_0x3b4d73){if(_0x449f3f['transcribeStatus']==='NEW'){return transcribe(_0x32493a[_0x270c('0x46')]['id'],_0x46253a[_0x270c('0x8a')],_0x46253a[_0x270c('0x8b')],_0x356611[_0x270c('0x83')],_0x356611[_0x270c('0x75')],_0x449f3f['value'],_0x356611['language']);}else{logger[_0x270c('0x66')](util[_0x270c('0x31')]('[RUNTRANSCRIPT][%d]\x20Transcript\x20action\x20already\x20requested',_0x32493a[_0x270c('0x46')]['id']));return{'transcribeStatus':_0x270c('0x8f')};}})['then'](function(_0xec21db){if(_0xec21db){_0xec21db['tempSentiment']=_0x32493a[_0x270c('0x4b')][_0x270c('0x86')];return _0x449f3f['updateAttributes'](_0xec21db);}})[_0x270c('0x25')](respondWithResult(_0xdfd5d3,null))[_0x270c('0x45')](handleError(_0xdfd5d3,null));};function writeFile(_0xe2931a,_0x33b8b8){return new Promise(function(_0x3d796f,_0x54ded4){fs['writeFile'](_0x33b8b8,_0xe2931a,function(_0x5ed9c4,_0x4ea15c){if(_0x5ed9c4){return _0x54ded4(_0x5ed9c4);}else{return _0x3d796f(_0x4ea15c);}});});}exports[_0x270c('0x90')]=function(_0xc7dc6b,_0x39c757,_0x6cee1d){return db[_0x270c('0x42')][_0x270c('0x7d')]({'where':{'id':_0xc7dc6b[_0x270c('0x46')]['id']}})[_0x270c('0x25')](handleEntityNotFound(_0x39c757))[_0x270c('0x25')](function(_0x55d456){if(_0x55d456&&_0x55d456[_0x270c('0x91')]){var _0x1450bd=_0x55d456[_0x270c('0x91')];var _0x346e14=config[_0x270c('0x92')]+_0x270c('0x93')+_0x55d456['id']+_0x270c('0x94');if(fs[_0x270c('0x51')](_0x346e14)){return _0x346e14;}return writeFile(_0x1450bd,_0x346e14)[_0x270c('0x25')](function(){return _0x346e14;});}else{throw new db['Sequelize'][(_0x270c('0x63'))]('Transcript\x20not\x20available');}})[_0x270c('0x25')](function(_0x12da17){return _0x39c757[_0x270c('0x57')](_0x12da17);})['catch'](handleError(_0x39c757));};