Built motion from commit ff78e754.|2.6.29
[motion2.git] / server / api / voiceMusicOnHold / voiceMusicOnHold.controller.js
index 893afbb..bb265fe 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0x86f9=['options','includeAll','include','findAll','rows','catch','show','params','find','body','create','sequelize','directory','join','root','server/files/moh','mode','files','mkdirSync','0777','user','Unable\x20to\x20retrieve\x20the\x20current\x20user','UserProfileSection','userProfileId','autoAssociation','error','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','readdirSync','forEach','unlinkSync','Sequelize','ValidationError','message','addSound','transaction','save_name','converted_format','createdAt','format','basename','extname','%s.%s','symlinkSync','removeSound','findOne','id2','Sound','getSounds','eml-format','zip-dir','request-promise','moment','bluebird','mustache','util','path','sox','to-csv','ejs','fs-extra','squel','crypto','../../components/auth/service','../../components/parsers/qs','../../config/license/hardware','../../config/logger','../../config/environment','../../config/license/util','sendStatus','end','status','json','undefined','limit','offset','count','set','apply','reject','save','update','destroy','get','MusicOnHolds','UserProfileResource','then','stack','name','send','index','VoiceMusicOnHold','rawAttributes','type','key','model','map','query','keys','filters','intersection','attributes','fields','length','hasOwnProperty','nolimit','sort','pick','filter','where','merge','VIRTUAL'];(function(_0x14715a,_0x3e1fb1){var _0x14055d=function(_0x4a968f){while(--_0x4a968f){_0x14715a['push'](_0x14715a['shift']());}};_0x14055d(++_0x3e1fb1);}(_0x86f9,0x10e));var _0x986f=function(_0x5d1044,_0x18f656){_0x5d1044=_0x5d1044-0x0;var _0x3cd90e=_0x86f9[_0x5d1044];return _0x3cd90e;};'use strict';var emlformat=require(_0x986f('0x0'));var rimraf=require('rimraf');var zipdir=require(_0x986f('0x1'));var jsonpatch=require('fast-json-patch');var rp=require(_0x986f('0x2'));var moment=require(_0x986f('0x3'));var BPromise=require(_0x986f('0x4'));var Mustache=require(_0x986f('0x5'));var util=require(_0x986f('0x6'));var path=require(_0x986f('0x7'));var sox=require(_0x986f('0x8'));var csv=require(_0x986f('0x9'));var ejs=require(_0x986f('0xa'));var fs=require('fs');var fs_extra=require(_0x986f('0xb'));var _=require('lodash');var squel=require(_0x986f('0xc'));var crypto=require(_0x986f('0xd'));var jsforce=require('jsforce');var deskjs=require('desk.js');var toCsv=require(_0x986f('0x9'));var querystring=require('querystring');var Papa=require('papaparse');var Redis=require('ioredis');var authService=require(_0x986f('0xe'));var qs=require(_0x986f('0xf'));var as=require('../../components/parsers/advancedSearch');var hardwareService=require(_0x986f('0x10'));var logger=require(_0x986f('0x11'))('api');var utils=require('../../config/utils');var config=require(_0x986f('0x12'));var licenseUtil=require(_0x986f('0x13'));var db=require('../../mysqldb')['db'];function respondWithStatusCode(_0x3b5d5e,_0x1aa57f){_0x1aa57f=_0x1aa57f||0xcc;return function(_0x209cee){if(_0x209cee){return _0x3b5d5e[_0x986f('0x14')](_0x1aa57f);}return _0x3b5d5e['status'](_0x1aa57f)[_0x986f('0x15')]();};}function respondWithResult(_0x514ec2,_0x37abb0){_0x37abb0=_0x37abb0||0xc8;return function(_0x20c044){if(_0x20c044){return _0x514ec2[_0x986f('0x16')](_0x37abb0)[_0x986f('0x17')](_0x20c044);}};}function respondWithFilteredResult(_0x360516,_0x2052e0){return function(_0x4d9f9f){if(_0x4d9f9f){var _0x3e6513=typeof _0x2052e0['offset']===_0x986f('0x18')&&typeof _0x2052e0[_0x986f('0x19')]===_0x986f('0x18');var _0x3e082e=_0x4d9f9f['count'];var _0x207508=_0x3e6513?0x0:_0x2052e0[_0x986f('0x1a')];var _0x5beee0=_0x3e6513?_0x4d9f9f[_0x986f('0x1b')]:_0x2052e0['offset']+_0x2052e0[_0x986f('0x19')];var _0x56ad37;if(_0x5beee0>=_0x3e082e){_0x5beee0=_0x3e082e;_0x56ad37=0xc8;}else{_0x56ad37=0xce;}_0x360516[_0x986f('0x16')](_0x56ad37);return _0x360516[_0x986f('0x1c')]('Content-Range',_0x207508+'-'+_0x5beee0+'/'+_0x3e082e)['json'](_0x4d9f9f);}return null;};}function patchUpdates(_0x133fd8){return function(_0x5b58ad){try{jsonpatch[_0x986f('0x1d')](_0x5b58ad,_0x133fd8,!![]);}catch(_0x3e9579){return BPromise[_0x986f('0x1e')](_0x3e9579);}return _0x5b58ad[_0x986f('0x1f')]();};}function saveUpdates(_0x31b740,_0xa8c4ea){return function(_0x4eaabe){if(_0x4eaabe){return _0x4eaabe[_0x986f('0x20')](_0x31b740)['then'](function(_0x35b2d7){return _0x35b2d7;});}return null;};}function removeEntity(_0xf91331,_0xae3111){return function(_0x1ed72d){if(_0x1ed72d){return _0x1ed72d[_0x986f('0x21')]()['then'](function(){var _0x35ba80=_0x1ed72d[_0x986f('0x22')]({'plain':!![]});var _0x14fe1c=_0x986f('0x23');return db[_0x986f('0x24')][_0x986f('0x21')]({'where':{'type':_0x14fe1c,'resourceId':_0x35ba80['id']}})[_0x986f('0x25')](function(){return _0x1ed72d;});})[_0x986f('0x25')](function(){_0xf91331[_0x986f('0x16')](0xcc)[_0x986f('0x15')]();});}};}function handleEntityNotFound(_0x1b62bd,_0x4d142f){return function(_0x303239){if(!_0x303239){_0x1b62bd[_0x986f('0x14')](0x194);}return _0x303239;};}function handleError(_0x5410af,_0x365a10){_0x365a10=_0x365a10||0x1f4;return function(_0x32d5d1){logger['error'](_0x32d5d1[_0x986f('0x26')]);if(_0x32d5d1[_0x986f('0x27')]){delete _0x32d5d1[_0x986f('0x27')];}_0x5410af[_0x986f('0x16')](_0x365a10)[_0x986f('0x28')](_0x32d5d1);};}exports[_0x986f('0x29')]=function(_0x2f05cf,_0x58799d){var _0x12061e={},_0x50883c={},_0x3a6325={'count':0x0,'rows':[]};var _0x4e9540=_['map'](db[_0x986f('0x2a')][_0x986f('0x2b')],function(_0x49d645){return{'name':_0x49d645['fieldName'],'type':_0x49d645[_0x986f('0x2c')][_0x986f('0x2d')]};});_0x50883c[_0x986f('0x2e')]=_[_0x986f('0x2f')](_0x4e9540,_0x986f('0x27'));_0x50883c[_0x986f('0x30')]=_[_0x986f('0x31')](_0x2f05cf[_0x986f('0x30')]);_0x50883c[_0x986f('0x32')]=_[_0x986f('0x33')](_0x50883c[_0x986f('0x2e')],_0x50883c[_0x986f('0x30')]);_0x12061e[_0x986f('0x34')]=_[_0x986f('0x33')](_0x50883c[_0x986f('0x2e')],qs['fields'](_0x2f05cf['query'][_0x986f('0x35')]));_0x12061e[_0x986f('0x34')]=_0x12061e['attributes'][_0x986f('0x36')]?_0x12061e[_0x986f('0x34')]:_0x50883c[_0x986f('0x2e')];if(!_0x2f05cf[_0x986f('0x30')][_0x986f('0x37')](_0x986f('0x38'))){_0x12061e[_0x986f('0x19')]=qs['limit'](_0x2f05cf[_0x986f('0x30')]['limit']);_0x12061e[_0x986f('0x1a')]=qs[_0x986f('0x1a')](_0x2f05cf[_0x986f('0x30')][_0x986f('0x1a')]);}_0x12061e['order']=qs[_0x986f('0x39')](_0x2f05cf[_0x986f('0x30')][_0x986f('0x39')]);delete _0x2f05cf[_0x986f('0x30')][_0x986f('0x39')];_0x12061e['where']=qs[_0x986f('0x32')](_[_0x986f('0x3a')](_0x2f05cf['query'],_0x50883c[_0x986f('0x32')]),_0x4e9540);if(_0x2f05cf[_0x986f('0x30')][_0x986f('0x3b')]){_0x12061e[_0x986f('0x3c')]=_[_0x986f('0x3d')](_0x12061e[_0x986f('0x3c')],{'$or':_[_0x986f('0x2f')](_0x4e9540,function(_0x2589fb){if(_0x2589fb['type']!==_0x986f('0x3e')){var _0x7c2060={};_0x7c2060[_0x2589fb[_0x986f('0x27')]]={'$like':'%'+_0x2f05cf[_0x986f('0x30')][_0x986f('0x3b')]+'%'};return _0x7c2060;}})});}_0x12061e=_[_0x986f('0x3d')]({},_0x12061e,_0x2f05cf[_0x986f('0x3f')]);var _0x5db9d0={'where':_0x12061e[_0x986f('0x3c')]};return db[_0x986f('0x2a')][_0x986f('0x1b')](_0x5db9d0)[_0x986f('0x25')](function(_0x53ed55){_0x3a6325[_0x986f('0x1b')]=_0x53ed55;if(_0x2f05cf[_0x986f('0x30')][_0x986f('0x40')]){_0x12061e[_0x986f('0x41')]=[{'all':!![]}];}return db[_0x986f('0x2a')][_0x986f('0x42')](_0x12061e);})[_0x986f('0x25')](function(_0x5076db){_0x3a6325[_0x986f('0x43')]=_0x5076db;return _0x3a6325;})[_0x986f('0x25')](respondWithFilteredResult(_0x58799d,_0x12061e))[_0x986f('0x44')](handleError(_0x58799d,null));};exports[_0x986f('0x45')]=function(_0x37f056,_0x4031e5){var _0x39883b={'raw':![],'where':{'id':_0x37f056[_0x986f('0x46')]['id']}},_0x2df899={};_0x2df899[_0x986f('0x2e')]=_[_0x986f('0x31')](db[_0x986f('0x2a')][_0x986f('0x2b')]);_0x2df899['query']=_[_0x986f('0x31')](_0x37f056[_0x986f('0x30')]);_0x2df899[_0x986f('0x32')]=_[_0x986f('0x33')](_0x2df899[_0x986f('0x2e')],_0x2df899[_0x986f('0x30')]);_0x39883b[_0x986f('0x34')]=_[_0x986f('0x33')](_0x2df899[_0x986f('0x2e')],qs['fields'](_0x37f056[_0x986f('0x30')][_0x986f('0x35')]));_0x39883b[_0x986f('0x34')]=_0x39883b[_0x986f('0x34')][_0x986f('0x36')]?_0x39883b[_0x986f('0x34')]:_0x2df899[_0x986f('0x2e')];if(_0x37f056[_0x986f('0x30')][_0x986f('0x40')]){_0x39883b['include']=[{'all':!![]}];}_0x39883b=_['merge']({},_0x39883b,_0x37f056['options']);return db[_0x986f('0x2a')][_0x986f('0x47')](_0x39883b)[_0x986f('0x25')](handleEntityNotFound(_0x4031e5,null))[_0x986f('0x25')](respondWithResult(_0x4031e5,null))[_0x986f('0x44')](handleError(_0x4031e5,null));};exports[_0x986f('0x20')]=function(_0x1eb0c5,_0x35b0e9){if(_0x1eb0c5['body']['id']){delete _0x1eb0c5[_0x986f('0x48')]['id'];}return db[_0x986f('0x2a')]['find']({'where':{'id':_0x1eb0c5[_0x986f('0x46')]['id']}})[_0x986f('0x25')](handleEntityNotFound(_0x35b0e9,null))['then'](saveUpdates(_0x1eb0c5[_0x986f('0x48')],null))[_0x986f('0x25')](respondWithResult(_0x35b0e9,null))[_0x986f('0x44')](handleError(_0x35b0e9,null));};exports[_0x986f('0x49')]=function(_0x4c1521,_0x4060c1,_0x16d48b){return db[_0x986f('0x4a')]['transaction'](function(_0x1a7b31){if(_0x4c1521[_0x986f('0x48')]['mode']==='files'){_0x4c1521[_0x986f('0x48')][_0x986f('0x4b')]=path[_0x986f('0x4c')](config[_0x986f('0x4d')],_0x986f('0x4e'),_0x4c1521[_0x986f('0x48')][_0x986f('0x27')]);}return db[_0x986f('0x2a')]['create'](_0x4c1521['body'],{'transaction':_0x1a7b31})[_0x986f('0x25')](function(_0x571519){if(_0x4c1521[_0x986f('0x48')][_0x986f('0x4f')]===_0x986f('0x50')){fs[_0x986f('0x51')](_0x571519[_0x986f('0x4b')],parseInt(_0x986f('0x52'),0x8));}var _0x1c017f=_0x4c1521[_0x986f('0x53')]['get']({'plain':!![]});if(!_0x1c017f)throw new Error(_0x986f('0x54'));if(_0x1c017f['role']===_0x986f('0x53')){var _0x819805=_0x571519['get']({'plain':!![]});return db[_0x986f('0x55')][_0x986f('0x47')]({'where':{'name':_0x986f('0x23'),'userProfileId':_0x1c017f[_0x986f('0x56')]},'raw':!![]})[_0x986f('0x25')](function(_0x165b18){if(_0x165b18&&_0x165b18[_0x986f('0x57')]===0x0){return db[_0x986f('0x24')][_0x986f('0x49')]({'name':_0x819805[_0x986f('0x27')],'resourceId':_0x819805['id'],'type':_0x165b18[_0x986f('0x27')],'sectionId':_0x165b18['id']},{})[_0x986f('0x25')](function(){return _0x571519;});}else{return _0x571519;}})[_0x986f('0x44')](function(_0x266fa2){logger[_0x986f('0x58')](_0x986f('0x59'),_0x266fa2);});}return _0x571519;});})[_0x986f('0x25')](respondWithResult(_0x4060c1,0xc9))['catch'](handleError(_0x4060c1,null));};exports[_0x986f('0x21')]=function(_0x5c95c1,_0xa46e3,_0x3e68ba){var _0x23ec45;return db[_0x986f('0x2a')]['find']({'where':{'id':_0x5c95c1[_0x986f('0x46')]['id']}})[_0x986f('0x25')](function(_0xd44368){if(_0xd44368){return db['sequelize']['transaction'](function(_0x555c6a){return _0xd44368[_0x986f('0x21')]({'transaction':_0x555c6a,'raw':!![]})[_0x986f('0x25')](function(_0x10e74e){if(_0x10e74e[_0x986f('0x4b')]){fs[_0x986f('0x5a')](_0x10e74e['directory'])[_0x986f('0x5b')](function(_0x3ecf85){fs[_0x986f('0x5c')](path['join'](_0x10e74e[_0x986f('0x4b')],_0x3ecf85));});fs['rmdirSync'](_0x10e74e[_0x986f('0x4b')]);}return _0x10e74e;});})[_0x986f('0x44')](function(_0x3276e3){throw new db[(_0x986f('0x5d'))][(_0x986f('0x5e'))](_0x3276e3[_0x986f('0x5f')]);});}})['then'](handleEntityNotFound(_0xa46e3,null))[_0x986f('0x25')](removeEntity(_0xa46e3,null))[_0x986f('0x44')](handleError(_0xa46e3,null));};exports[_0x986f('0x60')]=function(_0x280fac,_0x5080a4,_0x14ef43){return db['sequelize'][_0x986f('0x61')](function(_0x1ba36a){var _0xb76efb;return db['VoiceMusicOnHold'][_0x986f('0x47')]({'where':{'id':_0x280fac[_0x986f('0x46')]['id']}})[_0x986f('0x25')](function(_0x3894f5){if(_0x3894f5){_0xb76efb=_0x3894f5;return _0x3894f5[_0x986f('0x60')](_0x280fac[_0x986f('0x48')]['id'],{'transaction':_0x1ba36a});}})['then'](function(_0x1fd5b7){if(_0x1fd5b7){return db['Sound']['findOne']({'where':{'id':_0x280fac[_0x986f('0x48')]['id']},'attributes':['id',_0x986f('0x27'),_0x986f('0x62'),_0x986f('0x63'),_0x986f('0x64')],'raw':!![]});}})['then'](function(_0x20a248){if(_0x20a248){var _0x5c8e27=path['join'](config[_0x986f('0x4d')],'server/files/sounds/converted',util[_0x986f('0x65')]('%s.%s',path[_0x986f('0x66')](_0x20a248['save_name'],path[_0x986f('0x67')](_0x20a248[_0x986f('0x62')])),_0x20a248['converted_format']));var _0x4db7d3=path['join'](config[_0x986f('0x4d')],_0x986f('0x4e'),_0xb76efb['name'],util['format'](_0x986f('0x68'),_0x20a248[_0x986f('0x27')],_0x20a248[_0x986f('0x63')]));fs[_0x986f('0x69')](_0x5c8e27,_0x4db7d3);return _0x20a248;}})[_0x986f('0x44')](function(_0x5adefc){throw new db[(_0x986f('0x5d'))][(_0x986f('0x5e'))](_0x5adefc[_0x986f('0x5f')]);});})[_0x986f('0x25')](handleEntityNotFound(_0x5080a4,null))['then'](respondWithResult(_0x5080a4,0xc9))[_0x986f('0x44')](handleError(_0x5080a4,null));};exports[_0x986f('0x6a')]=function(_0x4364bd,_0x188838,_0x55f477){return db[_0x986f('0x4a')][_0x986f('0x61')](function(_0x36816c){var _0x4b79f5;return db['VoiceMusicOnHold'][_0x986f('0x6b')]({'where':{'id':_0x4364bd[_0x986f('0x46')]['id']}})['then'](handleEntityNotFound(_0x188838,null))[_0x986f('0x25')](function(_0x4c51bf){if(_0x4c51bf){_0x4b79f5=_0x4c51bf;return _0x4c51bf['removeSound'](_0x4364bd[_0x986f('0x46')][_0x986f('0x6c')]);}})[_0x986f('0x25')](function(_0x2ae87e){if(_0x2ae87e){return db[_0x986f('0x6d')][_0x986f('0x6b')]({'where':{'id':_0x4364bd[_0x986f('0x46')][_0x986f('0x6c')]},'attributes':['id',_0x986f('0x27'),_0x986f('0x62'),_0x986f('0x63'),'createdAt'],'raw':!![]});}})[_0x986f('0x25')](function(_0x6557af){if(_0x6557af){fs['unlinkSync'](path[_0x986f('0x4c')](_0x4b79f5[_0x986f('0x4b')],util['format'](_0x986f('0x68'),_0x6557af[_0x986f('0x27')],_0x6557af[_0x986f('0x63')])));return _0x6557af;}})[_0x986f('0x44')](function(_0x519d54){throw new db['Sequelize'][(_0x986f('0x5e'))](_0x519d54[_0x986f('0x5f')]);});})[_0x986f('0x25')](handleEntityNotFound(_0x188838,null))[_0x986f('0x25')](respondWithStatusCode(_0x188838,0xcc))['catch'](handleError(_0x188838,null));};exports[_0x986f('0x6e')]=function(_0x30f847,_0x409e67,_0x1da512){var _0x2ce109={};var _0x31140c={};var _0x491cc2;var _0x464e1c;return db[_0x986f('0x2a')]['findOne']({'where':{'id':_0x30f847[_0x986f('0x46')]['id']}})['then'](handleEntityNotFound(_0x409e67,null))['then'](function(_0x32726a){if(_0x32726a){_0x491cc2=_0x32726a;_0x31140c[_0x986f('0x2e')]=_[_0x986f('0x31')](db['Sound'][_0x986f('0x2b')]);_0x31140c[_0x986f('0x30')]=_[_0x986f('0x31')](_0x30f847[_0x986f('0x30')]);_0x31140c[_0x986f('0x32')]=_['intersection'](_0x31140c['model'],_0x31140c['query']);_0x2ce109[_0x986f('0x34')]=_['intersection'](_0x31140c['model'],qs[_0x986f('0x35')](_0x30f847['query'][_0x986f('0x35')]));_0x2ce109[_0x986f('0x34')]=_0x2ce109[_0x986f('0x34')][_0x986f('0x36')]?_0x2ce109[_0x986f('0x34')]:_0x31140c[_0x986f('0x2e')];_0x2ce109['order']=qs[_0x986f('0x39')](_0x30f847['query'][_0x986f('0x39')]);_0x2ce109[_0x986f('0x3c')]=qs[_0x986f('0x32')](_[_0x986f('0x3a')](_0x30f847[_0x986f('0x30')],_0x31140c['filters']));if(_0x30f847[_0x986f('0x30')][_0x986f('0x3b')]){_0x2ce109[_0x986f('0x3c')]=_[_0x986f('0x3d')](_0x2ce109[_0x986f('0x3c')],{'$or':_[_0x986f('0x2f')](_0x2ce109[_0x986f('0x34')],function(_0x4805d5){var _0x32fbe1={};_0x32fbe1[_0x4805d5]={'$like':'%'+_0x30f847[_0x986f('0x30')]['filter']+'%'};return _0x32fbe1;})});}_0x2ce109=_[_0x986f('0x3d')]({},_0x2ce109,_0x30f847[_0x986f('0x3f')]);return _0x491cc2['getSounds'](_0x2ce109);}})['then'](function(_0x21cc1a){if(_0x21cc1a){_0x464e1c=_0x21cc1a['length'];if(!_0x30f847[_0x986f('0x30')][_0x986f('0x37')]('nolimit')){_0x2ce109[_0x986f('0x19')]=qs[_0x986f('0x19')](_0x30f847[_0x986f('0x30')][_0x986f('0x19')]);_0x2ce109[_0x986f('0x1a')]=qs[_0x986f('0x1a')](_0x30f847[_0x986f('0x30')][_0x986f('0x1a')]);}return _0x491cc2['getSounds'](_0x2ce109);}})[_0x986f('0x25')](function(_0x496019){if(_0x496019){return _0x496019?{'count':_0x464e1c,'rows':_0x496019}:null;}})[_0x986f('0x25')](respondWithResult(_0x409e67,null))['catch'](handleError(_0x409e67,null));};
\ No newline at end of file
+var _0xc78c=['extname','converted_format','symlinkSync','Sequelize','removeSound','findOne','id2','Sound','message','getSounds','hasOwnProperty','eml-format','fast-json-patch','request-promise','moment','bluebird','mustache','util','sox','fs-extra','lodash','squel','crypto','jsforce','to-csv','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/environment','../../config/license/util','../../mysqldb','status','end','json','undefined','limit','count','offset','Content-Range','reject','save','update','then','destroy','get','MusicOnHolds','error','stack','name','send','index','map','VoiceMusicOnHold','rawAttributes','fieldName','type','model','query','keys','intersection','attributes','fields','length','nolimit','order','sort','filters','filter','merge','where','VIRTUAL','options','findAll','rows','catch','show','params','includeAll','include','find','body','create','mode','files','directory','join','server/files/moh','0777','user','Unable\x20to\x20retrieve\x20the\x20current\x20user','role','UserProfileSection','UserProfileResource','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','sequelize','transaction','readdirSync','unlinkSync','rmdirSync','ValidationError','addSound','createdAt','root','server/files/sounds/converted','format','%s.%s','basename','save_name'];(function(_0x12278e,_0x3aa534){var _0x49ab91=function(_0x3a2cc9){while(--_0x3a2cc9){_0x12278e['push'](_0x12278e['shift']());}};_0x49ab91(++_0x3aa534);}(_0xc78c,0xef));var _0xcc78=function(_0x2dafbe,_0x5d04de){_0x2dafbe=_0x2dafbe-0x0;var _0x58a45a=_0xc78c[_0x2dafbe];return _0x58a45a;};'use strict';var emlformat=require(_0xcc78('0x0'));var rimraf=require('rimraf');var zipdir=require('zip-dir');var jsonpatch=require(_0xcc78('0x1'));var rp=require(_0xcc78('0x2'));var moment=require(_0xcc78('0x3'));var BPromise=require(_0xcc78('0x4'));var Mustache=require(_0xcc78('0x5'));var util=require(_0xcc78('0x6'));var path=require('path');var sox=require(_0xcc78('0x7'));var csv=require('to-csv');var ejs=require('ejs');var fs=require('fs');var fs_extra=require(_0xcc78('0x8'));var _=require(_0xcc78('0x9'));var squel=require(_0xcc78('0xa'));var crypto=require(_0xcc78('0xb'));var jsforce=require(_0xcc78('0xc'));var deskjs=require('desk.js');var toCsv=require(_0xcc78('0xd'));var querystring=require(_0xcc78('0xe'));var Papa=require(_0xcc78('0xf'));var Redis=require(_0xcc78('0x10'));var authService=require(_0xcc78('0x11'));var qs=require(_0xcc78('0x12'));var as=require(_0xcc78('0x13'));var hardwareService=require(_0xcc78('0x14'));var logger=require(_0xcc78('0x15'))(_0xcc78('0x16'));var utils=require('../../config/utils');var config=require(_0xcc78('0x17'));var licenseUtil=require(_0xcc78('0x18'));var db=require(_0xcc78('0x19'))['db'];function respondWithStatusCode(_0x5291cf,_0x4f946d){_0x4f946d=_0x4f946d||0xcc;return function(_0x1a723a){if(_0x1a723a){return _0x5291cf['sendStatus'](_0x4f946d);}return _0x5291cf[_0xcc78('0x1a')](_0x4f946d)[_0xcc78('0x1b')]();};}function respondWithResult(_0x52d8b3,_0x687a3c){_0x687a3c=_0x687a3c||0xc8;return function(_0x10d6ae){if(_0x10d6ae){return _0x52d8b3[_0xcc78('0x1a')](_0x687a3c)[_0xcc78('0x1c')](_0x10d6ae);}};}function respondWithFilteredResult(_0x142974,_0x414a25){return function(_0x115f4c){if(_0x115f4c){var _0x1adcf6=typeof _0x414a25['offset']===_0xcc78('0x1d')&&typeof _0x414a25[_0xcc78('0x1e')]===_0xcc78('0x1d');var _0x330b50=_0x115f4c[_0xcc78('0x1f')];var _0x1280cc=_0x1adcf6?0x0:_0x414a25[_0xcc78('0x20')];var _0x424dee=_0x1adcf6?_0x115f4c[_0xcc78('0x1f')]:_0x414a25['offset']+_0x414a25[_0xcc78('0x1e')];var _0x2e2c1b;if(_0x424dee>=_0x330b50){_0x424dee=_0x330b50;_0x2e2c1b=0xc8;}else{_0x2e2c1b=0xce;}_0x142974[_0xcc78('0x1a')](_0x2e2c1b);return _0x142974['set'](_0xcc78('0x21'),_0x1280cc+'-'+_0x424dee+'/'+_0x330b50)[_0xcc78('0x1c')](_0x115f4c);}return null;};}function patchUpdates(_0x5e75d9){return function(_0x31d2c2){try{jsonpatch['apply'](_0x31d2c2,_0x5e75d9,!![]);}catch(_0xed1394){return BPromise[_0xcc78('0x22')](_0xed1394);}return _0x31d2c2[_0xcc78('0x23')]();};}function saveUpdates(_0x16f734,_0xe22a0b){return function(_0xa87b17){if(_0xa87b17){return _0xa87b17[_0xcc78('0x24')](_0x16f734)[_0xcc78('0x25')](function(_0x4ba938){return _0x4ba938;});}return null;};}function removeEntity(_0x1b0840,_0x20821a){return function(_0x3f320c){if(_0x3f320c){return _0x3f320c[_0xcc78('0x26')]()['then'](function(){var _0x3e45c8=_0x3f320c[_0xcc78('0x27')]({'plain':!![]});var _0x91ffb4=_0xcc78('0x28');return db['UserProfileResource']['destroy']({'where':{'type':_0x91ffb4,'resourceId':_0x3e45c8['id']}})[_0xcc78('0x25')](function(){return _0x3f320c;});})['then'](function(){_0x1b0840[_0xcc78('0x1a')](0xcc)[_0xcc78('0x1b')]();});}};}function handleEntityNotFound(_0x38897b,_0xb5855a){return function(_0x3864e4){if(!_0x3864e4){_0x38897b['sendStatus'](0x194);}return _0x3864e4;};}function handleError(_0x3590c3,_0x4adacd){_0x4adacd=_0x4adacd||0x1f4;return function(_0x23a105){logger[_0xcc78('0x29')](_0x23a105[_0xcc78('0x2a')]);if(_0x23a105[_0xcc78('0x2b')]){delete _0x23a105[_0xcc78('0x2b')];}_0x3590c3[_0xcc78('0x1a')](_0x4adacd)[_0xcc78('0x2c')](_0x23a105);};}exports[_0xcc78('0x2d')]=function(_0x236bfc,_0x2e88ec){var _0x1c188c={},_0x228062={},_0x367461={'count':0x0,'rows':[]};var _0x1c6575=_[_0xcc78('0x2e')](db[_0xcc78('0x2f')][_0xcc78('0x30')],function(_0x26b91f){return{'name':_0x26b91f[_0xcc78('0x31')],'type':_0x26b91f[_0xcc78('0x32')]['key']};});_0x228062[_0xcc78('0x33')]=_[_0xcc78('0x2e')](_0x1c6575,_0xcc78('0x2b'));_0x228062[_0xcc78('0x34')]=_[_0xcc78('0x35')](_0x236bfc[_0xcc78('0x34')]);_0x228062['filters']=_[_0xcc78('0x36')](_0x228062[_0xcc78('0x33')],_0x228062[_0xcc78('0x34')]);_0x1c188c[_0xcc78('0x37')]=_[_0xcc78('0x36')](_0x228062[_0xcc78('0x33')],qs[_0xcc78('0x38')](_0x236bfc[_0xcc78('0x34')]['fields']));_0x1c188c[_0xcc78('0x37')]=_0x1c188c['attributes'][_0xcc78('0x39')]?_0x1c188c[_0xcc78('0x37')]:_0x228062[_0xcc78('0x33')];if(!_0x236bfc[_0xcc78('0x34')]['hasOwnProperty'](_0xcc78('0x3a'))){_0x1c188c['limit']=qs[_0xcc78('0x1e')](_0x236bfc[_0xcc78('0x34')][_0xcc78('0x1e')]);_0x1c188c[_0xcc78('0x20')]=qs[_0xcc78('0x20')](_0x236bfc[_0xcc78('0x34')][_0xcc78('0x20')]);}_0x1c188c[_0xcc78('0x3b')]=qs[_0xcc78('0x3c')](_0x236bfc[_0xcc78('0x34')][_0xcc78('0x3c')]);delete _0x236bfc[_0xcc78('0x34')][_0xcc78('0x3c')];_0x1c188c['where']=qs['filters'](_['pick'](_0x236bfc[_0xcc78('0x34')],_0x228062[_0xcc78('0x3d')]),_0x1c6575);if(_0x236bfc[_0xcc78('0x34')][_0xcc78('0x3e')]){_0x1c188c['where']=_[_0xcc78('0x3f')](_0x1c188c[_0xcc78('0x40')],{'$or':_['map'](_0x1c6575,function(_0x27f28b){if(_0x27f28b[_0xcc78('0x32')]!==_0xcc78('0x41')){var _0x188006={};_0x188006[_0x27f28b[_0xcc78('0x2b')]]={'$like':'%'+_0x236bfc[_0xcc78('0x34')]['filter']+'%'};return _0x188006;}})});}_0x1c188c=_[_0xcc78('0x3f')]({},_0x1c188c,_0x236bfc[_0xcc78('0x42')]);var _0x3d02d2={'where':_0x1c188c[_0xcc78('0x40')]};return db['VoiceMusicOnHold'][_0xcc78('0x1f')](_0x3d02d2)[_0xcc78('0x25')](function(_0x559861){_0x367461[_0xcc78('0x1f')]=_0x559861;if(_0x236bfc[_0xcc78('0x34')]['includeAll']){_0x1c188c['include']=[{'all':!![]}];}return db[_0xcc78('0x2f')][_0xcc78('0x43')](_0x1c188c);})['then'](function(_0x3f06e7){_0x367461[_0xcc78('0x44')]=_0x3f06e7;return _0x367461;})['then'](respondWithFilteredResult(_0x2e88ec,_0x1c188c))[_0xcc78('0x45')](handleError(_0x2e88ec,null));};exports[_0xcc78('0x46')]=function(_0x5108f9,_0x33abd0){var _0x493201={'raw':![],'where':{'id':_0x5108f9[_0xcc78('0x47')]['id']}},_0x56dc92={};_0x56dc92[_0xcc78('0x33')]=_['keys'](db[_0xcc78('0x2f')][_0xcc78('0x30')]);_0x56dc92[_0xcc78('0x34')]=_[_0xcc78('0x35')](_0x5108f9['query']);_0x56dc92[_0xcc78('0x3d')]=_[_0xcc78('0x36')](_0x56dc92[_0xcc78('0x33')],_0x56dc92[_0xcc78('0x34')]);_0x493201['attributes']=_[_0xcc78('0x36')](_0x56dc92[_0xcc78('0x33')],qs[_0xcc78('0x38')](_0x5108f9[_0xcc78('0x34')][_0xcc78('0x38')]));_0x493201[_0xcc78('0x37')]=_0x493201[_0xcc78('0x37')]['length']?_0x493201['attributes']:_0x56dc92[_0xcc78('0x33')];if(_0x5108f9[_0xcc78('0x34')][_0xcc78('0x48')]){_0x493201[_0xcc78('0x49')]=[{'all':!![]}];}_0x493201=_[_0xcc78('0x3f')]({},_0x493201,_0x5108f9[_0xcc78('0x42')]);return db[_0xcc78('0x2f')][_0xcc78('0x4a')](_0x493201)[_0xcc78('0x25')](handleEntityNotFound(_0x33abd0,null))[_0xcc78('0x25')](respondWithResult(_0x33abd0,null))['catch'](handleError(_0x33abd0,null));};exports[_0xcc78('0x24')]=function(_0x357eec,_0x3c2ded){if(_0x357eec[_0xcc78('0x4b')]['id']){delete _0x357eec['body']['id'];}return db[_0xcc78('0x2f')][_0xcc78('0x4a')]({'where':{'id':_0x357eec['params']['id']}})[_0xcc78('0x25')](handleEntityNotFound(_0x3c2ded,null))['then'](saveUpdates(_0x357eec[_0xcc78('0x4b')],null))[_0xcc78('0x25')](respondWithResult(_0x3c2ded,null))[_0xcc78('0x45')](handleError(_0x3c2ded,null));};exports[_0xcc78('0x4c')]=function(_0xa8b17f,_0xd83eb2,_0x139a0f){return db['sequelize']['transaction'](function(_0x121c20){if(_0xa8b17f[_0xcc78('0x4b')][_0xcc78('0x4d')]===_0xcc78('0x4e')){_0xa8b17f[_0xcc78('0x4b')][_0xcc78('0x4f')]=path[_0xcc78('0x50')](config['root'],_0xcc78('0x51'),_0xa8b17f[_0xcc78('0x4b')][_0xcc78('0x2b')]);}return db[_0xcc78('0x2f')][_0xcc78('0x4c')](_0xa8b17f[_0xcc78('0x4b')],{'transaction':_0x121c20})[_0xcc78('0x25')](function(_0x119d53){if(_0xa8b17f[_0xcc78('0x4b')][_0xcc78('0x4d')]==='files'){fs['mkdirSync'](_0x119d53[_0xcc78('0x4f')],parseInt(_0xcc78('0x52'),0x8));}var _0x312aac=_0xa8b17f[_0xcc78('0x53')]['get']({'plain':!![]});if(!_0x312aac)throw new Error(_0xcc78('0x54'));if(_0x312aac[_0xcc78('0x55')]===_0xcc78('0x53')){var _0x225685=_0x119d53[_0xcc78('0x27')]({'plain':!![]});return db[_0xcc78('0x56')][_0xcc78('0x4a')]({'where':{'name':'MusicOnHolds','userProfileId':_0x312aac['userProfileId']},'raw':!![]})[_0xcc78('0x25')](function(_0x3cb9bb){if(_0x3cb9bb&&_0x3cb9bb['autoAssociation']===0x0){return db[_0xcc78('0x57')]['create']({'name':_0x225685[_0xcc78('0x2b')],'resourceId':_0x225685['id'],'type':_0x3cb9bb['name'],'sectionId':_0x3cb9bb['id']},{})[_0xcc78('0x25')](function(){return _0x119d53;});}else{return _0x119d53;}})[_0xcc78('0x45')](function(_0x5f50c6){logger[_0xcc78('0x29')](_0xcc78('0x58'),_0x5f50c6);});}return _0x119d53;});})[_0xcc78('0x25')](respondWithResult(_0xd83eb2,0xc9))[_0xcc78('0x45')](handleError(_0xd83eb2,null));};exports[_0xcc78('0x26')]=function(_0x1613ff,_0x41ef04,_0x3857a4){var _0x3c288a;return db[_0xcc78('0x2f')]['find']({'where':{'id':_0x1613ff[_0xcc78('0x47')]['id']}})[_0xcc78('0x25')](function(_0x1921fc){if(_0x1921fc){return db[_0xcc78('0x59')][_0xcc78('0x5a')](function(_0x4d4d5a){return _0x1921fc[_0xcc78('0x26')]({'transaction':_0x4d4d5a,'raw':!![]})[_0xcc78('0x25')](function(_0x525c14){if(_0x525c14[_0xcc78('0x4f')]){fs[_0xcc78('0x5b')](_0x525c14[_0xcc78('0x4f')])['forEach'](function(_0x935deb){fs[_0xcc78('0x5c')](path[_0xcc78('0x50')](_0x525c14[_0xcc78('0x4f')],_0x935deb));});fs[_0xcc78('0x5d')](_0x525c14[_0xcc78('0x4f')]);}return _0x525c14;});})[_0xcc78('0x45')](function(_0x772953){throw new db['Sequelize'][(_0xcc78('0x5e'))](_0x772953['message']);});}})[_0xcc78('0x25')](handleEntityNotFound(_0x41ef04,null))[_0xcc78('0x25')](removeEntity(_0x41ef04,null))[_0xcc78('0x45')](handleError(_0x41ef04,null));};exports[_0xcc78('0x5f')]=function(_0x4b2bb6,_0x401644,_0x240f48){return db[_0xcc78('0x59')]['transaction'](function(_0x2cd008){var _0x5b189d;return db[_0xcc78('0x2f')][_0xcc78('0x4a')]({'where':{'id':_0x4b2bb6[_0xcc78('0x47')]['id']}})[_0xcc78('0x25')](function(_0x9f0da8){if(_0x9f0da8){_0x5b189d=_0x9f0da8;return _0x9f0da8['addSound'](_0x4b2bb6[_0xcc78('0x4b')]['id'],{'transaction':_0x2cd008});}})[_0xcc78('0x25')](function(_0xc5b147){if(_0xc5b147){return db['Sound']['findOne']({'where':{'id':_0x4b2bb6[_0xcc78('0x4b')]['id']},'attributes':['id','name','save_name','converted_format',_0xcc78('0x60')],'raw':!![]});}})[_0xcc78('0x25')](function(_0x50eec5){if(_0x50eec5){var _0xd2d6c1=path[_0xcc78('0x50')](config[_0xcc78('0x61')],_0xcc78('0x62'),util[_0xcc78('0x63')](_0xcc78('0x64'),path[_0xcc78('0x65')](_0x50eec5[_0xcc78('0x66')],path[_0xcc78('0x67')](_0x50eec5['save_name'])),_0x50eec5['converted_format']));var _0x4d9e71=path[_0xcc78('0x50')](config[_0xcc78('0x61')],'server/files/moh',_0x5b189d['name'],util[_0xcc78('0x63')](_0xcc78('0x64'),_0x50eec5[_0xcc78('0x2b')],_0x50eec5[_0xcc78('0x68')]));fs[_0xcc78('0x69')](_0xd2d6c1,_0x4d9e71);return _0x50eec5;}})['catch'](function(_0x20e9f7){throw new db[(_0xcc78('0x6a'))][(_0xcc78('0x5e'))](_0x20e9f7['message']);});})[_0xcc78('0x25')](handleEntityNotFound(_0x401644,null))[_0xcc78('0x25')](respondWithResult(_0x401644,0xc9))[_0xcc78('0x45')](handleError(_0x401644,null));};exports[_0xcc78('0x6b')]=function(_0x101cab,_0x3de946,_0x261c1e){return db[_0xcc78('0x59')][_0xcc78('0x5a')](function(_0x57cdaa){var _0x2d4fec;return db[_0xcc78('0x2f')][_0xcc78('0x6c')]({'where':{'id':_0x101cab[_0xcc78('0x47')]['id']}})[_0xcc78('0x25')](handleEntityNotFound(_0x3de946,null))[_0xcc78('0x25')](function(_0x4d28a2){if(_0x4d28a2){_0x2d4fec=_0x4d28a2;return _0x4d28a2[_0xcc78('0x6b')](_0x101cab['params'][_0xcc78('0x6d')]);}})[_0xcc78('0x25')](function(_0x1b1c51){if(_0x1b1c51){return db[_0xcc78('0x6e')][_0xcc78('0x6c')]({'where':{'id':_0x101cab['params']['id2']},'attributes':['id',_0xcc78('0x2b'),_0xcc78('0x66'),_0xcc78('0x68'),_0xcc78('0x60')],'raw':!![]});}})[_0xcc78('0x25')](function(_0xe65d06){if(_0xe65d06){fs[_0xcc78('0x5c')](path[_0xcc78('0x50')](_0x2d4fec[_0xcc78('0x4f')],util[_0xcc78('0x63')](_0xcc78('0x64'),_0xe65d06[_0xcc78('0x2b')],_0xe65d06[_0xcc78('0x68')])));return _0xe65d06;}})[_0xcc78('0x45')](function(_0x212874){throw new db['Sequelize']['ValidationError'](_0x212874[_0xcc78('0x6f')]);});})[_0xcc78('0x25')](handleEntityNotFound(_0x3de946,null))[_0xcc78('0x25')](respondWithStatusCode(_0x3de946,0xcc))['catch'](handleError(_0x3de946,null));};exports[_0xcc78('0x70')]=function(_0x11f301,_0x145ee8,_0xfa0a96){var _0x4e419f={};var _0x125d67={};var _0x102630;var _0x30a891;return db[_0xcc78('0x2f')][_0xcc78('0x6c')]({'where':{'id':_0x11f301['params']['id']}})[_0xcc78('0x25')](handleEntityNotFound(_0x145ee8,null))[_0xcc78('0x25')](function(_0x4d8fe1){if(_0x4d8fe1){_0x102630=_0x4d8fe1;_0x125d67['model']=_[_0xcc78('0x35')](db[_0xcc78('0x6e')][_0xcc78('0x30')]);_0x125d67[_0xcc78('0x34')]=_[_0xcc78('0x35')](_0x11f301[_0xcc78('0x34')]);_0x125d67['filters']=_[_0xcc78('0x36')](_0x125d67[_0xcc78('0x33')],_0x125d67[_0xcc78('0x34')]);_0x4e419f['attributes']=_['intersection'](_0x125d67['model'],qs['fields'](_0x11f301[_0xcc78('0x34')][_0xcc78('0x38')]));_0x4e419f[_0xcc78('0x37')]=_0x4e419f[_0xcc78('0x37')][_0xcc78('0x39')]?_0x4e419f[_0xcc78('0x37')]:_0x125d67[_0xcc78('0x33')];_0x4e419f[_0xcc78('0x3b')]=qs[_0xcc78('0x3c')](_0x11f301[_0xcc78('0x34')][_0xcc78('0x3c')]);_0x4e419f['where']=qs[_0xcc78('0x3d')](_['pick'](_0x11f301[_0xcc78('0x34')],_0x125d67[_0xcc78('0x3d')]));if(_0x11f301['query'][_0xcc78('0x3e')]){_0x4e419f['where']=_[_0xcc78('0x3f')](_0x4e419f[_0xcc78('0x40')],{'$or':_[_0xcc78('0x2e')](_0x4e419f[_0xcc78('0x37')],function(_0x929d41){var _0x3181d4={};_0x3181d4[_0x929d41]={'$like':'%'+_0x11f301[_0xcc78('0x34')][_0xcc78('0x3e')]+'%'};return _0x3181d4;})});}_0x4e419f=_['merge']({},_0x4e419f,_0x11f301[_0xcc78('0x42')]);return _0x102630['getSounds'](_0x4e419f);}})[_0xcc78('0x25')](function(_0x1a99db){if(_0x1a99db){_0x30a891=_0x1a99db['length'];if(!_0x11f301[_0xcc78('0x34')][_0xcc78('0x71')](_0xcc78('0x3a'))){_0x4e419f[_0xcc78('0x1e')]=qs[_0xcc78('0x1e')](_0x11f301['query'][_0xcc78('0x1e')]);_0x4e419f[_0xcc78('0x20')]=qs[_0xcc78('0x20')](_0x11f301['query'][_0xcc78('0x20')]);}return _0x102630[_0xcc78('0x70')](_0x4e419f);}})[_0xcc78('0x25')](function(_0x1b0089){if(_0x1b0089){return _0x1b0089?{'count':_0x30a891,'rows':_0x1b0089}:null;}})[_0xcc78('0x25')](respondWithResult(_0x145ee8,null))['catch'](handleError(_0x145ee8,null));};
\ No newline at end of file