Built motion from commit (unavailable).|2.4.3
[motion2.git] / server / api / attachment / attachment.controller.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 _0x2eb2=['mimetype','download','findOne','join','root','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','moment','util','to-csv','crypto','jsforce','desk.js','querystring','papaparse','../../components/parsers/qs','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','../../mysqldb','sendStatus','status','end','count','offset','limit','set','json','apply','save','update','then','destroy','error','stack','name','send','index','rawAttributes','model','query','filters','intersection','attributes','fields','length','hasOwnProperty','nolimit','order','sort','filter','where','map','type','key','field','merge','options','Attachment','includeAll','include','catch','show','body','find','params','create','file','originalname','basename','filename'];(function(_0x3639e8,_0x320f73){var _0xcba16b=function(_0xa773aa){while(--_0xa773aa){_0x3639e8['push'](_0x3639e8['shift']());}};_0xcba16b(++_0x320f73);}(_0x2eb2,0x1cd));var _0x22eb=function(_0x491a7f,_0x28bb80){_0x491a7f=_0x491a7f-0x0;var _0x3d8f44=_0x2eb2[_0x491a7f];return _0x3d8f44;};'use strict';var pdf=require('html-pdf');var emlformat=require(_0x22eb('0x0'));var rimraf=require(_0x22eb('0x1'));var zipdir=require(_0x22eb('0x2'));var jsonpatch=require(_0x22eb('0x3'));var rp=require(_0x22eb('0x4'));var moment=require(_0x22eb('0x5'));var BPromise=require('bluebird');var Mustache=require('mustache');var util=require(_0x22eb('0x6'));var path=require('path');var sox=require('sox');var csv=require(_0x22eb('0x7'));var ejs=require('ejs');var fs=require('fs');var _=require('lodash');var squel=require('squel');var crypto=require(_0x22eb('0x8'));var jsforce=require(_0x22eb('0x9'));var deskjs=require(_0x22eb('0xa'));var toCsv=require(_0x22eb('0x7'));var querystring=require(_0x22eb('0xb'));var Papa=require(_0x22eb('0xc'));var Redis=require('ioredis');var authService=require('../../components/auth/service');var qs=require(_0x22eb('0xd'));var hardwareService=require(_0x22eb('0xe'));var logger=require(_0x22eb('0xf'))(_0x22eb('0x10'));var utils=require(_0x22eb('0x11'));var config=require(_0x22eb('0x12'));var db=require(_0x22eb('0x13'))['db'];function respondWithStatusCode(_0x5a7641,_0x4fb536){_0x4fb536=_0x4fb536||0xcc;return function(_0x67f47e){if(_0x67f47e){return _0x5a7641[_0x22eb('0x14')](_0x4fb536);}return _0x5a7641[_0x22eb('0x15')](_0x4fb536)[_0x22eb('0x16')]();};}function respondWithResult(_0x402d2d,_0x6c69b7){_0x6c69b7=_0x6c69b7||0xc8;return function(_0x314a1b){if(_0x314a1b){return _0x402d2d['status'](_0x6c69b7)['json'](_0x314a1b);}};}function respondWithFilteredResult(_0x10bfe7,_0x3f2e91){return function(_0xd9ae70){if(_0xd9ae70){var _0x5ee4da=_0xd9ae70[_0x22eb('0x17')],_0x42ce4b=_0x3f2e91[_0x22eb('0x18')],_0x1ba626=_0x3f2e91[_0x22eb('0x18')]+_0x3f2e91[_0x22eb('0x19')],_0x1757d1;if(_0x1ba626>=_0x5ee4da){_0x1ba626=_0x5ee4da;_0x1757d1=0xc8;}else{_0x1757d1=0xce;}_0x10bfe7[_0x22eb('0x15')](_0x1757d1);return _0x10bfe7[_0x22eb('0x1a')]('Content-Range',_0x42ce4b+'-'+_0x1ba626+'/'+_0x5ee4da)[_0x22eb('0x1b')](_0xd9ae70);}return null;};}function patchUpdates(_0x3e0e7c){return function(_0x30791b){try{jsonpatch[_0x22eb('0x1c')](_0x30791b,_0x3e0e7c,!![]);}catch(_0x184f67){return BPromise['reject'](_0x184f67);}return _0x30791b[_0x22eb('0x1d')]();};}function saveUpdates(_0x23f920,_0x30573e){return function(_0x3db0d9){if(_0x3db0d9){return _0x3db0d9[_0x22eb('0x1e')](_0x23f920)[_0x22eb('0x1f')](function(_0x226499){return _0x226499;});}return null;};}function removeEntity(_0x254640,_0x105867){return function(_0x67f333){if(_0x67f333){return _0x67f333[_0x22eb('0x20')]()[_0x22eb('0x1f')](function(){_0x254640[_0x22eb('0x15')](0xcc)['end']();});}};}function handleEntityNotFound(_0x1f8d33,_0x9521ef){return function(_0x52045d){if(!_0x52045d){_0x1f8d33['sendStatus'](0x194);}return _0x52045d;};}function handleError(_0x57390e,_0x40a6cb){_0x40a6cb=_0x40a6cb||0x1f4;return function(_0x5bb7d6){logger[_0x22eb('0x21')](_0x5bb7d6[_0x22eb('0x22')]);if(_0x5bb7d6[_0x22eb('0x23')]){delete _0x5bb7d6[_0x22eb('0x23')];}_0x57390e[_0x22eb('0x15')](_0x40a6cb)[_0x22eb('0x24')](_0x5bb7d6);};}exports[_0x22eb('0x25')]=function(_0x182c63,_0x151ea2){var _0x7028f1={},_0x316c0e={},_0x3b26c3={'count':0x0,'rows':[]};var _0x3c4be7=db['Attachment'][_0x22eb('0x26')];_0x316c0e[_0x22eb('0x27')]=_['keys'](_0x3c4be7);_0x316c0e[_0x22eb('0x28')]=_['keys'](_0x182c63[_0x22eb('0x28')]);_0x316c0e[_0x22eb('0x29')]=_[_0x22eb('0x2a')](_0x316c0e[_0x22eb('0x27')],_0x316c0e['query']);_0x7028f1[_0x22eb('0x2b')]=_[_0x22eb('0x2a')](_0x316c0e[_0x22eb('0x27')],qs[_0x22eb('0x2c')](_0x182c63['query'][_0x22eb('0x2c')]));_0x7028f1['attributes']=_0x7028f1[_0x22eb('0x2b')][_0x22eb('0x2d')]?_0x7028f1[_0x22eb('0x2b')]:_0x316c0e['model'];if(!_0x182c63[_0x22eb('0x28')][_0x22eb('0x2e')](_0x22eb('0x2f'))){_0x7028f1[_0x22eb('0x19')]=qs[_0x22eb('0x19')](_0x182c63[_0x22eb('0x28')][_0x22eb('0x19')]);_0x7028f1[_0x22eb('0x18')]=qs[_0x22eb('0x18')](_0x182c63[_0x22eb('0x28')][_0x22eb('0x18')]);}_0x7028f1[_0x22eb('0x30')]=qs[_0x22eb('0x31')](_0x182c63[_0x22eb('0x28')][_0x22eb('0x31')]);_0x7028f1['where']=qs[_0x22eb('0x29')](_['pick'](_0x182c63[_0x22eb('0x28')],_0x316c0e['filters']));if(_0x182c63[_0x22eb('0x28')][_0x22eb('0x32')]){_0x7028f1[_0x22eb('0x33')]=_['merge'](_0x7028f1['where'],{'$or':_[_0x22eb('0x34')](_0x3c4be7,function(_0x11f34a){if(_0x11f34a[_0x22eb('0x35')][_0x22eb('0x36')]!=='VIRTUAL'){var _0x3ba5a1={};_0x3ba5a1[_0x11f34a[_0x22eb('0x37')]]={'$like':'%'+_0x182c63[_0x22eb('0x28')][_0x22eb('0x32')]+'%'};return _0x3ba5a1;}})});}_0x7028f1=_[_0x22eb('0x38')]({},_0x7028f1,_0x182c63[_0x22eb('0x39')]);var _0x5b44d3={'where':_0x7028f1['where']};return db[_0x22eb('0x3a')][_0x22eb('0x17')](_0x5b44d3)[_0x22eb('0x1f')](function(_0x4cabea){_0x3b26c3[_0x22eb('0x17')]=_0x4cabea;if(_0x182c63[_0x22eb('0x28')][_0x22eb('0x3b')]){_0x7028f1[_0x22eb('0x3c')]=[{'all':!![]}];}return db[_0x22eb('0x3a')]['findAll'](_0x7028f1);})[_0x22eb('0x1f')](function(_0x23663c){_0x3b26c3['rows']=_0x23663c;return _0x3b26c3;})[_0x22eb('0x1f')](respondWithFilteredResult(_0x151ea2,_0x7028f1))[_0x22eb('0x3d')](handleError(_0x151ea2,null));};exports[_0x22eb('0x3e')]=function(_0x592fbf,_0x513dc9){var _0x556d8f={'raw':!![],'where':{'id':_0x592fbf['params']['id']}},_0x2b8675={};_0x2b8675[_0x22eb('0x27')]=_['keys'](db[_0x22eb('0x3a')][_0x22eb('0x26')]);_0x2b8675[_0x22eb('0x28')]=_['keys'](_0x592fbf[_0x22eb('0x28')]);_0x2b8675[_0x22eb('0x29')]=_[_0x22eb('0x2a')](_0x2b8675[_0x22eb('0x27')],_0x2b8675['query']);_0x556d8f['attributes']=_[_0x22eb('0x2a')](_0x2b8675[_0x22eb('0x27')],qs['fields'](_0x592fbf[_0x22eb('0x28')][_0x22eb('0x2c')]));_0x556d8f[_0x22eb('0x2b')]=_0x556d8f[_0x22eb('0x2b')]['length']?_0x556d8f['attributes']:_0x2b8675['model'];if(_0x592fbf['query'][_0x22eb('0x3b')]){_0x556d8f[_0x22eb('0x3c')]=[{'all':!![]}];}_0x556d8f=_[_0x22eb('0x38')]({},_0x556d8f,_0x592fbf['options']);return db['Attachment']['find'](_0x556d8f)[_0x22eb('0x1f')](handleEntityNotFound(_0x513dc9,null))[_0x22eb('0x1f')](respondWithResult(_0x513dc9,null))[_0x22eb('0x3d')](handleError(_0x513dc9,null));};exports[_0x22eb('0x1e')]=function(_0x4aba6a,_0x1ae588){if(_0x4aba6a[_0x22eb('0x3f')]['id']){delete _0x4aba6a[_0x22eb('0x3f')]['id'];}return db[_0x22eb('0x3a')]['find']({'where':{'id':_0x4aba6a['params']['id']}})[_0x22eb('0x1f')](handleEntityNotFound(_0x1ae588,null))[_0x22eb('0x1f')](saveUpdates(_0x4aba6a[_0x22eb('0x3f')],null))[_0x22eb('0x1f')](respondWithResult(_0x1ae588,null))[_0x22eb('0x3d')](handleError(_0x1ae588,null));};exports['destroy']=function(_0x47a3c3,_0x8e88b1){return db[_0x22eb('0x3a')][_0x22eb('0x40')]({'where':{'id':_0x47a3c3[_0x22eb('0x41')]['id']}})[_0x22eb('0x1f')](handleEntityNotFound(_0x8e88b1,null))[_0x22eb('0x1f')](removeEntity(_0x8e88b1,null))[_0x22eb('0x3d')](handleError(_0x8e88b1,null));};exports[_0x22eb('0x42')]=function(_0x4a0f0b,_0x1257b0,_0xbf607a){_0x4a0f0b['body'][_0x22eb('0x23')]=_0x4a0f0b[_0x22eb('0x43')][_0x22eb('0x44')];_0x4a0f0b[_0x22eb('0x3f')][_0x22eb('0x45')]=_0x4a0f0b[_0x22eb('0x43')][_0x22eb('0x46')];_0x4a0f0b['body']['type']=_0x4a0f0b[_0x22eb('0x43')][_0x22eb('0x47')];return db['Attachment']['create'](_0x4a0f0b[_0x22eb('0x3f')])[_0x22eb('0x1f')](respondWithResult(_0x1257b0,0xc9))[_0x22eb('0x3d')](handleError(_0x1257b0,null));};exports[_0x22eb('0x48')]=function(_0x2bdfa0,_0x1c64bb,_0xcc02ee){return db[_0x22eb('0x3a')][_0x22eb('0x49')]({'where':{'id':_0x2bdfa0[_0x22eb('0x41')]['id']},'raw':!![]})[_0x22eb('0x1f')](handleEntityNotFound(_0x1c64bb,null))[_0x22eb('0x1f')](function(_0x252990){if(_0x252990){return _0x1c64bb['download'](path[_0x22eb('0x4a')](config[_0x22eb('0x4b')],'server/files/attachments/',_0x252990[_0x22eb('0x45')]));}})['catch'](handleError(_0x1c64bb,null));};