a44b7c97a7794fb7063792243a73ff8082c7af70
[motion2.git] / server / api / attachment / attachment.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 _0x4b1f=['randomstring','ioredis','../../config/utils','../../config/logger','rpc','client','http','then','info','debug','Attachment,\x20%s,\x20%s,\x20%s','request\x20sent','stringify','error','code','Attachment,\x20%s,\x20%s','message','Attachment','create','options','CreateAttachment','lodash','util','bluebird'];(function(_0x33c7a9,_0x463a29){var _0x3aec79=function(_0x374dee){while(--_0x374dee){_0x33c7a9['push'](_0x33c7a9['shift']());}};_0x3aec79(++_0x463a29);}(_0x4b1f,0x195));var _0xf4b1=function(_0x1589dd,_0x2b9d22){_0x1589dd=_0x1589dd-0x0;var _0x1bddd1=_0x4b1f[_0x1589dd];return _0x1bddd1;};'use strict';var _=require(_0xf4b1('0x0'));var util=require(_0xf4b1('0x1'));var moment=require('moment');var BPromise=require(_0xf4b1('0x2'));var rs=require(_0xf4b1('0x3'));var fs=require('fs');var Redis=require(_0xf4b1('0x4'));var db=require('../../mysqldb')['db'];var utils=require(_0xf4b1('0x5'));var logger=require(_0xf4b1('0x6'))(_0xf4b1('0x7'));var config=require('../../config/environment');var jayson=require('jayson/promise');var client=jayson[_0xf4b1('0x8')][_0xf4b1('0x9')]({'port':0x232a});function respondWithRpcPromise(_0x310db5,_0x3b9c78,_0x1abfc7){return new BPromise(function(_0x50738c,_0x59cf77){return client['request'](_0x310db5,_0x1abfc7)[_0xf4b1('0xa')](function(_0x53a786){logger[_0xf4b1('0xb')]('Attachment,\x20%s,\x20%s',_0x3b9c78,'request\x20sent');logger[_0xf4b1('0xc')](_0xf4b1('0xd'),_0x3b9c78,_0xf4b1('0xe'),JSON[_0xf4b1('0xf')](_0x53a786));if(_0x53a786[_0xf4b1('0x10')]){if(_0x53a786[_0xf4b1('0x10')][_0xf4b1('0x11')]===0x1f4){logger[_0xf4b1('0x10')](_0xf4b1('0x12'),_0x3b9c78,_0x53a786[_0xf4b1('0x10')][_0xf4b1('0x13')]);return _0x59cf77(_0x53a786[_0xf4b1('0x10')][_0xf4b1('0x13')]);}logger['error']('Attachment,\x20%s,\x20%s',_0x3b9c78,_0x53a786[_0xf4b1('0x10')]['message']);return _0x50738c(_0x53a786['error'][_0xf4b1('0x13')]);}else{logger['info']('Attachment,\x20%s,\x20%s',_0x3b9c78,_0xf4b1('0xe'));_0x50738c(_0x53a786['result']['message']);}})['catch'](function(_0x5cb2a1){logger[_0xf4b1('0x10')](_0xf4b1('0x12'),_0x3b9c78,_0x5cb2a1);_0x59cf77(_0x5cb2a1);});});}exports['CreateAttachment']=function(_0x3b378e){var _0x420f9e=this;return new Promise(function(_0x322b38,_0x465da2){return db[_0xf4b1('0x14')][_0xf4b1('0x15')](_0x3b378e['body'],{'raw':_0x3b378e[_0xf4b1('0x16')]?_0x3b378e[_0xf4b1('0x16')]['raw']===undefined?!![]:![]:!![]})[_0xf4b1('0xa')](function(_0x30c239){logger['info'](_0xf4b1('0x17'),_0x3b378e);logger[_0xf4b1('0xc')](_0xf4b1('0x17'),_0x3b378e,JSON[_0xf4b1('0xf')](_0x30c239));_0x322b38(_0x30c239);})['catch'](function(_0x20013c){logger[_0xf4b1('0x10')](_0xf4b1('0x17'),_0x20013c[_0xf4b1('0x13')],_0x3b378e);_0x465da2(_0x420f9e['error'](0x1f4,_0x20013c[_0xf4b1('0x13')]));});});};