Built motion from commit 994c64e1.|2.6.1
[motion2.git] / server / api / voiceRecording / voiceRecording.rpc.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 _0xb145=['info','request\x20sent','debug','VoiceRecording,\x20%s,\x20%s,\x20%s','stringify','error','VoiceRecording,\x20%s,\x20%s','message','result','catch','VoiceRecording','update','body','options','where','attributes','limit','UpdateVoiceRecording','CreateVoiceRecording','../../components/encryptor','Setting','findOne','callRecordingEncryption','then','create','existsSync','format','value','encryptFile','recording','unlink','util','moment','bluebird','randomstring','ioredis','../../mysqldb','../../config/utils','../../config/logger','../../config/environment','jayson/promise','client','http','request'];(function(_0x4565bf,_0x5ad9d6){var _0x5610ba=function(_0x170988){while(--_0x170988){_0x4565bf['push'](_0x4565bf['shift']());}};_0x5610ba(++_0x5ad9d6);}(_0xb145,0xa3));var _0x5b14=function(_0xca6cd2,_0x213e70){_0xca6cd2=_0xca6cd2-0x0;var _0x44214a=_0xb145[_0xca6cd2];return _0x44214a;};'use strict';var _=require('lodash');var util=require(_0x5b14('0x0'));var moment=require(_0x5b14('0x1'));var BPromise=require(_0x5b14('0x2'));var rs=require(_0x5b14('0x3'));var fs=require('fs');var Redis=require(_0x5b14('0x4'));var db=require(_0x5b14('0x5'))['db'];var utils=require(_0x5b14('0x6'));var logger=require(_0x5b14('0x7'))('rpc');var config=require(_0x5b14('0x8'));var jayson=require(_0x5b14('0x9'));var client=jayson[_0x5b14('0xa')][_0x5b14('0xb')]({'port':0x232a});function respondWithRpcPromise(_0x50fd91,_0x1d12ed,_0x2a3921){return new BPromise(function(_0x34530a,_0x62cdcd){return client[_0x5b14('0xc')](_0x50fd91,_0x2a3921)['then'](function(_0x32d729){logger[_0x5b14('0xd')]('VoiceRecording,\x20%s,\x20%s',_0x1d12ed,_0x5b14('0xe'));logger[_0x5b14('0xf')](_0x5b14('0x10'),_0x1d12ed,_0x5b14('0xe'),JSON[_0x5b14('0x11')](_0x32d729));if(_0x32d729['error']){if(_0x32d729[_0x5b14('0x12')]['code']===0x1f4){logger[_0x5b14('0x12')](_0x5b14('0x13'),_0x1d12ed,_0x32d729[_0x5b14('0x12')][_0x5b14('0x14')]);return _0x62cdcd(_0x32d729[_0x5b14('0x12')][_0x5b14('0x14')]);}logger['error'](_0x5b14('0x13'),_0x1d12ed,_0x32d729[_0x5b14('0x12')][_0x5b14('0x14')]);return _0x34530a(_0x32d729[_0x5b14('0x12')][_0x5b14('0x14')]);}else{logger[_0x5b14('0xd')](_0x5b14('0x13'),_0x1d12ed,_0x5b14('0xe'));_0x34530a(_0x32d729[_0x5b14('0x15')][_0x5b14('0x14')]);}})[_0x5b14('0x16')](function(_0x2c3efb){logger['error'](_0x5b14('0x13'),_0x1d12ed,_0x2c3efb);_0x62cdcd(_0x2c3efb);});});}exports['UpdateVoiceRecording']=function(_0x48d395){var _0x58bf3c=this;return new Promise(function(_0x3f397d,_0x3035b5){return db[_0x5b14('0x17')][_0x5b14('0x18')](_0x48d395[_0x5b14('0x19')],{'raw':_0x48d395[_0x5b14('0x1a')]?_0x48d395[_0x5b14('0x1a')]['raw']===undefined?!![]:![]:!![],'individualHooks':!![],'where':_0x48d395['options']?_0x48d395['options'][_0x5b14('0x1b')]||null:null,'attributes':_0x48d395[_0x5b14('0x1a')]?_0x48d395[_0x5b14('0x1a')][_0x5b14('0x1c')]||null:null,'limit':_0x48d395['options']?_0x48d395[_0x5b14('0x1a')][_0x5b14('0x1d')]||null:null})['then'](function(_0x2d7b38){logger[_0x5b14('0xd')]('UpdateVoiceRecording',_0x48d395);logger[_0x5b14('0xf')]('UpdateVoiceRecording',_0x48d395,JSON['stringify'](_0x2d7b38));_0x3f397d(_0x2d7b38);})['catch'](function(_0x4def4b){logger[_0x5b14('0x12')](_0x5b14('0x1e'),_0x4def4b[_0x5b14('0x14')],_0x48d395);_0x3035b5(_0x58bf3c['error'](0x1f4,_0x4def4b[_0x5b14('0x14')]));});});};exports[_0x5b14('0x1f')]=function(_0x2ac7b0){var _0x143648=this;return new Promise(function(_0xe6851b,_0x1bbbd7){var _0x422d22=require(_0x5b14('0x20'));var _0x296d65;return db[_0x5b14('0x21')][_0x5b14('0x22')]({'attributes':['id',_0x5b14('0x23')],'where':{'id':0x1},'raw':!![]})[_0x5b14('0x24')](function(_0x266bbe){_0x296d65=_0x266bbe;return db['VoiceRecording'][_0x5b14('0x25')](_0x2ac7b0[_0x5b14('0x19')]);})['then'](function(_0x4ecf7c){if(_0x296d65[_0x5b14('0x23')]&&fs[_0x5b14('0x26')](_0x4ecf7c['value'])){var _0x4c1f0e=util[_0x5b14('0x27')]('%s.cypher',_0x4ecf7c[_0x5b14('0x28')]);return _0x422d22[_0x5b14('0x29')](_0x4ecf7c['value'],_0x4c1f0e,config['secrets'][_0x5b14('0x2a')])[_0x5b14('0x24')](function(){fs[_0x5b14('0x2b')](_0x4ecf7c['value']);logger[_0x5b14('0xd')]('CreateVoiceRecording\x20file\x20encrypted');return _0x4ecf7c;});}return _0x4ecf7c;})[_0x5b14('0x24')](function(_0x291c92){logger[_0x5b14('0xd')](_0x5b14('0x1f'),_0x2ac7b0);logger['debug'](_0x5b14('0x1f'),_0x2ac7b0,JSON[_0x5b14('0x11')](_0x291c92));_0xe6851b(_0x291c92);})[_0x5b14('0x16')](function(_0x37f62c){logger['error'](_0x5b14('0x1f'),_0x37f62c[_0x5b14('0x14')],_0x2ac7b0);_0x1bbbd7(_0x143648[_0x5b14('0x12')](0x1f4,_0x37f62c['message']));});});};