406f7e91ca693f2e2a865f3d965dc6dc6faecad7
[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 _0x57ca=['update','body','options','where','limit','then','debug','stringify','CreateVoiceRecording','../../components/encryptor','Setting','callRecordingEncryption','create','value','format','recording','unlink','CreateVoiceRecording\x20file\x20encrypted','util','moment','randomstring','ioredis','../../mysqldb','../../config/utils','../../config/logger','../../config/environment','jayson/promise','client','http','request','info','request\x20sent','VoiceRecording,\x20%s,\x20%s,\x20%s','error','code','VoiceRecording,\x20%s,\x20%s','message','result','catch','UpdateVoiceRecording','VoiceRecording'];(function(_0x3be714,_0x38e9f4){var _0xcf112e=function(_0x15d9c2){while(--_0x15d9c2){_0x3be714['push'](_0x3be714['shift']());}};_0xcf112e(++_0x38e9f4);}(_0x57ca,0x108));var _0xa57c=function(_0x10d76c,_0x4c8135){_0x10d76c=_0x10d76c-0x0;var _0x415d3d=_0x57ca[_0x10d76c];return _0x415d3d;};'use strict';var _=require('lodash');var util=require(_0xa57c('0x0'));var moment=require(_0xa57c('0x1'));var BPromise=require('bluebird');var rs=require(_0xa57c('0x2'));var fs=require('fs');var Redis=require(_0xa57c('0x3'));var db=require(_0xa57c('0x4'))['db'];var utils=require(_0xa57c('0x5'));var logger=require(_0xa57c('0x6'))('rpc');var config=require(_0xa57c('0x7'));var jayson=require(_0xa57c('0x8'));var client=jayson[_0xa57c('0x9')][_0xa57c('0xa')]({'port':0x232a});function respondWithRpcPromise(_0xbdfffb,_0x314574,_0x19e28e){return new BPromise(function(_0x271ccc,_0x5e3962){return client[_0xa57c('0xb')](_0xbdfffb,_0x19e28e)['then'](function(_0x46ba92){logger[_0xa57c('0xc')]('VoiceRecording,\x20%s,\x20%s',_0x314574,_0xa57c('0xd'));logger['debug'](_0xa57c('0xe'),_0x314574,_0xa57c('0xd'),JSON['stringify'](_0x46ba92));if(_0x46ba92[_0xa57c('0xf')]){if(_0x46ba92['error'][_0xa57c('0x10')]===0x1f4){logger[_0xa57c('0xf')](_0xa57c('0x11'),_0x314574,_0x46ba92[_0xa57c('0xf')][_0xa57c('0x12')]);return _0x5e3962(_0x46ba92['error'][_0xa57c('0x12')]);}logger['error'](_0xa57c('0x11'),_0x314574,_0x46ba92[_0xa57c('0xf')][_0xa57c('0x12')]);return _0x271ccc(_0x46ba92[_0xa57c('0xf')][_0xa57c('0x12')]);}else{logger[_0xa57c('0xc')](_0xa57c('0x11'),_0x314574,'request\x20sent');_0x271ccc(_0x46ba92[_0xa57c('0x13')][_0xa57c('0x12')]);}})[_0xa57c('0x14')](function(_0x5a6024){logger[_0xa57c('0xf')]('VoiceRecording,\x20%s,\x20%s',_0x314574,_0x5a6024);_0x5e3962(_0x5a6024);});});}exports[_0xa57c('0x15')]=function(_0x3d781d){var _0x93462c=this;return new Promise(function(_0xe3d505,_0x1fd0d8){return db[_0xa57c('0x16')][_0xa57c('0x17')](_0x3d781d[_0xa57c('0x18')],{'raw':_0x3d781d['options']?_0x3d781d[_0xa57c('0x19')]['raw']===undefined?!![]:![]:!![],'individualHooks':!![],'where':_0x3d781d['options']?_0x3d781d[_0xa57c('0x19')][_0xa57c('0x1a')]||null:null,'attributes':_0x3d781d[_0xa57c('0x19')]?_0x3d781d[_0xa57c('0x19')]['attributes']||null:null,'limit':_0x3d781d[_0xa57c('0x19')]?_0x3d781d[_0xa57c('0x19')][_0xa57c('0x1b')]||null:null})[_0xa57c('0x1c')](function(_0x3bb969){logger[_0xa57c('0xc')](_0xa57c('0x15'),_0x3d781d);logger[_0xa57c('0x1d')](_0xa57c('0x15'),_0x3d781d,JSON[_0xa57c('0x1e')](_0x3bb969));_0xe3d505(_0x3bb969);})[_0xa57c('0x14')](function(_0x1e7f7a){logger[_0xa57c('0xf')](_0xa57c('0x15'),_0x1e7f7a[_0xa57c('0x12')],_0x3d781d);_0x1fd0d8(_0x93462c['error'](0x1f4,_0x1e7f7a[_0xa57c('0x12')]));});});};exports[_0xa57c('0x1f')]=function(_0x27884d){var _0x5228b9=this;return new Promise(function(_0x315ad7,_0x1e8e45){var _0x8ee1c0=require(_0xa57c('0x20'));var _0x337f97;return db[_0xa57c('0x21')]['findOne']({'attributes':['id',_0xa57c('0x22')],'where':{'id':0x1},'raw':!![]})['then'](function(_0x54a18b){_0x337f97=_0x54a18b;return db[_0xa57c('0x16')][_0xa57c('0x23')](_0x27884d['body']);})[_0xa57c('0x1c')](function(_0x1ef331){if(_0x337f97[_0xa57c('0x22')]&&fs['existsSync'](_0x1ef331[_0xa57c('0x24')])){var _0x58d46f=util[_0xa57c('0x25')]('%s.cypher',_0x1ef331[_0xa57c('0x24')]);return _0x8ee1c0['encryptFile'](_0x1ef331[_0xa57c('0x24')],_0x58d46f,config['secrets'][_0xa57c('0x26')])[_0xa57c('0x1c')](function(){fs[_0xa57c('0x27')](_0x1ef331[_0xa57c('0x24')]);logger[_0xa57c('0xc')](_0xa57c('0x28'));return _0x1ef331;});}return _0x1ef331;})[_0xa57c('0x1c')](function(_0x5aa91e){logger[_0xa57c('0xc')]('CreateVoiceRecording',_0x27884d);logger[_0xa57c('0x1d')](_0xa57c('0x1f'),_0x27884d,JSON[_0xa57c('0x1e')](_0x5aa91e));_0x315ad7(_0x5aa91e);})['catch'](function(_0x289174){logger['error'](_0xa57c('0x1f'),_0x289174['message'],_0x27884d);_0x1e8e45(_0x5228b9[_0xa57c('0xf')](0x1f4,_0x289174['message']));});});};