9c685fd9aa6845caa37a065ce906f68a4b470779
[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 _0x68b3=['../../components/encryptor','Setting','findOne','callRecordingEncryption','existsSync','format','%s.cypher','value','encryptFile','secrets','recording','unlink','lodash','util','moment','bluebird','randomstring','../../mysqldb','../../config/utils','../../config/logger','rpc','jayson/promise','client','http','request','then','VoiceRecording,\x20%s,\x20%s','request\x20sent','debug','stringify','error','code','message','info','result','catch','UpdateVoiceRecording','VoiceRecording','update','body','options','raw','where','attributes','limit','CreateVoiceRecording'];(function(_0x39db05,_0x3868d0){var _0x3f0e22=function(_0x532c4f){while(--_0x532c4f){_0x39db05['push'](_0x39db05['shift']());}};_0x3f0e22(++_0x3868d0);}(_0x68b3,0x1d8));var _0x368b=function(_0x5db127,_0x364b60){_0x5db127=_0x5db127-0x0;var _0x5d217b=_0x68b3[_0x5db127];return _0x5d217b;};'use strict';var _=require(_0x368b('0x0'));var util=require(_0x368b('0x1'));var moment=require(_0x368b('0x2'));var BPromise=require(_0x368b('0x3'));var rs=require(_0x368b('0x4'));var fs=require('fs');var Redis=require('ioredis');var db=require(_0x368b('0x5'))['db'];var utils=require(_0x368b('0x6'));var logger=require(_0x368b('0x7'))(_0x368b('0x8'));var config=require('../../config/environment');var jayson=require(_0x368b('0x9'));var client=jayson[_0x368b('0xa')][_0x368b('0xb')]({'port':0x232a});function respondWithRpcPromise(_0x23584a,_0x4406c8,_0x127c1e){return new BPromise(function(_0x2dec1c,_0x142d05){return client[_0x368b('0xc')](_0x23584a,_0x127c1e)[_0x368b('0xd')](function(_0x2a7b9f){logger['info'](_0x368b('0xe'),_0x4406c8,_0x368b('0xf'));logger[_0x368b('0x10')]('VoiceRecording,\x20%s,\x20%s,\x20%s',_0x4406c8,_0x368b('0xf'),JSON[_0x368b('0x11')](_0x2a7b9f));if(_0x2a7b9f[_0x368b('0x12')]){if(_0x2a7b9f['error'][_0x368b('0x13')]===0x1f4){logger[_0x368b('0x12')]('VoiceRecording,\x20%s,\x20%s',_0x4406c8,_0x2a7b9f[_0x368b('0x12')][_0x368b('0x14')]);return _0x142d05(_0x2a7b9f[_0x368b('0x12')][_0x368b('0x14')]);}logger[_0x368b('0x12')]('VoiceRecording,\x20%s,\x20%s',_0x4406c8,_0x2a7b9f[_0x368b('0x12')][_0x368b('0x14')]);return _0x2dec1c(_0x2a7b9f['error'][_0x368b('0x14')]);}else{logger[_0x368b('0x15')](_0x368b('0xe'),_0x4406c8,'request\x20sent');_0x2dec1c(_0x2a7b9f[_0x368b('0x16')][_0x368b('0x14')]);}})[_0x368b('0x17')](function(_0x4d6d9d){logger[_0x368b('0x12')](_0x368b('0xe'),_0x4406c8,_0x4d6d9d);_0x142d05(_0x4d6d9d);});});}exports[_0x368b('0x18')]=function(_0x540f57){var _0x5d543e=this;return new Promise(function(_0x3e2e9f,_0x27d2a0){return db[_0x368b('0x19')][_0x368b('0x1a')](_0x540f57[_0x368b('0x1b')],{'raw':_0x540f57['options']?_0x540f57[_0x368b('0x1c')][_0x368b('0x1d')]===undefined?!![]:![]:!![],'individualHooks':!![],'where':_0x540f57[_0x368b('0x1c')]?_0x540f57[_0x368b('0x1c')][_0x368b('0x1e')]||null:null,'attributes':_0x540f57[_0x368b('0x1c')]?_0x540f57[_0x368b('0x1c')][_0x368b('0x1f')]||null:null,'limit':_0x540f57['options']?_0x540f57[_0x368b('0x1c')][_0x368b('0x20')]||null:null})[_0x368b('0xd')](function(_0xc0f7af){logger[_0x368b('0x15')]('UpdateVoiceRecording',_0x540f57);logger[_0x368b('0x10')](_0x368b('0x18'),_0x540f57,JSON[_0x368b('0x11')](_0xc0f7af));_0x3e2e9f(_0xc0f7af);})[_0x368b('0x17')](function(_0x77a269){logger[_0x368b('0x12')](_0x368b('0x18'),_0x77a269[_0x368b('0x14')],_0x540f57);_0x27d2a0(_0x5d543e[_0x368b('0x12')](0x1f4,_0x77a269[_0x368b('0x14')]));});});};exports[_0x368b('0x21')]=function(_0x344d8a){var _0xceec4b=this;return new Promise(function(_0x376e61,_0x4636f4){var _0x23a83a=require(_0x368b('0x22'));var _0x9f192e;return db[_0x368b('0x23')][_0x368b('0x24')]({'attributes':['id',_0x368b('0x25')],'where':{'id':0x1},'raw':!![]})[_0x368b('0xd')](function(_0x107d2f){_0x9f192e=_0x107d2f;return db[_0x368b('0x19')]['create'](_0x344d8a['body']);})[_0x368b('0xd')](function(_0x2f1d52){if(_0x9f192e[_0x368b('0x25')]&&fs[_0x368b('0x26')](_0x2f1d52['value'])){var _0x12ae59=util[_0x368b('0x27')](_0x368b('0x28'),_0x2f1d52[_0x368b('0x29')]);return _0x23a83a[_0x368b('0x2a')](_0x2f1d52['value'],_0x12ae59,config[_0x368b('0x2b')][_0x368b('0x2c')])[_0x368b('0xd')](function(){fs[_0x368b('0x2d')](_0x2f1d52['value']);logger['info']('CreateVoiceRecording\x20file\x20encrypted');return _0x2f1d52;});}return _0x2f1d52;})[_0x368b('0xd')](function(_0x2bc363){logger[_0x368b('0x15')](_0x368b('0x21'),_0x344d8a);logger[_0x368b('0x10')]('CreateVoiceRecording',_0x344d8a,JSON[_0x368b('0x11')](_0x2bc363));_0x376e61(_0x2bc363);})[_0x368b('0x17')](function(_0x54e7e5){logger[_0x368b('0x12')](_0x368b('0x21'),_0x54e7e5['message'],_0x344d8a);_0x4636f4(_0xceec4b[_0x368b('0x12')](0x1f4,_0x54e7e5[_0x368b('0x14')]));});});};