Built motion from commit da24aabd.|2.6.20
[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 _0xaebd=['randomstring','ioredis','../../mysqldb','../../config/logger','rpc','../../config/environment','jayson/promise','client','request','then','info','request\x20sent','VoiceRecording,\x20%s,\x20%s,\x20%s','stringify','error','message','VoiceRecording,\x20%s,\x20%s','catch','UpdateVoiceRecording','update','options','raw','where','attributes','debug','CreateVoiceRecording','Setting','findOne','callRecordingEncryption','VoiceRecording','create','body','value','format','%s.cypher','encryptFile','recording','unlink','lodash','moment','bluebird'];(function(_0xfb0cfd,_0x500179){var _0x2fd8aa=function(_0xccb501){while(--_0xccb501){_0xfb0cfd['push'](_0xfb0cfd['shift']());}};_0x2fd8aa(++_0x500179);}(_0xaebd,0x1e9));var _0xdaeb=function(_0x4ab015,_0x332cc4){_0x4ab015=_0x4ab015-0x0;var _0x19410d=_0xaebd[_0x4ab015];return _0x19410d;};'use strict';var _=require(_0xdaeb('0x0'));var util=require('util');var moment=require(_0xdaeb('0x1'));var BPromise=require(_0xdaeb('0x2'));var rs=require(_0xdaeb('0x3'));var fs=require('fs');var Redis=require(_0xdaeb('0x4'));var db=require(_0xdaeb('0x5'))['db'];var utils=require('../../config/utils');var logger=require(_0xdaeb('0x6'))(_0xdaeb('0x7'));var config=require(_0xdaeb('0x8'));var jayson=require(_0xdaeb('0x9'));var client=jayson[_0xdaeb('0xa')]['http']({'port':0x232a});function respondWithRpcPromise(_0x3ea090,_0x3f7ba1,_0x52c717){return new BPromise(function(_0x550bd9,_0x1b9d37){return client[_0xdaeb('0xb')](_0x3ea090,_0x52c717)[_0xdaeb('0xc')](function(_0x5e0ae9){logger[_0xdaeb('0xd')]('VoiceRecording,\x20%s,\x20%s',_0x3f7ba1,_0xdaeb('0xe'));logger['debug'](_0xdaeb('0xf'),_0x3f7ba1,'request\x20sent',JSON[_0xdaeb('0x10')](_0x5e0ae9));if(_0x5e0ae9[_0xdaeb('0x11')]){if(_0x5e0ae9['error']['code']===0x1f4){logger[_0xdaeb('0x11')]('VoiceRecording,\x20%s,\x20%s',_0x3f7ba1,_0x5e0ae9[_0xdaeb('0x11')][_0xdaeb('0x12')]);return _0x1b9d37(_0x5e0ae9[_0xdaeb('0x11')][_0xdaeb('0x12')]);}logger[_0xdaeb('0x11')](_0xdaeb('0x13'),_0x3f7ba1,_0x5e0ae9[_0xdaeb('0x11')]['message']);return _0x550bd9(_0x5e0ae9['error'][_0xdaeb('0x12')]);}else{logger[_0xdaeb('0xd')](_0xdaeb('0x13'),_0x3f7ba1,_0xdaeb('0xe'));_0x550bd9(_0x5e0ae9['result']['message']);}})[_0xdaeb('0x14')](function(_0x4dd803){logger['error'](_0xdaeb('0x13'),_0x3f7ba1,_0x4dd803);_0x1b9d37(_0x4dd803);});});}exports[_0xdaeb('0x15')]=function(_0x1b5243){var _0x1fe84e=this;return new Promise(function(_0x2d8f11,_0x36f9ac){return db['VoiceRecording'][_0xdaeb('0x16')](_0x1b5243['body'],{'raw':_0x1b5243[_0xdaeb('0x17')]?_0x1b5243[_0xdaeb('0x17')][_0xdaeb('0x18')]===undefined?!![]:![]:!![],'individualHooks':!![],'where':_0x1b5243['options']?_0x1b5243['options'][_0xdaeb('0x19')]||null:null,'attributes':_0x1b5243[_0xdaeb('0x17')]?_0x1b5243[_0xdaeb('0x17')][_0xdaeb('0x1a')]||null:null,'limit':_0x1b5243[_0xdaeb('0x17')]?_0x1b5243['options']['limit']||null:null})[_0xdaeb('0xc')](function(_0x3cfcaf){logger[_0xdaeb('0xd')](_0xdaeb('0x15'),_0x1b5243);logger[_0xdaeb('0x1b')]('UpdateVoiceRecording',_0x1b5243,JSON[_0xdaeb('0x10')](_0x3cfcaf));_0x2d8f11(_0x3cfcaf);})['catch'](function(_0x130c35){logger[_0xdaeb('0x11')](_0xdaeb('0x15'),_0x130c35[_0xdaeb('0x12')],_0x1b5243);_0x36f9ac(_0x1fe84e[_0xdaeb('0x11')](0x1f4,_0x130c35['message']));});});};exports[_0xdaeb('0x1c')]=function(_0x34fa21){var _0x338687=this;return new Promise(function(_0x4eb719,_0x57c2c4){var _0x43095f=require('../../components/encryptor');var _0x5045f8;return db[_0xdaeb('0x1d')][_0xdaeb('0x1e')]({'attributes':['id',_0xdaeb('0x1f')],'where':{'id':0x1},'raw':!![]})['then'](function(_0x5e6f97){_0x5045f8=_0x5e6f97;return db[_0xdaeb('0x20')][_0xdaeb('0x21')](_0x34fa21[_0xdaeb('0x22')]);})['then'](function(_0x36c933){if(_0x5045f8['callRecordingEncryption']&&fs['existsSync'](_0x36c933[_0xdaeb('0x23')])){var _0x21f6cf=util[_0xdaeb('0x24')](_0xdaeb('0x25'),_0x36c933[_0xdaeb('0x23')]);return _0x43095f[_0xdaeb('0x26')](_0x36c933[_0xdaeb('0x23')],_0x21f6cf,config['secrets'][_0xdaeb('0x27')])[_0xdaeb('0xc')](function(){fs[_0xdaeb('0x28')](_0x36c933[_0xdaeb('0x23')]);logger[_0xdaeb('0xd')]('CreateVoiceRecording\x20file\x20encrypted');return _0x36c933;});}return _0x36c933;})[_0xdaeb('0xc')](function(_0x3de2bd){logger['info'](_0xdaeb('0x1c'),_0x34fa21);logger[_0xdaeb('0x1b')](_0xdaeb('0x1c'),_0x34fa21,JSON[_0xdaeb('0x10')](_0x3de2bd));_0x4eb719(_0x3de2bd);})[_0xdaeb('0x14')](function(_0x1628b8){logger[_0xdaeb('0x11')](_0xdaeb('0x1c'),_0x1628b8[_0xdaeb('0x12')],_0x34fa21);_0x57c2c4(_0x338687[_0xdaeb('0x11')](0x1f4,_0x1628b8['message']));});});};