Built motion from commit (unavailable).|2.5.22
[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 _0x2f24=['../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../mysqldb','sendStatus','end','status','json','count','offset','set','Content-Range','apply','reject','save','update','then','destroy','error','name','send','fieldName','key','query','keys','filters','intersection','model','attributes','fields','nolimit','limit','sort','where','pick','filter','map','type','VIRTUAL','options','includeAll','include','findAll','rows','catch','show','params','Attachment','rawAttributes','length','merge','find','omit','updatedAt','body','createdAt','create','file','originalname','basename','mimetype','download','findOne','join','root','server/files/attachments/','html-pdf','rimraf','zip-dir','fast-json-patch','request-promise','moment','bluebird','mustache','util','path','to-csv','lodash','squel','crypto','jsforce','desk.js','querystring','papaparse','../../components/parsers/qs'];(function(_0x3fb5e6,_0x4781e1){var _0x2d36fa=function(_0x37d72e){while(--_0x37d72e){_0x3fb5e6['push'](_0x3fb5e6['shift']());}};_0x2d36fa(++_0x4781e1);}(_0x2f24,0x1f1));var _0x42f2=function(_0x3b380d,_0x4bf247){_0x3b380d=_0x3b380d-0x0;var _0x54502b=_0x2f24[_0x3b380d];return _0x54502b;};'use strict';var pdf=require(_0x42f2('0x0'));var emlformat=require('eml-format');var rimraf=require(_0x42f2('0x1'));var zipdir=require(_0x42f2('0x2'));var jsonpatch=require(_0x42f2('0x3'));var rp=require(_0x42f2('0x4'));var moment=require(_0x42f2('0x5'));var BPromise=require(_0x42f2('0x6'));var Mustache=require(_0x42f2('0x7'));var util=require(_0x42f2('0x8'));var path=require(_0x42f2('0x9'));var sox=require('sox');var csv=require(_0x42f2('0xa'));var ejs=require('ejs');var fs=require('fs');var _=require(_0x42f2('0xb'));var squel=require(_0x42f2('0xc'));var crypto=require(_0x42f2('0xd'));var jsforce=require(_0x42f2('0xe'));var deskjs=require(_0x42f2('0xf'));var toCsv=require(_0x42f2('0xa'));var querystring=require(_0x42f2('0x10'));var Papa=require(_0x42f2('0x11'));var Redis=require('ioredis');var authService=require('../../components/auth/service');var qs=require(_0x42f2('0x12'));var as=require(_0x42f2('0x13'));var hardwareService=require(_0x42f2('0x14'));var logger=require(_0x42f2('0x15'))(_0x42f2('0x16'));var utils=require('../../config/utils');var config=require('../../config/environment');var licenseUtil=require('../../config/license/util');var db=require(_0x42f2('0x17'))['db'];function respondWithStatusCode(_0x140f84,_0x27ebb7){_0x27ebb7=_0x27ebb7||0xcc;return function(_0xc7e421){if(_0xc7e421){return _0x140f84[_0x42f2('0x18')](_0x27ebb7);}return _0x140f84['status'](_0x27ebb7)[_0x42f2('0x19')]();};}function respondWithResult(_0x3758ef,_0x333512){_0x333512=_0x333512||0xc8;return function(_0x37bab3){if(_0x37bab3){return _0x3758ef[_0x42f2('0x1a')](_0x333512)[_0x42f2('0x1b')](_0x37bab3);}};}function respondWithFilteredResult(_0x3489a1,_0x514bae){return function(_0x455830){if(_0x455830){var _0x53ef3b=_0x455830[_0x42f2('0x1c')],_0x1b3755=_0x514bae[_0x42f2('0x1d')],_0x1e2e13=_0x514bae[_0x42f2('0x1d')]+_0x514bae['limit'],_0x9f5bfc;if(_0x1e2e13>=_0x53ef3b){_0x1e2e13=_0x53ef3b;_0x9f5bfc=0xc8;}else{_0x9f5bfc=0xce;}_0x3489a1[_0x42f2('0x1a')](_0x9f5bfc);return _0x3489a1[_0x42f2('0x1e')](_0x42f2('0x1f'),_0x1b3755+'-'+_0x1e2e13+'/'+_0x53ef3b)[_0x42f2('0x1b')](_0x455830);}return null;};}function patchUpdates(_0x17f460){return function(_0x297705){try{jsonpatch[_0x42f2('0x20')](_0x297705,_0x17f460,!![]);}catch(_0x442170){return BPromise[_0x42f2('0x21')](_0x442170);}return _0x297705[_0x42f2('0x22')]();};}function saveUpdates(_0x3151af,_0x4f9427){return function(_0x162fdf){if(_0x162fdf){return _0x162fdf[_0x42f2('0x23')](_0x3151af)[_0x42f2('0x24')](function(_0x154022){return _0x154022;});}return null;};}function removeEntity(_0x1c0bf9,_0x3421f1){return function(_0x154850){if(_0x154850){return _0x154850[_0x42f2('0x25')]()[_0x42f2('0x24')](function(){_0x1c0bf9[_0x42f2('0x1a')](0xcc)[_0x42f2('0x19')]();});}};}function handleEntityNotFound(_0x1fbd0d,_0x17856c){return function(_0x2bcb08){if(!_0x2bcb08){_0x1fbd0d[_0x42f2('0x18')](0x194);}return _0x2bcb08;};}function handleError(_0x10fcfe,_0x5d71d2){_0x5d71d2=_0x5d71d2||0x1f4;return function(_0x1b4129){logger[_0x42f2('0x26')](_0x1b4129['stack']);if(_0x1b4129['name']){delete _0x1b4129[_0x42f2('0x27')];}_0x10fcfe[_0x42f2('0x1a')](_0x5d71d2)[_0x42f2('0x28')](_0x1b4129);};}exports['index']=function(_0x4f4832,_0x5e33a4){var _0x4895b9={},_0x4ab7e3={},_0x243302={'count':0x0,'rows':[]};var _0x5047b0=_['map'](db['Attachment']['rawAttributes'],function(_0x166350){return{'name':_0x166350[_0x42f2('0x29')],'type':_0x166350['type'][_0x42f2('0x2a')]};});_0x4ab7e3['model']=_['map'](_0x5047b0,'name');_0x4ab7e3[_0x42f2('0x2b')]=_[_0x42f2('0x2c')](_0x4f4832['query']);_0x4ab7e3[_0x42f2('0x2d')]=_[_0x42f2('0x2e')](_0x4ab7e3[_0x42f2('0x2f')],_0x4ab7e3[_0x42f2('0x2b')]);_0x4895b9[_0x42f2('0x30')]=_[_0x42f2('0x2e')](_0x4ab7e3[_0x42f2('0x2f')],qs[_0x42f2('0x31')](_0x4f4832[_0x42f2('0x2b')]['fields']));_0x4895b9[_0x42f2('0x30')]=_0x4895b9[_0x42f2('0x30')]['length']?_0x4895b9['attributes']:_0x4ab7e3[_0x42f2('0x2f')];if(!_0x4f4832[_0x42f2('0x2b')]['hasOwnProperty'](_0x42f2('0x32'))){_0x4895b9[_0x42f2('0x33')]=qs[_0x42f2('0x33')](_0x4f4832['query']['limit']);_0x4895b9[_0x42f2('0x1d')]=qs[_0x42f2('0x1d')](_0x4f4832[_0x42f2('0x2b')][_0x42f2('0x1d')]);}_0x4895b9['order']=qs[_0x42f2('0x34')](_0x4f4832['query'][_0x42f2('0x34')]);_0x4895b9[_0x42f2('0x35')]=qs[_0x42f2('0x2d')](_[_0x42f2('0x36')](_0x4f4832[_0x42f2('0x2b')],_0x4ab7e3[_0x42f2('0x2d')]),_0x5047b0);if(_0x4f4832[_0x42f2('0x2b')][_0x42f2('0x37')]){_0x4895b9[_0x42f2('0x35')]=_['merge'](_0x4895b9[_0x42f2('0x35')],{'$or':_[_0x42f2('0x38')](_0x5047b0,function(_0x3ad73a){if(_0x3ad73a[_0x42f2('0x39')]!==_0x42f2('0x3a')){var _0x77446e={};_0x77446e[_0x3ad73a[_0x42f2('0x27')]]={'$like':'%'+_0x4f4832['query'][_0x42f2('0x37')]+'%'};return _0x77446e;}})});}_0x4895b9=_['merge']({},_0x4895b9,_0x4f4832[_0x42f2('0x3b')]);var _0x4c8bfc={'where':_0x4895b9[_0x42f2('0x35')]};return db['Attachment'][_0x42f2('0x1c')](_0x4c8bfc)[_0x42f2('0x24')](function(_0x5d6b31){_0x243302[_0x42f2('0x1c')]=_0x5d6b31;if(_0x4f4832['query'][_0x42f2('0x3c')]){_0x4895b9[_0x42f2('0x3d')]=[{'all':!![]}];}return db['Attachment'][_0x42f2('0x3e')](_0x4895b9);})[_0x42f2('0x24')](function(_0x3622ea){_0x243302[_0x42f2('0x3f')]=_0x3622ea;return _0x243302;})['then'](respondWithFilteredResult(_0x5e33a4,_0x4895b9))[_0x42f2('0x40')](handleError(_0x5e33a4,null));};exports[_0x42f2('0x41')]=function(_0x3a8183,_0x16978b){var _0x22309c={'raw':!![],'where':{'id':_0x3a8183[_0x42f2('0x42')]['id']}},_0x4e7f86={};_0x4e7f86[_0x42f2('0x2f')]=_[_0x42f2('0x2c')](db[_0x42f2('0x43')][_0x42f2('0x44')]);_0x4e7f86[_0x42f2('0x2b')]=_[_0x42f2('0x2c')](_0x3a8183[_0x42f2('0x2b')]);_0x4e7f86['filters']=_[_0x42f2('0x2e')](_0x4e7f86['model'],_0x4e7f86[_0x42f2('0x2b')]);_0x22309c[_0x42f2('0x30')]=_[_0x42f2('0x2e')](_0x4e7f86['model'],qs['fields'](_0x3a8183[_0x42f2('0x2b')][_0x42f2('0x31')]));_0x22309c[_0x42f2('0x30')]=_0x22309c['attributes'][_0x42f2('0x45')]?_0x22309c[_0x42f2('0x30')]:_0x4e7f86[_0x42f2('0x2f')];if(_0x3a8183[_0x42f2('0x2b')][_0x42f2('0x3c')]){_0x22309c['include']=[{'all':!![]}];}_0x22309c=_[_0x42f2('0x46')]({},_0x22309c,_0x3a8183['options']);return db[_0x42f2('0x43')][_0x42f2('0x47')](_0x22309c)[_0x42f2('0x24')](handleEntityNotFound(_0x16978b,null))[_0x42f2('0x24')](respondWithResult(_0x16978b,null))[_0x42f2('0x40')](handleError(_0x16978b,null));};exports['clone']=function(_0x51a146,_0x15baca){var _0x5ca686={'where':{'id':_0x51a146[_0x42f2('0x42')]['id']}},_0x369492={};_0x369492[_0x42f2('0x2f')]=_[_0x42f2('0x2c')](db[_0x42f2('0x43')][_0x42f2('0x44')]);_0x5ca686[_0x42f2('0x30')]=_[_0x42f2('0x2e')](_0x369492['model'],qs[_0x42f2('0x31')](_0x51a146[_0x42f2('0x2b')][_0x42f2('0x31')]));_0x5ca686[_0x42f2('0x30')]=_0x5ca686[_0x42f2('0x30')][_0x42f2('0x45')]?_0x5ca686[_0x42f2('0x30')]:_0x369492['model'];if(_0x51a146[_0x42f2('0x2b')][_0x42f2('0x3c')]){_0x5ca686[_0x42f2('0x3d')]=[{'all':!![]}];}_0x5ca686=_['merge']({},_0x5ca686,_0x51a146[_0x42f2('0x3b')]);return db[_0x42f2('0x43')][_0x42f2('0x47')](_0x5ca686)['then'](handleEntityNotFound(_0x15baca,null))[_0x42f2('0x24')](function(_0x5b7b06){if(_0x5b7b06){var _0x4eac0b=_0x5b7b06['get']({'plain':!![]});_0x4eac0b=qs[_0x42f2('0x48')](_0x4eac0b,['id','createdAt',_0x42f2('0x49')]);_0x51a146[_0x42f2('0x4a')]=_['omit'](_0x51a146[_0x42f2('0x4a')],['id',_0x42f2('0x4b'),_0x42f2('0x49')]);return db[_0x42f2('0x43')][_0x42f2('0x4c')](_[_0x42f2('0x46')](_0x4eac0b,_0x51a146[_0x42f2('0x4a')]),{'include':_0x51a146[_0x42f2('0x2b')][_0x42f2('0x3c')]?[{'all':!![]}]:undefined});}})['then'](respondWithResult(_0x15baca,0xc9))['catch'](handleError(_0x15baca,null));};exports['update']=function(_0x5a8ec4,_0x223e35){if(_0x5a8ec4[_0x42f2('0x4a')]['id']){delete _0x5a8ec4[_0x42f2('0x4a')]['id'];}return db[_0x42f2('0x43')]['find']({'where':{'id':_0x5a8ec4['params']['id']}})['then'](handleEntityNotFound(_0x223e35,null))[_0x42f2('0x24')](saveUpdates(_0x5a8ec4[_0x42f2('0x4a')],null))[_0x42f2('0x24')](respondWithResult(_0x223e35,null))[_0x42f2('0x40')](handleError(_0x223e35,null));};exports[_0x42f2('0x25')]=function(_0x54e1d2,_0xbefce3){return db[_0x42f2('0x43')][_0x42f2('0x47')]({'where':{'id':_0x54e1d2[_0x42f2('0x42')]['id']}})['then'](handleEntityNotFound(_0xbefce3,null))['then'](removeEntity(_0xbefce3,null))[_0x42f2('0x40')](handleError(_0xbefce3,null));};exports[_0x42f2('0x4c')]=function(_0x445b8f,_0x5da4c1,_0x48330d){_0x445b8f['body']['name']=_0x445b8f[_0x42f2('0x4d')][_0x42f2('0x4e')];_0x445b8f[_0x42f2('0x4a')][_0x42f2('0x4f')]=_0x445b8f['file']['filename'];_0x445b8f['body']['type']=_0x445b8f[_0x42f2('0x4d')][_0x42f2('0x50')];return db[_0x42f2('0x43')][_0x42f2('0x4c')](_0x445b8f[_0x42f2('0x4a')])[_0x42f2('0x24')](respondWithResult(_0x5da4c1,0xc9))[_0x42f2('0x40')](handleError(_0x5da4c1,null));};exports[_0x42f2('0x51')]=function(_0x43b620,_0x14777a,_0x55006e){return db[_0x42f2('0x43')][_0x42f2('0x52')]({'where':{'id':_0x43b620[_0x42f2('0x42')]['id']},'raw':!![]})['then'](handleEntityNotFound(_0x14777a,null))[_0x42f2('0x24')](function(_0x5dcf61){if(_0x5dcf61){return _0x14777a[_0x42f2('0x51')](path[_0x42f2('0x53')](config[_0x42f2('0x54')],_0x42f2('0x55'),_0x5dcf61[_0x42f2('0x4f')]));}})[_0x42f2('0x40')](handleError(_0x14777a,null));};