b332222875885da9f85a17ff1e72f46e068304f1
[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 _0xecb4=['util','bluebird','../../mysqldb','../../config/utils','rpc','../../config/environment','jayson/promise','http','request','info','Attachment,\x20%s,\x20%s','request\x20sent','debug','Attachment,\x20%s,\x20%s,\x20%s','stringify','error','code','message','result','catch','body','options','raw','CreateAttachment'];(function(_0x3dd500,_0x1ab959){var _0x442e4d=function(_0x4283d4){while(--_0x4283d4){_0x3dd500['push'](_0x3dd500['shift']());}};_0x442e4d(++_0x1ab959);}(_0xecb4,0x168));var _0x4ecb=function(_0x2db9e4,_0x67030e){_0x2db9e4=_0x2db9e4-0x0;var _0x2eca40=_0xecb4[_0x2db9e4];return _0x2eca40;};'use strict';var _=require('lodash');var util=require(_0x4ecb('0x0'));var moment=require('moment');var BPromise=require(_0x4ecb('0x1'));var rs=require('randomstring');var fs=require('fs');var Redis=require('ioredis');var db=require(_0x4ecb('0x2'))['db'];var utils=require(_0x4ecb('0x3'));var logger=require('../../config/logger')(_0x4ecb('0x4'));var config=require(_0x4ecb('0x5'));var jayson=require(_0x4ecb('0x6'));var client=jayson['client'][_0x4ecb('0x7')]({'port':0x232a});function respondWithRpcPromise(_0x38ad40,_0xc6f6,_0x30e90b){return new BPromise(function(_0x4380ee,_0xe1ab1b){return client[_0x4ecb('0x8')](_0x38ad40,_0x30e90b)['then'](function(_0x56d597){logger[_0x4ecb('0x9')](_0x4ecb('0xa'),_0xc6f6,_0x4ecb('0xb'));logger[_0x4ecb('0xc')](_0x4ecb('0xd'),_0xc6f6,_0x4ecb('0xb'),JSON[_0x4ecb('0xe')](_0x56d597));if(_0x56d597[_0x4ecb('0xf')]){if(_0x56d597['error'][_0x4ecb('0x10')]===0x1f4){logger[_0x4ecb('0xf')](_0x4ecb('0xa'),_0xc6f6,_0x56d597[_0x4ecb('0xf')][_0x4ecb('0x11')]);return _0xe1ab1b(_0x56d597[_0x4ecb('0xf')][_0x4ecb('0x11')]);}logger[_0x4ecb('0xf')](_0x4ecb('0xa'),_0xc6f6,_0x56d597[_0x4ecb('0xf')][_0x4ecb('0x11')]);return _0x4380ee(_0x56d597[_0x4ecb('0xf')][_0x4ecb('0x11')]);}else{logger[_0x4ecb('0x9')]('Attachment,\x20%s,\x20%s',_0xc6f6,'request\x20sent');_0x4380ee(_0x56d597[_0x4ecb('0x12')]['message']);}})[_0x4ecb('0x13')](function(_0x963fb9){logger[_0x4ecb('0xf')](_0x4ecb('0xa'),_0xc6f6,_0x963fb9);_0xe1ab1b(_0x963fb9);});});}exports['CreateAttachment']=function(_0x50248a){var _0x1bb5ac=this;return new Promise(function(_0x44edc5,_0xd60a2e){return db['Attachment']['create'](_0x50248a[_0x4ecb('0x14')],{'raw':_0x50248a[_0x4ecb('0x15')]?_0x50248a[_0x4ecb('0x15')][_0x4ecb('0x16')]===undefined?!![]:![]:!![]})['then'](function(_0x3b3b3b){logger['info'](_0x4ecb('0x17'),_0x50248a);logger['debug'](_0x4ecb('0x17'),_0x50248a,JSON[_0x4ecb('0xe')](_0x3b3b3b));_0x44edc5(_0x3b3b3b);})[_0x4ecb('0x13')](function(_0x5e1ae2){logger[_0x4ecb('0xf')](_0x4ecb('0x17'),_0x5e1ae2['message'],_0x50248a);_0xd60a2e(_0x1bb5ac['error'](0x1f4,_0x5e1ae2['message']));});});};