Built motion from commit eddce310.|2.6.12
[motion2.git] / server / api / plugin / plugin.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 _0x17b2=['extract-zip','ioredis','../../components/auth/service','../../components/parsers/qs','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','redis','defaults','localhost','register','sendStatus','status','end','json','undefined','limit','offset','count','Content-Range','apply','save','update','then','get','error','stack','name','index','map','Plugin','fieldName','type','key','model','query','filters','intersection','attributes','fields','length','hasOwnProperty','nolimit','order','pick','filter','merge','where','options','includeAll','include','rows','catch','params','keys','rawAttributes','find','join','root','server/files/plugins','format','%s.zip','basename','createWriteStream','zip','warning','code','ENOENT','Sequelize','Error','Error\x20while\x20generating\x20the\x20zip\x20archive','**/*','node_modules/**/*','attachments/**/*','finalize','existsSync','Plugin\x20not\x20found','download','Error\x20while\x20downloading\x20the\x20plugin','unlinkSync','info','Download\x20completed','upload','filename','extname','file','Plugin\x20upload\x20filepath:\x20%s','0777','readdirSync','lstatSync','isFile','Invalid\x20plugin\x20structure','isDirectory','some','manifest.json','Plugin\x20manifest\x20missing','readFileSync','Invalid\x20manifest:\x20type\x20missing','version','Invalid\x20manifest:\x20version\x20not\x20specified','parameters','Invalid\x20manifest:\x20parameters\x20missing','html','views','admin','script','scriptPath','Invalid\x20manifest:\x20script\x20path\x20missing','Invalid\x20manifest:\x20invalid\x20type','description','sidebar','always','icon','Warning:\x20admin\x20view\x20not\x20specified','agent','test','plugins','Warning:\x20agent\x20view\x20not\x20specified','scriptName','create','body','role','userProfileId','Unable\x20to\x20retrieve\x20the\x20current\x20user','user','UserProfileSection','Plugins','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','send','Zip\x20archive\x20removed','Extracted\x20folder\x20removed','delete','destroy','webhookGet','port','\x27PORT\x27\x20parameter\x20not\x20specified','hostname','http://localhost:','encoding','method','headers','content-length','content-type','statusCode','webhookPost','\x27PATH\x27\x20parameter\x20not\x20specified','%s%s','rimraf','zip-dir','moment','mustache','util','path','sox','lodash','crypto','to-csv','querystring','papaparse'];(function(_0x285a06,_0x344860){var _0x18191c=function(_0x417050){while(--_0x417050){_0x285a06['push'](_0x285a06['shift']());}};_0x18191c(++_0x344860);}(_0x17b2,0x1dd));var _0x217b=function(_0x336461,_0xa764aa){_0x336461=_0x336461-0x0;var _0x256a53=_0x17b2[_0x336461];return _0x256a53;};'use strict';var emlformat=require('eml-format');var rimraf=require(_0x217b('0x0'));var zipdir=require(_0x217b('0x1'));var jsonpatch=require('fast-json-patch');var rp=require('request-promise');var moment=require(_0x217b('0x2'));var BPromise=require('bluebird');var Mustache=require(_0x217b('0x3'));var util=require(_0x217b('0x4'));var path=require(_0x217b('0x5'));var sox=require(_0x217b('0x6'));var csv=require('to-csv');var ejs=require('ejs');var fs=require('fs');var fs_extra=require('fs-extra');var _=require(_0x217b('0x7'));var squel=require('squel');var crypto=require(_0x217b('0x8'));var jsforce=require('jsforce');var deskjs=require('desk.js');var toCsv=require(_0x217b('0x9'));var querystring=require(_0x217b('0xa'));var Papa=require(_0x217b('0xb'));var extract=require(_0x217b('0xc'));var rimraf=require(_0x217b('0x0'));var archiver=require('archiver');var Redis=require(_0x217b('0xd'));var authService=require(_0x217b('0xe'));var qs=require(_0x217b('0xf'));var as=require('../../components/parsers/advancedSearch');var hardwareService=require(_0x217b('0x10'));var logger=require(_0x217b('0x11'))(_0x217b('0x12'));var utils=require(_0x217b('0x13'));var config=require(_0x217b('0x14'));var licenseUtil=require(_0x217b('0x15'));var db=require(_0x217b('0x16'))['db'];config[_0x217b('0x17')]=_[_0x217b('0x18')](config[_0x217b('0x17')],{'host':_0x217b('0x19'),'port':0x18eb});var socket=require('socket.io-emitter')(new Redis(config[_0x217b('0x17')]));require('./plugin.socket')[_0x217b('0x1a')](socket);function respondWithStatusCode(_0x3eee70,_0x1cd71f){_0x1cd71f=_0x1cd71f||0xcc;return function(_0x4d82d8){if(_0x4d82d8){return _0x3eee70[_0x217b('0x1b')](_0x1cd71f);}return _0x3eee70[_0x217b('0x1c')](_0x1cd71f)[_0x217b('0x1d')]();};}function respondWithResult(_0x22cb2c,_0x5de611){_0x5de611=_0x5de611||0xc8;return function(_0x2296cc){if(_0x2296cc){return _0x22cb2c[_0x217b('0x1c')](_0x5de611)[_0x217b('0x1e')](_0x2296cc);}};}function respondWithFilteredResult(_0x56418a,_0x531469){return function(_0x270c93){if(_0x270c93){var _0x33928c=typeof _0x531469['offset']===_0x217b('0x1f')&&typeof _0x531469[_0x217b('0x20')]===_0x217b('0x1f');var _0x3aa6a0=_0x270c93['count'];var _0x31ec56=_0x33928c?0x0:_0x531469[_0x217b('0x21')];var _0x5d5632=_0x33928c?_0x270c93[_0x217b('0x22')]:_0x531469['offset']+_0x531469['limit'];var _0xbac649;if(_0x5d5632>=_0x3aa6a0){_0x5d5632=_0x3aa6a0;_0xbac649=0xc8;}else{_0xbac649=0xce;}_0x56418a[_0x217b('0x1c')](_0xbac649);return _0x56418a['set'](_0x217b('0x23'),_0x31ec56+'-'+_0x5d5632+'/'+_0x3aa6a0)[_0x217b('0x1e')](_0x270c93);}return null;};}function patchUpdates(_0x561964){return function(_0x408eed){try{jsonpatch[_0x217b('0x24')](_0x408eed,_0x561964,!![]);}catch(_0x657635){return BPromise['reject'](_0x657635);}return _0x408eed[_0x217b('0x25')]();};}function saveUpdates(_0x45a18b,_0x170fc0){return function(_0x53adde){if(_0x53adde){return _0x53adde[_0x217b('0x26')](_0x45a18b)[_0x217b('0x27')](function(_0x18a218){return _0x18a218;});}return null;};}function removeEntity(_0x3b6ed1,_0x21e37e){return function(_0x5c1ea9){if(_0x5c1ea9){return _0x5c1ea9['destroy']()[_0x217b('0x27')](function(){var _0x4cc562=_0x5c1ea9[_0x217b('0x28')]({'plain':!![]});var _0x1d76e1='Plugins';return db['UserProfileResource']['destroy']({'where':{'type':_0x1d76e1,'resourceId':_0x4cc562['id']}})['then'](function(){return _0x5c1ea9;});})[_0x217b('0x27')](function(){_0x3b6ed1[_0x217b('0x1c')](0xcc)[_0x217b('0x1d')]();});}};}function handleEntityNotFound(_0x574d79,_0x207b47){return function(_0x44801f){if(!_0x44801f){_0x574d79[_0x217b('0x1b')](0x194);}return _0x44801f;};}function handleError(_0x80639b,_0x558e16){_0x558e16=_0x558e16||0x1f4;return function(_0x4821ca){logger[_0x217b('0x29')](_0x4821ca[_0x217b('0x2a')]);if(_0x4821ca[_0x217b('0x2b')]){delete _0x4821ca['name'];}_0x80639b['status'](_0x558e16)['send'](_0x4821ca);};}exports[_0x217b('0x2c')]=function(_0x289770,_0x4532da){var _0x5c7723={},_0x21ef91={},_0x1602d0={'count':0x0,'rows':[]};var _0xe77380=_[_0x217b('0x2d')](db[_0x217b('0x2e')]['rawAttributes'],function(_0x3dd849){return{'name':_0x3dd849[_0x217b('0x2f')],'type':_0x3dd849[_0x217b('0x30')][_0x217b('0x31')]};});_0x21ef91[_0x217b('0x32')]=_[_0x217b('0x2d')](_0xe77380,_0x217b('0x2b'));_0x21ef91[_0x217b('0x33')]=_['keys'](_0x289770['query']);_0x21ef91[_0x217b('0x34')]=_[_0x217b('0x35')](_0x21ef91[_0x217b('0x32')],_0x21ef91[_0x217b('0x33')]);_0x5c7723[_0x217b('0x36')]=_[_0x217b('0x35')](_0x21ef91['model'],qs[_0x217b('0x37')](_0x289770[_0x217b('0x33')][_0x217b('0x37')]));_0x5c7723['attributes']=_0x5c7723[_0x217b('0x36')][_0x217b('0x38')]?_0x5c7723[_0x217b('0x36')]:_0x21ef91['model'];if(!_0x289770[_0x217b('0x33')][_0x217b('0x39')](_0x217b('0x3a'))){_0x5c7723[_0x217b('0x20')]=qs[_0x217b('0x20')](_0x289770[_0x217b('0x33')][_0x217b('0x20')]);_0x5c7723[_0x217b('0x21')]=qs[_0x217b('0x21')](_0x289770[_0x217b('0x33')][_0x217b('0x21')]);}_0x5c7723[_0x217b('0x3b')]=qs['sort'](_0x289770[_0x217b('0x33')]['sort']);_0x5c7723['where']=qs[_0x217b('0x34')](_[_0x217b('0x3c')](_0x289770[_0x217b('0x33')],_0x21ef91['filters']),_0xe77380);if(_0x289770[_0x217b('0x33')][_0x217b('0x3d')]){_0x5c7723['where']=_[_0x217b('0x3e')](_0x5c7723[_0x217b('0x3f')],{'$or':_[_0x217b('0x2d')](_0xe77380,function(_0x498d4a){if(_0x498d4a[_0x217b('0x30')]!=='VIRTUAL'){var _0x738262={};_0x738262[_0x498d4a[_0x217b('0x2b')]]={'$like':'%'+_0x289770[_0x217b('0x33')]['filter']+'%'};return _0x738262;}})});}_0x5c7723=_['merge']({},_0x5c7723,_0x289770[_0x217b('0x40')]);var _0x424692={'where':_0x5c7723['where']};return db[_0x217b('0x2e')][_0x217b('0x22')](_0x424692)['then'](function(_0x1c1968){_0x1602d0[_0x217b('0x22')]=_0x1c1968;if(_0x289770[_0x217b('0x33')][_0x217b('0x41')]){_0x5c7723[_0x217b('0x42')]=[{'all':!![]}];}return db[_0x217b('0x2e')]['findAll'](_0x5c7723);})[_0x217b('0x27')](function(_0x4d2813){_0x1602d0[_0x217b('0x43')]=_0x4d2813;return _0x1602d0;})[_0x217b('0x27')](respondWithFilteredResult(_0x4532da,_0x5c7723))[_0x217b('0x44')](handleError(_0x4532da,null));};exports['show']=function(_0x2b315c,_0x2ae36a){var _0x358240={'raw':!![],'where':{'id':_0x2b315c[_0x217b('0x45')]['id']}},_0x25fdaf={};_0x25fdaf[_0x217b('0x32')]=_[_0x217b('0x46')](db[_0x217b('0x2e')][_0x217b('0x47')]);_0x25fdaf['query']=_['keys'](_0x2b315c[_0x217b('0x33')]);_0x25fdaf[_0x217b('0x34')]=_[_0x217b('0x35')](_0x25fdaf[_0x217b('0x32')],_0x25fdaf['query']);_0x358240[_0x217b('0x36')]=_[_0x217b('0x35')](_0x25fdaf['model'],qs[_0x217b('0x37')](_0x2b315c['query']['fields']));_0x358240['attributes']=_0x358240[_0x217b('0x36')]['length']?_0x358240[_0x217b('0x36')]:_0x25fdaf[_0x217b('0x32')];if(_0x2b315c['query'][_0x217b('0x41')]){_0x358240[_0x217b('0x42')]=[{'all':!![]}];}_0x358240=_[_0x217b('0x3e')]({},_0x358240,_0x2b315c['options']);return db[_0x217b('0x2e')][_0x217b('0x48')](_0x358240)['then'](handleEntityNotFound(_0x2ae36a,null))[_0x217b('0x27')](respondWithResult(_0x2ae36a,null))['catch'](handleError(_0x2ae36a,null));};exports['download']=function(_0x1103ec,_0x286aba,_0x4386da){return db['Plugin']['find']({'where':{'id':_0x1103ec[_0x217b('0x45')]['id']},'attributes':[_0x217b('0x2b'),_0x217b('0x5')],'raw':!![]})[_0x217b('0x27')](handleEntityNotFound(_0x286aba,null))[_0x217b('0x27')](function(_0x48d2e4){if(_0x48d2e4){var _0x316e0e=path[_0x217b('0x49')](config[_0x217b('0x4a')],_0x217b('0x4b'),util[_0x217b('0x4c')](_0x217b('0x4d'),path[_0x217b('0x4e')](_0x48d2e4['path'])));var _0x56081b=fs[_0x217b('0x4f')](_0x316e0e);var _0x13c82e=archiver(_0x217b('0x50'),{'zlib':{'level':0x9}});_0x13c82e['on'](_0x217b('0x51'),function(_0x58614a){if(_0x58614a[_0x217b('0x52')]===_0x217b('0x53')){logger['error'](_0x58614a);}else{throw new db[(_0x217b('0x54'))][(_0x217b('0x55'))]('Error\x20while\x20generating\x20the\x20zip\x20archive');}});_0x13c82e['on'](_0x217b('0x29'),function(_0x3b4d03){throw new db[(_0x217b('0x54'))][(_0x217b('0x55'))](_0x217b('0x56'));});_0x13c82e['pipe'](_0x56081b);_0x13c82e['glob'](_0x217b('0x57'),{'cwd':path[_0x217b('0x49')](config[_0x217b('0x4a')],_0x217b('0x4b'),path['dirname'](_0x48d2e4[_0x217b('0x5')])),'ignore':[path[_0x217b('0x49')](path[_0x217b('0x4e')](_0x48d2e4['path']),_0x217b('0x58')),path[_0x217b('0x49')](path[_0x217b('0x4e')](_0x48d2e4[_0x217b('0x5')]),_0x217b('0x59'))],'nodir':!![]})[_0x217b('0x5a')]();_0x56081b['on']('close',function(){if(!fs[_0x217b('0x5b')](_0x316e0e)){throw new db[(_0x217b('0x54'))][(_0x217b('0x55'))](_0x217b('0x5c'));}return _0x286aba[_0x217b('0x5d')](_0x316e0e,util['format']('%s.zip',path[_0x217b('0x4e')](_0x48d2e4[_0x217b('0x5')])),function(_0x20a84b){if(_0x20a84b){throw new db[(_0x217b('0x54'))][(_0x217b('0x55'))](_0x217b('0x5e'));}fs[_0x217b('0x5f')](_0x316e0e);logger[_0x217b('0x60')](_0x217b('0x61'));logger['info']('Temporary\x20file\x20removed');});});}return null;})[_0x217b('0x44')](handleError(_0x286aba,null));};exports[_0x217b('0x62')]=function(_0x23806e,_0x5d2a7f,_0x5b0fad){var _0x2f82c3=path[_0x217b('0x4e')](_0x23806e['file'][_0x217b('0x63')],path[_0x217b('0x64')](_0x23806e[_0x217b('0x65')][_0x217b('0x63')]));var _0x31a618=path[_0x217b('0x49')](config[_0x217b('0x4a')],_0x217b('0x4b'),_0x23806e['file']['filename']);var _0x43bf0d=path[_0x217b('0x49')](config['root'],'server/files/plugins',_0x2f82c3);logger['info'](_0x217b('0x66'),_0x31a618);logger[_0x217b('0x60')]('Plugin\x20upload\x20destination:\x20%s',_0x43bf0d);try{fs['chmodSync'](_0x31a618,parseInt(_0x217b('0x67'),0x8));extract(_0x31a618,{'dir':_0x43bf0d},function(_0x245a79){if(_0x245a79){logger[_0x217b('0x29')](_0x245a79);handleError(_0x245a79,!![]);};var _0x78b443=fs[_0x217b('0x68')](_0x43bf0d);if(_0x78b443[_0x217b('0x38')]>0x1){removeReferences(_0x31a618,_0x43bf0d);logger['error']('Invalid\x20plugin\x20structure');return _0x5b0fad(new Error('Invalid\x20plugin\x20structure'));}var _0x1e990c=fs[_0x217b('0x69')](path[_0x217b('0x49')](_0x43bf0d,_0x78b443[0x0]));if(_0x1e990c[_0x217b('0x6a')]()){removeReferences(_0x31a618,_0x43bf0d);logger[_0x217b('0x29')]('Invalid\x20plugin\x20structure');return _0x5b0fad(new Error(_0x217b('0x6b')));}if(_0x1e990c[_0x217b('0x6c')]()){var _0x509d48=fs[_0x217b('0x68')](path[_0x217b('0x49')](_0x43bf0d,_0x78b443[0x0]));if(_0x509d48[_0x217b('0x38')]===0x0){removeReferences(_0x31a618,_0x43bf0d);logger[_0x217b('0x29')](_0x217b('0x6b'));return _0x5b0fad(new Error('Invalid\x20plugin\x20structure'));}var _0x822540=_0x509d48[_0x217b('0x6d')](function(_0x470225){return _0x470225===_0x217b('0x6e');});if(!_0x822540){return _0x5b0fad(new Error(_0x217b('0x6f')));}var _0x28c99a=fs[_0x217b('0x70')](path['join'](_0x43bf0d,_0x78b443[0x0],'manifest.json'));var _0xb978b2=JSON['parse'](_0x28c99a);if('undefined'==typeof _0xb978b2['name']){return _0x5b0fad(new Error('Invalid\x20manifest:\x20name\x20missing'));}if(_0x217b('0x1f')==typeof _0xb978b2[_0x217b('0x30')]){return _0x5b0fad(new Error(_0x217b('0x71')));}if(_0x217b('0x1f')==typeof _0xb978b2[_0x217b('0x72')]){return _0x5b0fad(new Error(_0x217b('0x73')));}if(_0x217b('0x1f')==typeof _0xb978b2[_0x217b('0x74')]){return _0x5b0fad(new Error(_0x217b('0x75')));}if(_0xb978b2[_0x217b('0x30')]===_0x217b('0x76')){if(_0x217b('0x1f')==typeof _0xb978b2[_0x217b('0x74')][_0x217b('0x77')]){return _0x5b0fad(new Error('Invalid\x20manifest:\x20views\x20missing'));}if(_0x217b('0x1f')==typeof _0xb978b2[_0x217b('0x74')][_0x217b('0x77')][_0x217b('0x78')]&&'undefined'==typeof _0xb978b2[_0x217b('0x74')]['views']['agent']){return _0x5b0fad(new Error('Invalid\x20manifest:\x20no\x20view\x20specified'));}}else if(_0xb978b2[_0x217b('0x30')]===_0x217b('0x79')){if(_0x217b('0x1f')==typeof _0xb978b2[_0x217b('0x74')]['scriptName']){return _0x5b0fad(new Error('Invalid\x20manifest:\x20script\x20name\x20missing'));}if(_0x217b('0x1f')==typeof _0xb978b2['parameters'][_0x217b('0x7a')]){return _0x5b0fad(new Error(_0x217b('0x7b')));}}else{return _0x5b0fad(new Error(_0x217b('0x7c')));}var _0x32e012=_0xb978b2['name'];var _0x544a2c=_0xb978b2[_0x217b('0x7d')];var _0x151b53=_0xb978b2[_0x217b('0x30')];var _0x1b8c28=_0xb978b2['sidebar']?_0xb978b2[_0x217b('0x7e')]:_0x217b('0x7f');var _0x53e840=_0xb978b2[_0x217b('0x80')]?_0xb978b2[_0x217b('0x80')]:'icon-apps';var _0x2d5bae='';var _0x41d999='';var _0x1f4e06='';var _0xe87349='';var _0x23d086=_0xb978b2['version'];if(_0x151b53===_0x217b('0x76')){if(_0x217b('0x1f')!=typeof _0xb978b2[_0x217b('0x74')][_0x217b('0x77')][_0x217b('0x78')]){var _0x5825ed=_0xb978b2[_0x217b('0x74')][_0x217b('0x77')][_0x217b('0x78')];if(!/^(f|ht)tps?:\/\//i['test'](_0x5825ed)){_0x2d5bae=path[_0x217b('0x49')]('plugins',_0x2f82c3,_0x78b443[0x0],_0x5825ed);}else{_0x2d5bae=_0x5825ed;}}else{logger[_0x217b('0x60')](_0x217b('0x81'));}if(_0x217b('0x1f')!=typeof _0xb978b2[_0x217b('0x74')][_0x217b('0x77')]['agent']){var _0x2dd350=_0xb978b2[_0x217b('0x74')][_0x217b('0x77')][_0x217b('0x82')];if(!/^(f|ht)tps?:\/\//i[_0x217b('0x83')](_0x2dd350)){_0x41d999=path['join'](_0x217b('0x84'),_0x2f82c3,_0x78b443[0x0],_0x2dd350);}else{_0x41d999=_0x2dd350;}}else{logger['info'](_0x217b('0x85'));}}else if(_0x151b53===_0x217b('0x79')){_0x1f4e06=_0xb978b2[_0x217b('0x74')][_0x217b('0x86')];_0xe87349=_0xb978b2['parameters'][_0x217b('0x7a')];if(_0x217b('0x1f')!=typeof _0xb978b2[_0x217b('0x74')][_0x217b('0x77')]){if(_0x217b('0x1f')!=typeof _0xb978b2['parameters'][_0x217b('0x77')][_0x217b('0x78')]){var _0x5825ed=_0xb978b2['parameters'][_0x217b('0x77')][_0x217b('0x78')];if(!/^(f|ht)tps?:\/\//i[_0x217b('0x83')](_0x5825ed)){_0x2d5bae=path[_0x217b('0x49')](_0x217b('0x84'),_0x2f82c3,_0x78b443[0x0],_0x5825ed);}else{_0x2d5bae=_0x5825ed;}}if(_0x217b('0x1f')!=typeof _0xb978b2[_0x217b('0x74')][_0x217b('0x77')][_0x217b('0x82')]){var _0x2dd350=_0xb978b2[_0x217b('0x74')][_0x217b('0x77')][_0x217b('0x82')];if(!/^(f|ht)tps?:\/\//i[_0x217b('0x83')](_0x2dd350)){_0x41d999=path[_0x217b('0x49')](_0x217b('0x84'),_0x2f82c3,_0x78b443[0x0],_0x2dd350);}else{_0x41d999=_0x2dd350;}}}}var _0x4beabc={'name':_0x32e012,'description':_0x544a2c,'path':path[_0x217b('0x49')](_0x2f82c3,_0x78b443[0x0]),'type':_0x151b53,'sidebar':_0x1b8c28,'icon':_0x53e840,'adminUrl':_0x2d5bae,'agentUrl':_0x41d999,'scriptName':_0x1f4e06,'scriptPath':_0xe87349,'version':_0x23d086};removeReferences(_0x31a618,null);return db[_0x217b('0x2e')][_0x217b('0x87')](_0x4beabc)[_0x217b('0x27')](function(_0x7f5f6d){var _0x454e02={'role':_0x23806e[_0x217b('0x88')][_0x217b('0x89')],'userProfileId':_0x23806e[_0x217b('0x88')][_0x217b('0x8a')]};if(!_0x454e02)throw new Error(_0x217b('0x8b'));if(_0x454e02[_0x217b('0x89')]===_0x217b('0x8c')){var _0xc6437d=_0x7f5f6d[_0x217b('0x28')]({'plain':!![]});return db[_0x217b('0x8d')]['find']({'where':{'name':_0x217b('0x8e'),'userProfileId':_0x454e02[_0x217b('0x8a')]},'raw':!![]})[_0x217b('0x27')](function(_0x435e6b){if(_0x435e6b&&_0x435e6b['autoAssociation']===0x0){return db['UserProfileResource']['create']({'name':_0xc6437d['name'],'resourceId':_0xc6437d['id'],'type':_0x435e6b[_0x217b('0x2b')],'sectionId':_0x435e6b['id']},{})[_0x217b('0x27')](function(){return _0x7f5f6d;});}else{return _0x7f5f6d;}})[_0x217b('0x44')](function(_0x17a608){logger[_0x217b('0x29')](_0x217b('0x8f'),_0x17a608);throw _0x17a608;});}return _0x7f5f6d;})[_0x217b('0x27')](respondWithResult(_0x5d2a7f,null))[_0x217b('0x44')](handleError(_0x5d2a7f,null));}});}catch(_0x4de3a8){_0x5d2a7f[_0x217b('0x1c')](0x1f4)[_0x217b('0x90')](_0x4de3a8);}};function removeReferences(_0x320f6f,_0x58acbd){try{if(_0x320f6f){fs[_0x217b('0x5f')](_0x320f6f);logger[_0x217b('0x60')](_0x217b('0x91'));}if(_0x58acbd){rimraf(_0x58acbd,function(){});logger[_0x217b('0x60')](_0x217b('0x92'));}}catch(_0x5aaf2a){logger[_0x217b('0x29')](_0x5aaf2a);}}exports[_0x217b('0x26')]=function(_0x1b4527,_0x5cb72f,_0x3753e4){return db[_0x217b('0x2e')][_0x217b('0x48')]({'where':{'id':_0x1b4527['params']['id']}})['then'](handleEntityNotFound(_0x5cb72f,null))[_0x217b('0x27')](saveUpdates(_0x1b4527[_0x217b('0x88')],null))[_0x217b('0x27')](respondWithResult(_0x5cb72f,null))[_0x217b('0x44')](handleError(_0x5cb72f,null));};exports[_0x217b('0x93')]=function(_0x550fa2,_0x506c5c,_0x1acd12){return db[_0x217b('0x2e')][_0x217b('0x48')]({'where':{'id':_0x550fa2['params']['id']}})[_0x217b('0x27')](function(_0x1d84c2){if(_0x1d84c2){return _0x1d84c2[_0x217b('0x94')]();}})['then'](function(_0x5dcf7a){rimraf(path['join'](config['root'],_0x217b('0x4b'),path['dirname'](_0x5dcf7a[_0x217b('0x5')])),function(){});return _0x5dcf7a;})['then'](handleEntityNotFound(_0x506c5c,null))[_0x217b('0x27')](respondWithStatusCode(_0x506c5c,null))['catch'](handleError(_0x506c5c,null));};exports[_0x217b('0x95')]=function(_0x2cd4af,_0x510f23,_0x554a81){return BPromise['resolve']()[_0x217b('0x27')](function(){if(!_0x2cd4af[_0x217b('0x33')][_0x217b('0x5')]){throw new Error('\x27PATH\x27\x20parameter\x20not\x20specified');}if(!_0x2cd4af[_0x217b('0x33')][_0x217b('0x96')]){throw new Error(_0x217b('0x97'));}var _0x50d1f7=_0x2cd4af['query'][_0x217b('0x98')]?_0x2cd4af[_0x217b('0x33')][_0x217b('0x98')]+':'+_0x2cd4af[_0x217b('0x33')][_0x217b('0x96')]:_0x217b('0x99')+_0x2cd4af[_0x217b('0x33')][_0x217b('0x96')];var _0x15ac32=_0x2cd4af[_0x217b('0x33')][_0x217b('0x1e')]?_0x2cd4af[_0x217b('0x33')][_0x217b('0x1e')]:!![];var _0x6b089e=_0x2cd4af[_0x217b('0x33')][_0x217b('0x9a')]?_0x2cd4af[_0x217b('0x33')][_0x217b('0x9a')]:null;var _0x319d12={'method':_0x2cd4af[_0x217b('0x9b')],'uri':util[_0x217b('0x4c')]('%s%s',_0x50d1f7,_0x2cd4af[_0x217b('0x33')]['path']),'json':_0x15ac32,'resolveWithFullResponse':!![],'encoding':_0x6b089e,'qs':_0x2cd4af[_0x217b('0x33')]};if(_0x2cd4af[_0x217b('0x9c')]){_0x319d12[_0x217b('0x9c')]=_0x2cd4af[_0x217b('0x9c')];if(_0x319d12['headers']['content-length']){delete _0x319d12[_0x217b('0x9c')][_0x217b('0x9d')];}}if(_0x319d12['headers'][_0x217b('0x9e')]){delete _0x319d12[_0x217b('0x9c')][_0x217b('0x9e')];}return rp(_0x319d12);})[_0x217b('0x27')](function(_0x17682c){if(_0x17682c){_0x510f23['set'](_0x17682c[_0x217b('0x9c')]);logger[_0x217b('0x60')](_0x17682c[_0x217b('0x88')]);if(_['endsWith'](_0x2cd4af[_0x217b('0x33')][_0x217b('0x5')],'download')&&_0x17682c[_0x217b('0x9f')]==0x1f4){return _0x510f23[_0x217b('0x1b')](_0x17682c['statusCode']);}else{return _0x510f23[_0x217b('0x1c')](_0x17682c[_0x217b('0x9f')])[_0x217b('0x90')](_0x17682c['body']);}}else{return _0x510f23['sendStatus'](0xc8);}})[_0x217b('0x44')](handleError(_0x510f23,null));};exports[_0x217b('0xa0')]=function(_0x307f84,_0x2cfc77,_0x44c090){return BPromise['resolve']()['then'](function(){if(!_0x307f84[_0x217b('0x33')][_0x217b('0x5')]){throw new Error(_0x217b('0xa1'));}if(!_0x307f84[_0x217b('0x33')][_0x217b('0x96')]){throw new Error(_0x217b('0x97'));}var _0x32e2e6=_0x307f84[_0x217b('0x33')][_0x217b('0x98')]?_0x307f84['query'][_0x217b('0x98')]+':'+_0x307f84[_0x217b('0x33')][_0x217b('0x96')]:'http://localhost:'+_0x307f84[_0x217b('0x33')][_0x217b('0x96')];var _0x50d993=_0x307f84[_0x217b('0x33')][_0x217b('0x1e')]?_0x307f84[_0x217b('0x33')][_0x217b('0x1e')]:!![];var _0x532b98=_0x307f84[_0x217b('0x33')][_0x217b('0x9a')]?_0x307f84[_0x217b('0x33')][_0x217b('0x9a')]:null;var _0x19a447={'method':_0x307f84['method'],'uri':util[_0x217b('0x4c')](_0x217b('0xa2'),_0x32e2e6,_0x307f84[_0x217b('0x33')][_0x217b('0x5')]),'json':_0x50d993,'resolveWithFullResponse':!![],'encoding':_0x532b98,'body':_0x307f84[_0x217b('0x88')]};if(_0x307f84[_0x217b('0x9c')]){_0x19a447[_0x217b('0x9c')]=_0x307f84[_0x217b('0x9c')];if(_0x19a447[_0x217b('0x9c')][_0x217b('0x9d')]){delete _0x19a447[_0x217b('0x9c')]['content-length'];}}if(_0x19a447[_0x217b('0x9c')][_0x217b('0x9e')]){delete _0x19a447[_0x217b('0x9c')][_0x217b('0x9e')];}return rp(_0x19a447);})[_0x217b('0x27')](function(_0x4fb585){if(_0x4fb585){_0x2cfc77['set'](_0x4fb585['headers']);logger[_0x217b('0x60')](_0x4fb585[_0x217b('0x88')]);return _0x2cfc77[_0x217b('0x1c')](_0x4fb585[_0x217b('0x9f')])['send'](_0x4fb585[_0x217b('0x88')]);}else{return _0x2cfc77['sendStatus'](0xc8);}})[_0x217b('0x44')](handleError(_0x2cfc77,null));};