ca6e4542744485361eddd1fbef65e5ca415ffa9c
[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 _0x6f0d=['Attachment,\x20%s,\x20%s,\x20%s','stringify','error','code','message','result','catch','CreateAttachment','Attachment','create','body','options','debug','util','moment','bluebird','randomstring','../../mysqldb','../../config/utils','../../config/logger','rpc','../../config/environment','client','then','info','Attachment,\x20%s,\x20%s','request\x20sent'];(function(_0x2e1778,_0x58ed92){var _0x233831=function(_0x58a93f){while(--_0x58a93f){_0x2e1778['push'](_0x2e1778['shift']());}};_0x233831(++_0x58ed92);}(_0x6f0d,0x16c));var _0xd6f0=function(_0x29c6bd,_0xf4af22){_0x29c6bd=_0x29c6bd-0x0;var _0x520948=_0x6f0d[_0x29c6bd];return _0x520948;};'use strict';var _=require('lodash');var util=require(_0xd6f0('0x0'));var moment=require(_0xd6f0('0x1'));var BPromise=require(_0xd6f0('0x2'));var rs=require(_0xd6f0('0x3'));var fs=require('fs');var Redis=require('ioredis');var db=require(_0xd6f0('0x4'))['db'];var utils=require(_0xd6f0('0x5'));var logger=require(_0xd6f0('0x6'))(_0xd6f0('0x7'));var config=require(_0xd6f0('0x8'));var jayson=require('jayson/promise');var client=jayson[_0xd6f0('0x9')]['http']({'port':0x232a});function respondWithRpcPromise(_0xe21ac4,_0x1af29c,_0x8b89a9){return new BPromise(function(_0x1a48a0,_0x4c4916){return client['request'](_0xe21ac4,_0x8b89a9)[_0xd6f0('0xa')](function(_0x272c4e){logger[_0xd6f0('0xb')](_0xd6f0('0xc'),_0x1af29c,_0xd6f0('0xd'));logger['debug'](_0xd6f0('0xe'),_0x1af29c,_0xd6f0('0xd'),JSON[_0xd6f0('0xf')](_0x272c4e));if(_0x272c4e[_0xd6f0('0x10')]){if(_0x272c4e['error'][_0xd6f0('0x11')]===0x1f4){logger[_0xd6f0('0x10')](_0xd6f0('0xc'),_0x1af29c,_0x272c4e[_0xd6f0('0x10')][_0xd6f0('0x12')]);return _0x4c4916(_0x272c4e[_0xd6f0('0x10')][_0xd6f0('0x12')]);}logger[_0xd6f0('0x10')](_0xd6f0('0xc'),_0x1af29c,_0x272c4e['error'][_0xd6f0('0x12')]);return _0x1a48a0(_0x272c4e[_0xd6f0('0x10')]['message']);}else{logger[_0xd6f0('0xb')]('Attachment,\x20%s,\x20%s',_0x1af29c,_0xd6f0('0xd'));_0x1a48a0(_0x272c4e[_0xd6f0('0x13')][_0xd6f0('0x12')]);}})[_0xd6f0('0x14')](function(_0x64ff5f){logger[_0xd6f0('0x10')](_0xd6f0('0xc'),_0x1af29c,_0x64ff5f);_0x4c4916(_0x64ff5f);});});}exports[_0xd6f0('0x15')]=function(_0x2e71bd){var _0x1862a9=this;return new Promise(function(_0x23ab6c,_0x17e7c6){return db[_0xd6f0('0x16')][_0xd6f0('0x17')](_0x2e71bd[_0xd6f0('0x18')],{'raw':_0x2e71bd[_0xd6f0('0x19')]?_0x2e71bd['options']['raw']===undefined?!![]:![]:!![]})[_0xd6f0('0xa')](function(_0x264104){logger[_0xd6f0('0xb')]('CreateAttachment',_0x2e71bd);logger[_0xd6f0('0x1a')](_0xd6f0('0x15'),_0x2e71bd,JSON['stringify'](_0x264104));_0x23ab6c(_0x264104);})[_0xd6f0('0x14')](function(_0x515687){logger[_0xd6f0('0x10')](_0xd6f0('0x15'),_0x515687['message'],_0x2e71bd);_0x17e7c6(_0x1862a9[_0xd6f0('0x10')](0x1f4,_0x515687[_0xd6f0('0x12')]));});});};