d870df6a9fdd98002f59fe22ff5d5f4c1f6f0652
[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 _0xcaf2=['CreateVoiceRecording','../../components/encryptor','Setting','findOne','callRecordingEncryption','create','existsSync','value','format','encryptFile','secrets','recording','lodash','moment','bluebird','ioredis','../../mysqldb','../../config/logger','../../config/environment','jayson/promise','client','request','then','info','VoiceRecording,\x20%s,\x20%s','request\x20sent','debug','VoiceRecording,\x20%s,\x20%s,\x20%s','error','code','message','result','VoiceRecording','body','options','raw','where','attributes','limit','UpdateVoiceRecording','stringify','catch'];(function(_0x11faf5,_0x5a7bc2){var _0x265160=function(_0xd989bb){while(--_0xd989bb){_0x11faf5['push'](_0x11faf5['shift']());}};_0x265160(++_0x5a7bc2);}(_0xcaf2,0x8a));var _0x2caf=function(_0x18fdaf,_0x457de2){_0x18fdaf=_0x18fdaf-0x0;var _0x557a9b=_0xcaf2[_0x18fdaf];return _0x557a9b;};'use strict';var _=require(_0x2caf('0x0'));var util=require('util');var moment=require(_0x2caf('0x1'));var BPromise=require(_0x2caf('0x2'));var rs=require('randomstring');var fs=require('fs');var Redis=require(_0x2caf('0x3'));var db=require(_0x2caf('0x4'))['db'];var utils=require('../../config/utils');var logger=require(_0x2caf('0x5'))('rpc');var config=require(_0x2caf('0x6'));var jayson=require(_0x2caf('0x7'));var client=jayson[_0x2caf('0x8')]['http']({'port':0x232a});function respondWithRpcPromise(_0xc44e4e,_0x314486,_0x4667c6){return new BPromise(function(_0x34e792,_0x5611aa){return client[_0x2caf('0x9')](_0xc44e4e,_0x4667c6)[_0x2caf('0xa')](function(_0x45e520){logger[_0x2caf('0xb')](_0x2caf('0xc'),_0x314486,_0x2caf('0xd'));logger[_0x2caf('0xe')](_0x2caf('0xf'),_0x314486,_0x2caf('0xd'),JSON['stringify'](_0x45e520));if(_0x45e520[_0x2caf('0x10')]){if(_0x45e520[_0x2caf('0x10')][_0x2caf('0x11')]===0x1f4){logger[_0x2caf('0x10')](_0x2caf('0xc'),_0x314486,_0x45e520[_0x2caf('0x10')][_0x2caf('0x12')]);return _0x5611aa(_0x45e520[_0x2caf('0x10')]['message']);}logger[_0x2caf('0x10')](_0x2caf('0xc'),_0x314486,_0x45e520['error']['message']);return _0x34e792(_0x45e520['error'][_0x2caf('0x12')]);}else{logger['info'](_0x2caf('0xc'),_0x314486,_0x2caf('0xd'));_0x34e792(_0x45e520[_0x2caf('0x13')][_0x2caf('0x12')]);}})['catch'](function(_0x184355){logger['error'](_0x2caf('0xc'),_0x314486,_0x184355);_0x5611aa(_0x184355);});});}exports['UpdateVoiceRecording']=function(_0x4a33fc){var _0x3e975f=this;return new Promise(function(_0x58047b,_0xe72440){return db[_0x2caf('0x14')]['update'](_0x4a33fc[_0x2caf('0x15')],{'raw':_0x4a33fc[_0x2caf('0x16')]?_0x4a33fc[_0x2caf('0x16')][_0x2caf('0x17')]===undefined?!![]:![]:!![],'individualHooks':!![],'where':_0x4a33fc[_0x2caf('0x16')]?_0x4a33fc['options'][_0x2caf('0x18')]||null:null,'attributes':_0x4a33fc[_0x2caf('0x16')]?_0x4a33fc[_0x2caf('0x16')][_0x2caf('0x19')]||null:null,'limit':_0x4a33fc[_0x2caf('0x16')]?_0x4a33fc[_0x2caf('0x16')][_0x2caf('0x1a')]||null:null})[_0x2caf('0xa')](function(_0x3332b1){logger[_0x2caf('0xb')](_0x2caf('0x1b'),_0x4a33fc);logger['debug'](_0x2caf('0x1b'),_0x4a33fc,JSON[_0x2caf('0x1c')](_0x3332b1));_0x58047b(_0x3332b1);})[_0x2caf('0x1d')](function(_0x401ea2){logger[_0x2caf('0x10')](_0x2caf('0x1b'),_0x401ea2[_0x2caf('0x12')],_0x4a33fc);_0xe72440(_0x3e975f[_0x2caf('0x10')](0x1f4,_0x401ea2[_0x2caf('0x12')]));});});};exports[_0x2caf('0x1e')]=function(_0x5ad211){var _0x6a32ac=this;return new Promise(function(_0x325eda,_0xbefce6){var _0x37b08f=require(_0x2caf('0x1f'));var _0x17d3c6;return db[_0x2caf('0x20')][_0x2caf('0x21')]({'attributes':['id',_0x2caf('0x22')],'where':{'id':0x1},'raw':!![]})[_0x2caf('0xa')](function(_0x30da75){_0x17d3c6=_0x30da75;return db[_0x2caf('0x14')][_0x2caf('0x23')](_0x5ad211['body']);})[_0x2caf('0xa')](function(_0xda0ec5){if(_0x17d3c6[_0x2caf('0x22')]&&fs[_0x2caf('0x24')](_0xda0ec5[_0x2caf('0x25')])){var _0x1f52bf=util[_0x2caf('0x26')]('%s.cypher',_0xda0ec5[_0x2caf('0x25')]);return _0x37b08f[_0x2caf('0x27')](_0xda0ec5['value'],_0x1f52bf,config[_0x2caf('0x28')][_0x2caf('0x29')])[_0x2caf('0xa')](function(){fs['unlink'](_0xda0ec5[_0x2caf('0x25')]);logger['info']('CreateVoiceRecording\x20file\x20encrypted');return _0xda0ec5;});}return _0xda0ec5;})[_0x2caf('0xa')](function(_0x28b715){logger[_0x2caf('0xb')](_0x2caf('0x1e'),_0x5ad211);logger[_0x2caf('0xe')](_0x2caf('0x1e'),_0x5ad211,JSON[_0x2caf('0x1c')](_0x28b715));_0x325eda(_0x28b715);})[_0x2caf('0x1d')](function(_0x20818e){logger['error'](_0x2caf('0x1e'),_0x20818e[_0x2caf('0x12')],_0x5ad211);_0xbefce6(_0x6a32ac[_0x2caf('0x10')](0x1f4,_0x20818e[_0x2caf('0x12')]));});});};