05620bd09862cdecaba3f0d69d1160bf33ca6cc9
[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 _0x5f66=['randomstring','ioredis','../../mysqldb','../../config/utils','rpc','jayson/promise','client','request','then','VoiceRecording,\x20%s,\x20%s','request\x20sent','debug','VoiceRecording,\x20%s,\x20%s,\x20%s','stringify','code','message','error','info','catch','UpdateVoiceRecording','update','raw','options','where','attributes','../../components/encryptor','findOne','callRecordingEncryption','body','existsSync','value','encryptFile','recording','unlink','CreateVoiceRecording\x20file\x20encrypted','CreateVoiceRecording','util','bluebird'];(function(_0x9b11d7,_0x4a7808){var _0x4f4953=function(_0x15ef42){while(--_0x15ef42){_0x9b11d7['push'](_0x9b11d7['shift']());}};_0x4f4953(++_0x4a7808);}(_0x5f66,0x1a0));var _0x65f6=function(_0x2b4411,_0x2625ed){_0x2b4411=_0x2b4411-0x0;var _0x8e41ef=_0x5f66[_0x2b4411];return _0x8e41ef;};'use strict';var _=require('lodash');var util=require(_0x65f6('0x0'));var moment=require('moment');var BPromise=require(_0x65f6('0x1'));var rs=require(_0x65f6('0x2'));var fs=require('fs');var Redis=require(_0x65f6('0x3'));var db=require(_0x65f6('0x4'))['db'];var utils=require(_0x65f6('0x5'));var logger=require('../../config/logger')(_0x65f6('0x6'));var config=require('../../config/environment');var jayson=require(_0x65f6('0x7'));var client=jayson[_0x65f6('0x8')]['http']({'port':0x232a});function respondWithRpcPromise(_0x4ed98f,_0x1c0e12,_0x2c6571){return new BPromise(function(_0x112079,_0x8f6451){return client[_0x65f6('0x9')](_0x4ed98f,_0x2c6571)[_0x65f6('0xa')](function(_0x48d85c){logger['info'](_0x65f6('0xb'),_0x1c0e12,_0x65f6('0xc'));logger[_0x65f6('0xd')](_0x65f6('0xe'),_0x1c0e12,'request\x20sent',JSON[_0x65f6('0xf')](_0x48d85c));if(_0x48d85c['error']){if(_0x48d85c['error'][_0x65f6('0x10')]===0x1f4){logger['error'](_0x65f6('0xb'),_0x1c0e12,_0x48d85c['error'][_0x65f6('0x11')]);return _0x8f6451(_0x48d85c[_0x65f6('0x12')][_0x65f6('0x11')]);}logger[_0x65f6('0x12')](_0x65f6('0xb'),_0x1c0e12,_0x48d85c[_0x65f6('0x12')][_0x65f6('0x11')]);return _0x112079(_0x48d85c[_0x65f6('0x12')][_0x65f6('0x11')]);}else{logger[_0x65f6('0x13')]('VoiceRecording,\x20%s,\x20%s',_0x1c0e12,_0x65f6('0xc'));_0x112079(_0x48d85c['result']['message']);}})[_0x65f6('0x14')](function(_0x5c69f8){logger[_0x65f6('0x12')](_0x65f6('0xb'),_0x1c0e12,_0x5c69f8);_0x8f6451(_0x5c69f8);});});}exports[_0x65f6('0x15')]=function(_0x1f974c){var _0xc8660c=this;return new Promise(function(_0x18380e,_0x495dd6){return db['VoiceRecording'][_0x65f6('0x16')](_0x1f974c['body'],{'raw':_0x1f974c['options']?_0x1f974c['options'][_0x65f6('0x17')]===undefined?!![]:![]:!![],'individualHooks':!![],'where':_0x1f974c[_0x65f6('0x18')]?_0x1f974c['options'][_0x65f6('0x19')]||null:null,'attributes':_0x1f974c[_0x65f6('0x18')]?_0x1f974c[_0x65f6('0x18')][_0x65f6('0x1a')]||null:null,'limit':_0x1f974c[_0x65f6('0x18')]?_0x1f974c[_0x65f6('0x18')]['limit']||null:null})[_0x65f6('0xa')](function(_0x4bb39e){logger['info'](_0x65f6('0x15'),_0x1f974c);logger[_0x65f6('0xd')]('UpdateVoiceRecording',_0x1f974c,JSON[_0x65f6('0xf')](_0x4bb39e));_0x18380e(_0x4bb39e);})[_0x65f6('0x14')](function(_0x2317ce){logger[_0x65f6('0x12')]('UpdateVoiceRecording',_0x2317ce[_0x65f6('0x11')],_0x1f974c);_0x495dd6(_0xc8660c[_0x65f6('0x12')](0x1f4,_0x2317ce[_0x65f6('0x11')]));});});};exports['CreateVoiceRecording']=function(_0x5cb131){var _0x4fde2f=this;return new Promise(function(_0x29abdb,_0x16cde8){var _0x4b2292=require(_0x65f6('0x1b'));var _0x28f710;return db['Setting'][_0x65f6('0x1c')]({'attributes':['id',_0x65f6('0x1d')],'where':{'id':0x1},'raw':!![]})[_0x65f6('0xa')](function(_0x559330){_0x28f710=_0x559330;return db['VoiceRecording']['create'](_0x5cb131[_0x65f6('0x1e')]);})[_0x65f6('0xa')](function(_0x4344b3){if(_0x28f710[_0x65f6('0x1d')]&&fs[_0x65f6('0x1f')](_0x4344b3[_0x65f6('0x20')])){var _0x144e55=util['format']('%s.cypher',_0x4344b3[_0x65f6('0x20')]);return _0x4b2292[_0x65f6('0x21')](_0x4344b3['value'],_0x144e55,config['secrets'][_0x65f6('0x22')])[_0x65f6('0xa')](function(){fs[_0x65f6('0x23')](_0x4344b3[_0x65f6('0x20')]);logger[_0x65f6('0x13')](_0x65f6('0x24'));return _0x4344b3;});}return _0x4344b3;})['then'](function(_0x103265){logger[_0x65f6('0x13')](_0x65f6('0x25'),_0x5cb131);logger['debug'](_0x65f6('0x25'),_0x5cb131,JSON[_0x65f6('0xf')](_0x103265));_0x29abdb(_0x103265);})[_0x65f6('0x14')](function(_0x45510a){logger[_0x65f6('0x12')](_0x65f6('0x25'),_0x45510a['message'],_0x5cb131);_0x16cde8(_0x4fde2f[_0x65f6('0x12')](0x1f4,_0x45510a[_0x65f6('0x11')]));});});};