18 var _0x4bd3=['error','stack','name','send','index','map','Attachment','rawAttributes','fieldName','key','model','query','keys','attributes','intersection','fields','length','hasOwnProperty','nolimit','sort','where','filters','pick','VIRTUAL','filter','merge','options','includeAll','include','findAll','rows','catch','find','params','omit','body','create','destroy','originalname','basename','filename','type','file','mimetype','download','findOne','ChatOfflineMessageId','join','eml-format','zip-dir','fast-json-patch','mustache','util','path','to-csv','ejs','lodash','squel','jsforce','desk.js','querystring','papaparse','ioredis','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','../../config/environment','sendStatus','status','end','json','count','offset','limit','set','apply','reject','save','update','then'];(function(_0x4b73a2,_0x40b5fe){var _0x383c66=function(_0x3917ae){while(--_0x3917ae){_0x4b73a2['push'](_0x4b73a2['shift']());}};_0x383c66(++_0x40b5fe);}(_0x4bd3,0x174));var _0x34bd=function(_0x334b55,_0x1f2c4d){_0x334b55=_0x334b55-0x0;var _0x52c824=_0x4bd3[_0x334b55];return _0x52c824;};'use strict';var emlformat=require(_0x34bd('0x0'));var rimraf=require('rimraf');var zipdir=require(_0x34bd('0x1'));var jsonpatch=require(_0x34bd('0x2'));var rp=require('request-promise');var moment=require('moment');var BPromise=require('bluebird');var Mustache=require(_0x34bd('0x3'));var util=require(_0x34bd('0x4'));var path=require(_0x34bd('0x5'));var sox=require('sox');var csv=require(_0x34bd('0x6'));var ejs=require(_0x34bd('0x7'));var fs=require('fs');var fs_extra=require('fs-extra');var _=require(_0x34bd('0x8'));var squel=require(_0x34bd('0x9'));var crypto=require('crypto');var jsforce=require(_0x34bd('0xa'));var deskjs=require(_0x34bd('0xb'));var toCsv=require(_0x34bd('0x6'));var querystring=require(_0x34bd('0xc'));var Papa=require(_0x34bd('0xd'));var Redis=require(_0x34bd('0xe'));var authService=require('../../components/auth/service');var qs=require(_0x34bd('0xf'));var as=require(_0x34bd('0x10'));var hardwareService=require(_0x34bd('0x11'));var logger=require(_0x34bd('0x12'))('api');var utils=require('../../config/utils');var config=require(_0x34bd('0x13'));var licenseUtil=require('../../config/license/util');var db=require('../../mysqldb')['db'];function respondWithStatusCode(_0x275d80,_0x1f19b9){_0x1f19b9=_0x1f19b9||0xcc;return function(_0x282af4){if(_0x282af4){return _0x275d80[_0x34bd('0x14')](_0x1f19b9);}return _0x275d80[_0x34bd('0x15')](_0x1f19b9)[_0x34bd('0x16')]();};}function respondWithResult(_0x4134ee,_0x236f6b){_0x236f6b=_0x236f6b||0xc8;return function(_0xf6d2f2){if(_0xf6d2f2){return _0x4134ee['status'](_0x236f6b)[_0x34bd('0x17')](_0xf6d2f2);}};}function respondWithFilteredResult(_0x4d4955,_0x4e3886){return function(_0x6638ed){if(_0x6638ed){var _0x30b3f2=_0x6638ed[_0x34bd('0x18')],_0x280c1a=_0x4e3886[_0x34bd('0x19')],_0x2dc917=_0x4e3886[_0x34bd('0x19')]+_0x4e3886[_0x34bd('0x1a')],_0x34b91b;if(_0x2dc917>=_0x30b3f2){_0x2dc917=_0x30b3f2;_0x34b91b=0xc8;}else{_0x34b91b=0xce;}_0x4d4955[_0x34bd('0x15')](_0x34b91b);return _0x4d4955[_0x34bd('0x1b')]('Content-Range',_0x280c1a+'-'+_0x2dc917+'/'+_0x30b3f2)[_0x34bd('0x17')](_0x6638ed);}return null;};}function patchUpdates(_0x324f7d){return function(_0x265e70){try{jsonpatch[_0x34bd('0x1c')](_0x265e70,_0x324f7d,!![]);}catch(_0x3976e4){return BPromise[_0x34bd('0x1d')](_0x3976e4);}return _0x265e70[_0x34bd('0x1e')]();};}function saveUpdates(_0x3d5f76,_0x130bd0){return function(_0x55538e){if(_0x55538e){return _0x55538e[_0x34bd('0x1f')](_0x3d5f76)[_0x34bd('0x20')](function(_0x49f625){return _0x49f625;});}return null;};}function removeEntity(_0x14254b,_0x463224){return function(_0x5e0c06){if(_0x5e0c06){return _0x5e0c06['destroy']()['then'](function(){_0x14254b['status'](0xcc)[_0x34bd('0x16')]();});}};}function handleEntityNotFound(_0x503a60,_0x10fc4b){return function(_0x1c2282){if(!_0x1c2282){_0x503a60[_0x34bd('0x14')](0x194);}return _0x1c2282;};}function handleError(_0x5c3c85,_0x41bffd){_0x41bffd=_0x41bffd||0x1f4;return function(_0x14479a){logger[_0x34bd('0x21')](_0x14479a[_0x34bd('0x22')]);if(_0x14479a['name']){delete _0x14479a[_0x34bd('0x23')];}_0x5c3c85[_0x34bd('0x15')](_0x41bffd)[_0x34bd('0x24')](_0x14479a);};}exports[_0x34bd('0x25')]=function(_0x56baf7,_0x45b4eb){var _0x3fe8b0={},_0x5d2e3d={},_0x27747e={'count':0x0,'rows':[]};var _0x510a30=_[_0x34bd('0x26')](db[_0x34bd('0x27')][_0x34bd('0x28')],function(_0x4500c8){return{'name':_0x4500c8[_0x34bd('0x29')],'type':_0x4500c8['type'][_0x34bd('0x2a')]};});_0x5d2e3d[_0x34bd('0x2b')]=_['map'](_0x510a30,'name');_0x5d2e3d[_0x34bd('0x2c')]=_[_0x34bd('0x2d')](_0x56baf7[_0x34bd('0x2c')]);_0x5d2e3d['filters']=_['intersection'](_0x5d2e3d[_0x34bd('0x2b')],_0x5d2e3d[_0x34bd('0x2c')]);_0x3fe8b0[_0x34bd('0x2e')]=_[_0x34bd('0x2f')](_0x5d2e3d['model'],qs[_0x34bd('0x30')](_0x56baf7[_0x34bd('0x2c')][_0x34bd('0x30')]));_0x3fe8b0[_0x34bd('0x2e')]=_0x3fe8b0[_0x34bd('0x2e')][_0x34bd('0x31')]?_0x3fe8b0['attributes']:_0x5d2e3d[_0x34bd('0x2b')];if(!_0x56baf7['query'][_0x34bd('0x32')](_0x34bd('0x33'))){_0x3fe8b0[_0x34bd('0x1a')]=qs['limit'](_0x56baf7[_0x34bd('0x2c')][_0x34bd('0x1a')]);_0x3fe8b0['offset']=qs[_0x34bd('0x19')](_0x56baf7[_0x34bd('0x2c')][_0x34bd('0x19')]);}_0x3fe8b0['order']=qs[_0x34bd('0x34')](_0x56baf7[_0x34bd('0x2c')]['sort']);_0x3fe8b0[_0x34bd('0x35')]=qs[_0x34bd('0x36')](_[_0x34bd('0x37')](_0x56baf7[_0x34bd('0x2c')],_0x5d2e3d[_0x34bd('0x36')]),_0x510a30);if(_0x56baf7[_0x34bd('0x2c')]['filter']){_0x3fe8b0['where']=_['merge'](_0x3fe8b0[_0x34bd('0x35')],{'$or':_[_0x34bd('0x26')](_0x510a30,function(_0x5e30c5){if(_0x5e30c5['type']!==_0x34bd('0x38')){var _0x4f5c8f={};_0x4f5c8f[_0x5e30c5['name']]={'$like':'%'+_0x56baf7[_0x34bd('0x2c')][_0x34bd('0x39')]+'%'};return _0x4f5c8f;}})});}_0x3fe8b0=_[_0x34bd('0x3a')]({},_0x3fe8b0,_0x56baf7[_0x34bd('0x3b')]);var _0x2af1af={'where':_0x3fe8b0['where']};return db['Attachment'][_0x34bd('0x18')](_0x2af1af)['then'](function(_0xce6bc6){_0x27747e[_0x34bd('0x18')]=_0xce6bc6;if(_0x56baf7[_0x34bd('0x2c')][_0x34bd('0x3c')]){_0x3fe8b0[_0x34bd('0x3d')]=[{'all':!![]}];}return db['Attachment'][_0x34bd('0x3e')](_0x3fe8b0);})[_0x34bd('0x20')](function(_0x16858c){_0x27747e[_0x34bd('0x3f')]=_0x16858c;return _0x27747e;})['then'](respondWithFilteredResult(_0x45b4eb,_0x3fe8b0))[_0x34bd('0x40')](handleError(_0x45b4eb,null));};exports['show']=function(_0x26e268,_0x560282){var _0x561f95={'raw':!![],'where':{'id':_0x26e268['params']['id']}},_0x279765={};_0x279765[_0x34bd('0x2b')]=_[_0x34bd('0x2d')](db[_0x34bd('0x27')][_0x34bd('0x28')]);_0x279765[_0x34bd('0x2c')]=_[_0x34bd('0x2d')](_0x26e268[_0x34bd('0x2c')]);_0x279765['filters']=_['intersection'](_0x279765['model'],_0x279765[_0x34bd('0x2c')]);_0x561f95[_0x34bd('0x2e')]=_[_0x34bd('0x2f')](_0x279765[_0x34bd('0x2b')],qs['fields'](_0x26e268[_0x34bd('0x2c')][_0x34bd('0x30')]));_0x561f95[_0x34bd('0x2e')]=_0x561f95[_0x34bd('0x2e')][_0x34bd('0x31')]?_0x561f95['attributes']:_0x279765[_0x34bd('0x2b')];if(_0x26e268['query']['includeAll']){_0x561f95[_0x34bd('0x3d')]=[{'all':!![]}];}_0x561f95=_['merge']({},_0x561f95,_0x26e268[_0x34bd('0x3b')]);return db[_0x34bd('0x27')][_0x34bd('0x41')](_0x561f95)[_0x34bd('0x20')](handleEntityNotFound(_0x560282,null))[_0x34bd('0x20')](respondWithResult(_0x560282,null))['catch'](handleError(_0x560282,null));};exports['clone']=function(_0x33e8e8,_0x51f892){var _0x1f3db3={'where':{'id':_0x33e8e8[_0x34bd('0x42')]['id']}},_0x223adb={};_0x223adb['model']=_['keys'](db['Attachment']['rawAttributes']);_0x1f3db3[_0x34bd('0x2e')]=_['intersection'](_0x223adb[_0x34bd('0x2b')],qs['fields'](_0x33e8e8[_0x34bd('0x2c')][_0x34bd('0x30')]));_0x1f3db3[_0x34bd('0x2e')]=_0x1f3db3[_0x34bd('0x2e')][_0x34bd('0x31')]?_0x1f3db3['attributes']:_0x223adb[_0x34bd('0x2b')];if(_0x33e8e8[_0x34bd('0x2c')][_0x34bd('0x3c')]){_0x1f3db3[_0x34bd('0x3d')]=[{'all':!![]}];}_0x1f3db3=_[_0x34bd('0x3a')]({},_0x1f3db3,_0x33e8e8['options']);return db[_0x34bd('0x27')][_0x34bd('0x41')](_0x1f3db3)['then'](handleEntityNotFound(_0x51f892,null))[_0x34bd('0x20')](function(_0x1a935e){if(_0x1a935e){var _0x52501b=_0x1a935e['get']({'plain':!![]});_0x52501b=qs[_0x34bd('0x43')](_0x52501b,['id','createdAt','updatedAt']);_0x33e8e8[_0x34bd('0x44')]=_[_0x34bd('0x43')](_0x33e8e8['body'],['id','createdAt','updatedAt']);return db['Attachment'][_0x34bd('0x45')](_[_0x34bd('0x3a')](_0x52501b,_0x33e8e8['body']),{'include':_0x33e8e8['query']['includeAll']?[{'all':!![]}]:undefined});}})[_0x34bd('0x20')](respondWithResult(_0x51f892,0xc9))[_0x34bd('0x40')](handleError(_0x51f892,null));};exports['update']=function(_0x162a08,_0x23b4cd){if(_0x162a08[_0x34bd('0x44')]['id']){delete _0x162a08[_0x34bd('0x44')]['id'];}return db[_0x34bd('0x27')][_0x34bd('0x41')]({'where':{'id':_0x162a08['params']['id']}})[_0x34bd('0x20')](handleEntityNotFound(_0x23b4cd,null))[_0x34bd('0x20')](saveUpdates(_0x162a08[_0x34bd('0x44')],null))[_0x34bd('0x20')](respondWithResult(_0x23b4cd,null))['catch'](handleError(_0x23b4cd,null));};exports[_0x34bd('0x46')]=function(_0x5235e4,_0x463ca0){return db['Attachment'][_0x34bd('0x41')]({'where':{'id':_0x5235e4[_0x34bd('0x42')]['id']}})[_0x34bd('0x20')](handleEntityNotFound(_0x463ca0,null))[_0x34bd('0x20')](removeEntity(_0x463ca0,null))[_0x34bd('0x40')](handleError(_0x463ca0,null));};exports[_0x34bd('0x45')]=function(_0x6db4ba,_0x28394c,_0x4768f8){_0x6db4ba[_0x34bd('0x44')][_0x34bd('0x23')]=_0x6db4ba['file'][_0x34bd('0x47')];_0x6db4ba['body'][_0x34bd('0x48')]=_0x6db4ba['file'][_0x34bd('0x49')];_0x6db4ba['body'][_0x34bd('0x4a')]=_0x6db4ba[_0x34bd('0x4b')][_0x34bd('0x4c')];return db[_0x34bd('0x27')][_0x34bd('0x45')](_0x6db4ba[_0x34bd('0x44')])[_0x34bd('0x20')](respondWithResult(_0x28394c,0xc9))[_0x34bd('0x40')](handleError(_0x28394c,null));};exports[_0x34bd('0x4d')]=function(_0x1d2bbe,_0x25a505,_0x3e65e6){return db[_0x34bd('0x27')][_0x34bd('0x4e')]({'where':{'id':_0x1d2bbe[_0x34bd('0x42')]['id']},'raw':!![]})['then'](handleEntityNotFound(_0x25a505,null))['then'](function(_0x246c52){if(_0x246c52){var _0x79e6b4=_0x246c52[_0x34bd('0x4f')]!==null;var _0x3e8c8e=path[_0x34bd('0x50')](config['root'],'server/files/attachments/');if(_0x79e6b4){_0x3e8c8e=path['join'](_0x3e8c8e,'offline-chat/');}var _0x24c635=path[_0x34bd('0x50')](_0x3e8c8e,_0x246c52['basename']);return _0x25a505[_0x34bd('0x4d')](_0x24c635);}})[_0x34bd('0x40')](handleError(_0x25a505,null));};