fd68130b0942efd15d83bd8ec8814d72ef4c4617
[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 _0xc51f=['info','VoiceRecording,\x20%s,\x20%s','request\x20sent','debug','VoiceRecording,\x20%s,\x20%s,\x20%s','stringify','error','message','catch','VoiceRecording','update','body','raw','options','where','attributes','UpdateVoiceRecording','CreateVoiceRecording','../../components/encryptor','Setting','create','existsSync','value','format','%s.cypher','encryptFile','secrets','recording','CreateVoiceRecording\x20file\x20encrypted','lodash','moment','bluebird','randomstring','../../config/utils','../../config/logger','../../config/environment','jayson/promise','client','http','request','then'];(function(_0x4b522c,_0x1f4593){var _0x1e2a67=function(_0x1e94c5){while(--_0x1e94c5){_0x4b522c['push'](_0x4b522c['shift']());}};_0x1e2a67(++_0x1f4593);}(_0xc51f,0xc1));var _0xfc51=function(_0x37a7c6,_0x3a84b6){_0x37a7c6=_0x37a7c6-0x0;var _0x539905=_0xc51f[_0x37a7c6];return _0x539905;};'use strict';var _=require(_0xfc51('0x0'));var util=require('util');var moment=require(_0xfc51('0x1'));var BPromise=require(_0xfc51('0x2'));var rs=require(_0xfc51('0x3'));var fs=require('fs');var Redis=require('ioredis');var db=require('../../mysqldb')['db'];var utils=require(_0xfc51('0x4'));var logger=require(_0xfc51('0x5'))('rpc');var config=require(_0xfc51('0x6'));var jayson=require(_0xfc51('0x7'));var client=jayson[_0xfc51('0x8')][_0xfc51('0x9')]({'port':0x232a});function respondWithRpcPromise(_0x2f1622,_0x280cd3,_0x5ca8db){return new BPromise(function(_0x333c8a,_0x1ecc4d){return client[_0xfc51('0xa')](_0x2f1622,_0x5ca8db)[_0xfc51('0xb')](function(_0x13ff29){logger[_0xfc51('0xc')](_0xfc51('0xd'),_0x280cd3,_0xfc51('0xe'));logger[_0xfc51('0xf')](_0xfc51('0x10'),_0x280cd3,'request\x20sent',JSON[_0xfc51('0x11')](_0x13ff29));if(_0x13ff29['error']){if(_0x13ff29['error']['code']===0x1f4){logger[_0xfc51('0x12')](_0xfc51('0xd'),_0x280cd3,_0x13ff29[_0xfc51('0x12')][_0xfc51('0x13')]);return _0x1ecc4d(_0x13ff29['error'][_0xfc51('0x13')]);}logger['error'](_0xfc51('0xd'),_0x280cd3,_0x13ff29[_0xfc51('0x12')]['message']);return _0x333c8a(_0x13ff29[_0xfc51('0x12')][_0xfc51('0x13')]);}else{logger['info'](_0xfc51('0xd'),_0x280cd3,_0xfc51('0xe'));_0x333c8a(_0x13ff29['result'][_0xfc51('0x13')]);}})[_0xfc51('0x14')](function(_0x52e3b4){logger[_0xfc51('0x12')](_0xfc51('0xd'),_0x280cd3,_0x52e3b4);_0x1ecc4d(_0x52e3b4);});});}exports['UpdateVoiceRecording']=function(_0x5e3917){var _0xf50273=this;return new Promise(function(_0x4d20f6,_0x4947ac){return db[_0xfc51('0x15')][_0xfc51('0x16')](_0x5e3917[_0xfc51('0x17')],{'raw':_0x5e3917['options']?_0x5e3917['options'][_0xfc51('0x18')]===undefined?!![]:![]:!![],'individualHooks':!![],'where':_0x5e3917[_0xfc51('0x19')]?_0x5e3917['options'][_0xfc51('0x1a')]||null:null,'attributes':_0x5e3917[_0xfc51('0x19')]?_0x5e3917[_0xfc51('0x19')][_0xfc51('0x1b')]||null:null,'limit':_0x5e3917[_0xfc51('0x19')]?_0x5e3917[_0xfc51('0x19')]['limit']||null:null})[_0xfc51('0xb')](function(_0x46e09e){logger['info']('UpdateVoiceRecording',_0x5e3917);logger['debug'](_0xfc51('0x1c'),_0x5e3917,JSON[_0xfc51('0x11')](_0x46e09e));_0x4d20f6(_0x46e09e);})['catch'](function(_0x26e67c){logger['error']('UpdateVoiceRecording',_0x26e67c[_0xfc51('0x13')],_0x5e3917);_0x4947ac(_0xf50273[_0xfc51('0x12')](0x1f4,_0x26e67c[_0xfc51('0x13')]));});});};exports[_0xfc51('0x1d')]=function(_0x118491){var _0xe7bf6=this;return new Promise(function(_0x52ca15,_0x4aa416){var _0x14de31=require(_0xfc51('0x1e'));var _0xfda9b5;return db[_0xfc51('0x1f')]['findOne']({'attributes':['id','callRecordingEncryption'],'where':{'id':0x1},'raw':!![]})[_0xfc51('0xb')](function(_0x3acea3){_0xfda9b5=_0x3acea3;return db[_0xfc51('0x15')][_0xfc51('0x20')](_0x118491[_0xfc51('0x17')]);})[_0xfc51('0xb')](function(_0x50c266){if(_0xfda9b5['callRecordingEncryption']&&fs[_0xfc51('0x21')](_0x50c266[_0xfc51('0x22')])){var _0x2e65f7=util[_0xfc51('0x23')](_0xfc51('0x24'),_0x50c266[_0xfc51('0x22')]);return _0x14de31[_0xfc51('0x25')](_0x50c266[_0xfc51('0x22')],_0x2e65f7,config[_0xfc51('0x26')][_0xfc51('0x27')])[_0xfc51('0xb')](function(){fs['unlink'](_0x50c266[_0xfc51('0x22')]);logger[_0xfc51('0xc')](_0xfc51('0x28'));return _0x50c266;});}return _0x50c266;})[_0xfc51('0xb')](function(_0x3337f1){logger[_0xfc51('0xc')]('CreateVoiceRecording',_0x118491);logger[_0xfc51('0xf')]('CreateVoiceRecording',_0x118491,JSON['stringify'](_0x3337f1));_0x52ca15(_0x3337f1);})['catch'](function(_0x43a79d){logger[_0xfc51('0x12')](_0xfc51('0x1d'),_0x43a79d[_0xfc51('0x13')],_0x118491);_0x4aa416(_0xe7bf6[_0xfc51('0x12')](0x1f4,_0x43a79d[_0xfc51('0x13')]));});});};