69e3ee5aebfb816f38b5afdb7233174e825bb7fd
[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 _0x55ea=['debug','lodash','util','moment','randomstring','ioredis','../../mysqldb','../../config/utils','../../config/logger','../../config/environment','request','then','info','Attachment,\x20%s,\x20%s','Attachment,\x20%s,\x20%s,\x20%s','request\x20sent','stringify','error','message','result','catch','Attachment','body','raw','CreateAttachment'];(function(_0x9826ae,_0x3b9549){var _0x50d382=function(_0x4c2f59){while(--_0x4c2f59){_0x9826ae['push'](_0x9826ae['shift']());}};_0x50d382(++_0x3b9549);}(_0x55ea,0xc9));var _0xa55e=function(_0x13ae89,_0x832c38){_0x13ae89=_0x13ae89-0x0;var _0x1744a0=_0x55ea[_0x13ae89];return _0x1744a0;};'use strict';var _=require(_0xa55e('0x0'));var util=require(_0xa55e('0x1'));var moment=require(_0xa55e('0x2'));var BPromise=require('bluebird');var rs=require(_0xa55e('0x3'));var fs=require('fs');var Redis=require(_0xa55e('0x4'));var db=require(_0xa55e('0x5'))['db'];var utils=require(_0xa55e('0x6'));var logger=require(_0xa55e('0x7'))('rpc');var config=require(_0xa55e('0x8'));var jayson=require('jayson/promise');var client=jayson['client']['http']({'port':0x232a});function respondWithRpcPromise(_0x5a009c,_0x38378e,_0x20f2ac){return new BPromise(function(_0x30b885,_0xca9526){return client[_0xa55e('0x9')](_0x5a009c,_0x20f2ac)[_0xa55e('0xa')](function(_0x32f6f7){logger[_0xa55e('0xb')](_0xa55e('0xc'),_0x38378e,'request\x20sent');logger['debug'](_0xa55e('0xd'),_0x38378e,_0xa55e('0xe'),JSON[_0xa55e('0xf')](_0x32f6f7));if(_0x32f6f7[_0xa55e('0x10')]){if(_0x32f6f7[_0xa55e('0x10')]['code']===0x1f4){logger[_0xa55e('0x10')]('Attachment,\x20%s,\x20%s',_0x38378e,_0x32f6f7[_0xa55e('0x10')][_0xa55e('0x11')]);return _0xca9526(_0x32f6f7[_0xa55e('0x10')][_0xa55e('0x11')]);}logger[_0xa55e('0x10')](_0xa55e('0xc'),_0x38378e,_0x32f6f7[_0xa55e('0x10')][_0xa55e('0x11')]);return _0x30b885(_0x32f6f7[_0xa55e('0x10')]['message']);}else{logger[_0xa55e('0xb')](_0xa55e('0xc'),_0x38378e,_0xa55e('0xe'));_0x30b885(_0x32f6f7[_0xa55e('0x12')][_0xa55e('0x11')]);}})[_0xa55e('0x13')](function(_0x585d3a){logger[_0xa55e('0x10')]('Attachment,\x20%s,\x20%s',_0x38378e,_0x585d3a);_0xca9526(_0x585d3a);});});}exports['CreateAttachment']=function(_0x4599b9){var _0x45935e=this;return new Promise(function(_0x30854e,_0x1bdfa3){return db[_0xa55e('0x14')]['create'](_0x4599b9[_0xa55e('0x15')],{'raw':_0x4599b9['options']?_0x4599b9['options'][_0xa55e('0x16')]===undefined?!![]:![]:!![]})[_0xa55e('0xa')](function(_0x262f6c){logger[_0xa55e('0xb')](_0xa55e('0x17'),_0x4599b9);logger[_0xa55e('0x18')](_0xa55e('0x17'),_0x4599b9,JSON[_0xa55e('0xf')](_0x262f6c));_0x30854e(_0x262f6c);})[_0xa55e('0x13')](function(_0x5b0e74){logger['error'](_0xa55e('0x17'),_0x5b0e74['message'],_0x4599b9);_0x1bdfa3(_0x45935e[_0xa55e('0x10')](0x1f4,_0x5b0e74[_0xa55e('0x11')]));});});};