Built motion from commit ded33658aad58fc8de845a8299a9db59a88cc353. Version 3.0.0...
[motion-next.git] / server / api / sound / sound.controller.js
1 const a583_0x1529=['original_format','sampleRate','limit','VIRTUAL','chmodSync','count','Sound\x20not\x20found','info','../../mysqldb','start','body','UserProfileSection','originalname','channelCount','findOne','../../config/logger','basename','filename','error','description','end','converted_format','%s.%s','Unable\x20to\x20retrieve\x20the\x20current\x20user','offset','filters','save_name','converted_duration','sampleCount','params','index','then','converted_sampleRate','filter','lodash','update','include','util','undefined','keys','catch','rawAttributes','Content-Range','like','extname','send','Sound\x20upload\x20destination:\x20%s','wav','sort','where','original_bitRate','0777','user','model','../../components/parsers/qs','type','UserProfileResource','length','map','json','Sound','format','file','join','merge','duration','Sound\x20upload\x20filepath:\x20%s','original_sampleCount','bitRate','server/files/sounds/converted','get','name','userProfileId','attributes','dest','original_channelCount','original_duration','../../config/environment','role','findAll','root','options','order','show','intersection','set','server/files/sounds/original','destroy','api','sox','pick','sendStatus','create','stack','fields','status','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','query','download','transcode','src'];(function(_0x248b9c,_0x1529f0){const _0x29d8a7=function(_0xd5d1de){while(--_0xd5d1de){_0x248b9c['push'](_0x248b9c['shift']());}};_0x29d8a7(++_0x1529f0);}(a583_0x1529,0x1ad));const a583_0x29d8=function(_0x248b9c,_0x1529f0){_0x248b9c=_0x248b9c-0x0;let _0x29d8a7=a583_0x1529[_0x248b9c];return _0x29d8a7;};const _0x3a13dd=a583_0x29d8;'use strict';const util=require(_0x3a13dd('0xc')),path=require('path'),sox=require(_0x3a13dd('0x40')),fs=require('fs'),_=require(_0x3a13dd('0x9')),qs=require(_0x3a13dd('0x1d')),logger=require(_0x3a13dd('0x5b'))(_0x3a13dd('0x3f')),config=require(_0x3a13dd('0x34')),db=require(_0x3a13dd('0x54'))['db'],{Op,ValidationError}=require('sequelize');function respondWithResult(_0xd5d1de,_0x42fa40){return _0x42fa40=_0x42fa40||0xc8,function(_0x158480){const _0x3abc91=a583_0x29d8;if(_0x158480)return _0xd5d1de['status'](_0x42fa40)[_0x3abc91('0x22')](_0x158480);};}function respondWithFilteredResult(_0x8a138b,_0x3974f6){return function(_0x5880d3){const _0x22754f=a583_0x29d8;if(_0x5880d3){const _0x426ae5=_0x5880d3[_0x22754f('0x51')],_0xc529d2=_0x3974f6['offset'];let _0x39d5ab=_0x3974f6[_0x22754f('0x64')]+_0x3974f6[_0x22754f('0x4e')],_0x3fc0e1;return _0x39d5ab>=_0x426ae5?(_0x39d5ab=_0x426ae5,_0x3fc0e1=0xc8):_0x3fc0e1=0xce,_0x8a138b[_0x22754f('0x46')](_0x3fc0e1),_0x8a138b[_0x22754f('0x3c')](_0x22754f('0x11'),_0xc529d2+'-'+_0x39d5ab+'/'+_0x426ae5)[_0x22754f('0x22')](_0x5880d3);}return null;};}function saveUpdates(_0x39fca4){return function(_0xac5717){const _0x2b07b6=a583_0x29d8;if(_0xac5717)return _0xac5717[_0x2b07b6('0xa')](_0x39fca4)[_0x2b07b6('0x6')](function(_0x459de5){return _0x459de5;});return null;};}function handleEntityNotFound(_0x30da0b){return function(_0xf6794f){const _0x529750=a583_0x29d8;return!_0xf6794f&&_0x30da0b[_0x529750('0x42')](0x194),_0xf6794f;};}function handleError(_0x5ac04d,_0x417cbf){return _0x417cbf=_0x417cbf||0x1f4,function(_0x2f6a7f){const _0x3d2b58=a583_0x29d8;logger[_0x3d2b58('0x5e')](_0x2f6a7f[_0x3d2b58('0x44')]),_0x2f6a7f['name']&&delete _0x2f6a7f[_0x3d2b58('0x2e')],_0x5ac04d['status'](_0x417cbf)[_0x3d2b58('0x14')](_0x2f6a7f);};}exports[_0x3a13dd('0x5')]=function(_0x234e6c,_0x34dc05){const _0x2549e1=_0x3a13dd;let _0x115bc7={};const _0x5e4416={},_0xf6eb40={'count':0x0,'rows':[]},_0x4a8303=_[_0x2549e1('0x21')](db[_0x2549e1('0x23')]['rawAttributes'],function(_0xebef3f){const _0x59c254=_0x2549e1;return{'name':_0xebef3f['fieldName'],'type':_0xebef3f[_0x59c254('0x1e')]['key']};});_0x5e4416[_0x2549e1('0x1c')]=_[_0x2549e1('0x21')](_0x4a8303,_0x2549e1('0x2e')),_0x5e4416['query']=_['keys'](_0x234e6c['query']),_0x5e4416['filters']=_[_0x2549e1('0x3b')](_0x5e4416[_0x2549e1('0x1c')],_0x5e4416[_0x2549e1('0x48')]),_0x115bc7[_0x2549e1('0x30')]=_['intersection'](_0x5e4416['model'],qs['fields'](_0x234e6c[_0x2549e1('0x48')][_0x2549e1('0x45')])),_0x115bc7[_0x2549e1('0x30')]=_0x115bc7[_0x2549e1('0x30')][_0x2549e1('0x20')]?_0x115bc7[_0x2549e1('0x30')]:_0x5e4416[_0x2549e1('0x1c')];typeof _0x234e6c[_0x2549e1('0x48')]['nolimit']===_0x2549e1('0xd')&&(_0x115bc7[_0x2549e1('0x4e')]=qs[_0x2549e1('0x4e')](_0x234e6c[_0x2549e1('0x48')][_0x2549e1('0x4e')]),_0x115bc7['offset']=qs['offset'](_0x234e6c[_0x2549e1('0x48')][_0x2549e1('0x64')]));_0x115bc7[_0x2549e1('0x39')]=qs[_0x2549e1('0x17')](_0x234e6c[_0x2549e1('0x48')][_0x2549e1('0x17')]),_0x115bc7[_0x2549e1('0x18')]=qs[_0x2549e1('0x0')](_[_0x2549e1('0x41')](_0x234e6c[_0x2549e1('0x48')],_0x5e4416['filters']),_0x4a8303);_0x234e6c['query'][_0x2549e1('0x8')]&&(_0x115bc7[_0x2549e1('0x18')]=_[_0x2549e1('0x27')](_0x115bc7[_0x2549e1('0x18')],{[Op['or']]:_['map'](_0x4a8303,function(_0x571699){const _0x4219ac=_0x2549e1;if(_0x571699[_0x4219ac('0x1e')]!==_0x4219ac('0x4f')){const _0x5b4603={};return _0x5b4603[_0x571699[_0x4219ac('0x2e')]]={[Op[_0x4219ac('0x12')]]:'%'+_0x234e6c[_0x4219ac('0x48')][_0x4219ac('0x8')]+'%'},_0x5b4603;}})}));_0x115bc7=_[_0x2549e1('0x27')]({},_0x115bc7,_0x234e6c[_0x2549e1('0x38')]);const _0x613eb={'where':_0x115bc7[_0x2549e1('0x18')]};return db[_0x2549e1('0x23')]['count'](_0x613eb)[_0x2549e1('0x6')](function(_0x44b32d){const _0x474eb5=_0x2549e1;return _0xf6eb40[_0x474eb5('0x51')]=_0x44b32d,_0x234e6c[_0x474eb5('0x48')]['includeAll']&&(_0x115bc7[_0x474eb5('0xb')]=[{'all':!![]}]),db[_0x474eb5('0x23')][_0x474eb5('0x36')](_0x115bc7);})['then'](function(_0x102cdb){return _0xf6eb40['rows']=_0x102cdb,_0xf6eb40;})['then'](respondWithFilteredResult(_0x34dc05,_0x115bc7))['catch'](handleError(_0x34dc05,null));},exports[_0x3a13dd('0x3a')]=function(_0x20f8eb,_0x73a8ad){const _0x28ccd4=_0x3a13dd;let _0x4a40af={'raw':!![],'where':{'id':_0x20f8eb[_0x28ccd4('0x4')]['id']}};const _0x540099={};return _0x540099[_0x28ccd4('0x1c')]=_['keys'](db[_0x28ccd4('0x23')][_0x28ccd4('0x10')]),_0x540099['query']=_[_0x28ccd4('0xe')](_0x20f8eb[_0x28ccd4('0x48')]),_0x540099[_0x28ccd4('0x0')]=_[_0x28ccd4('0x3b')](_0x540099[_0x28ccd4('0x1c')],_0x540099['query']),_0x4a40af[_0x28ccd4('0x30')]=_[_0x28ccd4('0x3b')](_0x540099[_0x28ccd4('0x1c')],qs['fields'](_0x20f8eb[_0x28ccd4('0x48')][_0x28ccd4('0x45')])),_0x4a40af[_0x28ccd4('0x30')]=_0x4a40af[_0x28ccd4('0x30')][_0x28ccd4('0x20')]?_0x4a40af[_0x28ccd4('0x30')]:_0x540099[_0x28ccd4('0x1c')],_0x20f8eb[_0x28ccd4('0x48')]['includeAll']&&(_0x4a40af['include']=[{'all':!![]}]),_0x4a40af=_[_0x28ccd4('0x27')]({},_0x4a40af,_0x20f8eb[_0x28ccd4('0x38')]),db[_0x28ccd4('0x23')][_0x28ccd4('0x5a')](_0x4a40af)['then'](handleEntityNotFound(_0x73a8ad,null))['then'](respondWithResult(_0x73a8ad,null))[_0x28ccd4('0xf')](handleError(_0x73a8ad,null));},exports['download']=function(_0x3fae92,_0x2789be){const _0xf8e837=_0x3a13dd;return db[_0xf8e837('0x23')][_0xf8e837('0x5a')]({'where':{'id':_0x3fae92[_0xf8e837('0x4')]['id']},'attributes':[_0xf8e837('0x2e'),_0xf8e837('0x1'),'converted_format'],'raw':!![]})['then'](handleEntityNotFound(_0x2789be,null))[_0xf8e837('0x6')](function(_0x514c12){const _0xa3274=_0xf8e837;if(_0x514c12){if(!fs['existsSync'](path[_0xa3274('0x26')](config['root'],'server/files/sounds/converted',_0x514c12[_0xa3274('0x1')]+'.'+_0x514c12['converted_format'])))throw new ValidationError(_0xa3274('0x52'));return _0x2789be[_0xa3274('0x49')](path['join'](config['root'],'server/files/sounds/converted',util['format'](_0xa3274('0x62'),_0x514c12[_0xa3274('0x1')],_0x514c12[_0xa3274('0x61')])),util[_0xa3274('0x24')](_0xa3274('0x62'),_0x514c12[_0xa3274('0x2e')],_0x514c12[_0xa3274('0x61')]));}return null;})[_0xf8e837('0xf')](handleError(_0x2789be,null));},exports[_0x3a13dd('0x43')]=function(_0x2fddac,_0x2aabea){const _0x512505=_0x3a13dd,_0x296526={'name':path[_0x512505('0x5c')](_0x2fddac[_0x512505('0x25')][_0x512505('0x58')],path[_0x512505('0x13')](_0x2fddac['file'][_0x512505('0x58')])),'save_name':path[_0x512505('0x5c')](_0x2fddac['file']['filename'],path[_0x512505('0x13')](_0x2fddac[_0x512505('0x25')][_0x512505('0x5d')])),'original_format':path['extname'](_0x2fddac[_0x512505('0x25')][_0x512505('0x58')])['substring'](0x1),'converted_format':_0x512505('0x16')},_0x4e836e=path['join'](config[_0x512505('0x37')],_0x512505('0x3d'),_0x2fddac[_0x512505('0x25')][_0x512505('0x5d')]),_0x5110e3=path[_0x512505('0x26')](config[_0x512505('0x37')],_0x512505('0x2c'),util[_0x512505('0x24')]('%s.%s',path[_0x512505('0x5c')](_0x2fddac[_0x512505('0x25')]['filename'],path[_0x512505('0x13')](_0x2fddac[_0x512505('0x25')][_0x512505('0x5d')])),_0x296526[_0x512505('0x61')]));logger[_0x512505('0x53')](_0x512505('0x29'),_0x4e836e),logger['info'](_0x512505('0x15'),_0x5110e3);try{fs[_0x512505('0x50')](_0x4e836e,parseInt(_0x512505('0x1a'),0x8));const _0x12f4c2=sox[_0x512505('0x4a')](_0x4e836e,_0x5110e3,{'sampleRate':0x1f40,'format':_0x512505('0x16'),'channelCount':0x1,'bitRate':0xc0*0x400,'compressionQuality':0x5});_0x12f4c2['on']('error',function(_0x509d9f){const _0x71fd71=_0x512505;fs['unlinkSync'](_0x4e836e),_0x2aabea[_0x71fd71('0x46')](0x1f4)['send'](_0x509d9f);}),_0x12f4c2['on'](_0x512505('0x4b'),function(_0x54db60){const _0x4c051e=_0x512505;_0x296526[_0x4c051e('0x33')]=isNaN(_0x54db60[_0x4c051e('0x28')])?null:_0x54db60[_0x4c051e('0x28')]*0x3e8,_0x296526[_0x4c051e('0x2a')]=isNaN(_0x54db60[_0x4c051e('0x3')])?null:_0x54db60[_0x4c051e('0x3')],_0x296526[_0x4c051e('0x32')]=isNaN(_0x54db60[_0x4c051e('0x59')])?null:_0x54db60['channelCount'],_0x296526[_0x4c051e('0x19')]=isNaN(_0x54db60['bitRate'])?null:_0x54db60['bitRate'],_0x296526['original_sampleRate']=isNaN(_0x54db60['sampleRate'])?null:_0x54db60['sampleRate'];}),_0x12f4c2['on'](_0x512505('0x31'),function(_0x4d9c39){const _0x3dd485=_0x512505;_0x296526[_0x3dd485('0x2')]=isNaN(_0x4d9c39[_0x3dd485('0x28')])?null:_0x4d9c39[_0x3dd485('0x28')]*0x3e8,_0x296526['converted_sampleCount']=isNaN(_0x4d9c39[_0x3dd485('0x3')])?null:_0x4d9c39['sampleCount'],_0x296526['converted_channelCount']=isNaN(_0x4d9c39[_0x3dd485('0x59')])?null:_0x4d9c39[_0x3dd485('0x59')],_0x296526['converted_bitRate']=isNaN(_0x4d9c39[_0x3dd485('0x2b')])?null:_0x4d9c39['bitRate'],_0x296526[_0x3dd485('0x7')]=isNaN(_0x4d9c39[_0x3dd485('0x4d')])?null:_0x4d9c39['sampleRate'];}),_0x12f4c2['on']('end',function(){const _0x20b04f=_0x512505;return fs[_0x20b04f('0x50')](_0x5110e3,parseInt(_0x20b04f('0x1a'),0x8)),db[_0x20b04f('0x23')]['create'](_0x296526)[_0x20b04f('0x6')](function(_0x4ec208){const _0x9c72bf=_0x20b04f,_0x51ab5c={'role':_0x2fddac['body'][_0x9c72bf('0x35')],'userProfileId':_0x2fddac['body'][_0x9c72bf('0x2f')]};if(!_0x51ab5c)throw new Error(_0x9c72bf('0x63'));if(_0x51ab5c[_0x9c72bf('0x35')]===_0x9c72bf('0x1b')){const _0x4b6619=_0x4ec208[_0x9c72bf('0x2d')]({'plain':!![]});return db[_0x9c72bf('0x57')]['findOne']({'where':{'name':'Sounds','userProfileId':_0x51ab5c[_0x9c72bf('0x2f')]},'raw':!![]})[_0x9c72bf('0x6')](function(_0x5e7903){const _0x2d39f5=_0x9c72bf;return _0x5e7903&&_0x5e7903['autoAssociation']===0x0?db[_0x2d39f5('0x1f')][_0x2d39f5('0x43')]({'name':_0x4b6619['name'],'resourceId':_0x4b6619['id'],'type':_0x5e7903['name'],'sectionId':_0x5e7903['id']},{})[_0x2d39f5('0x6')](function(){return _0x4ec208;}):_0x4ec208;})['catch'](function(_0x57b7fe){const _0x1e965e=_0x9c72bf;logger[_0x1e965e('0x5e')](_0x1e965e('0x47'),_0x57b7fe);throw _0x57b7fe;});}return _0x4ec208;})[_0x20b04f('0x6')](respondWithResult(_0x2aabea,null))[_0x20b04f('0xf')](handleError(_0x2aabea,null));}),_0x12f4c2[_0x512505('0x55')]();}catch(_0x439394){_0x2aabea[_0x512505('0x46')](0x1f4)[_0x512505('0x14')](_0x439394);}},exports[_0x3a13dd('0xa')]=function(_0x33c8d9,_0x31285c){const _0x19080f=_0x3a13dd;return db['Sound']['findOne']({'where':{'id':_0x33c8d9[_0x19080f('0x4')]['id']}})[_0x19080f('0x6')](handleEntityNotFound(_0x31285c,null))[_0x19080f('0x6')](saveUpdates(_[_0x19080f('0x41')](_0x33c8d9[_0x19080f('0x56')],[_0x19080f('0x2e'),_0x19080f('0x5f')]),null))['then'](respondWithResult(_0x31285c,null))['catch'](handleError(_0x31285c,null));},exports['delete']=function(_0x157fe3,_0x10c012){const _0x561a0c=_0x3a13dd;return db[_0x561a0c('0x23')][_0x561a0c('0x5a')]({'where':{'id':_0x157fe3['params']['id']}})[_0x561a0c('0x6')](function(_0x7c0f00){const _0x4eb2b2=_0x561a0c;if(_0x7c0f00)return _0x7c0f00[_0x4eb2b2('0x3e')]();})['then'](function(_0x37a786){const _0xb8e953=_0x561a0c,_0x50f53e=path[_0xb8e953('0x26')](config['root'],'server/files/sounds/original',util[_0xb8e953('0x24')](_0xb8e953('0x62'),_0x37a786['save_name'],_0x37a786[_0xb8e953('0x4c')])),_0x13f234=path[_0xb8e953('0x26')](config[_0xb8e953('0x37')],_0xb8e953('0x2c'),util[_0xb8e953('0x24')]('%s.%s',_0x37a786['save_name'],_0x37a786[_0xb8e953('0x61')]));return fs['unlinkSync'](_0x50f53e),fs['unlinkSync'](_0x13f234),_0x37a786;})[_0x561a0c('0x6')](function(_0x4a12b3){const _0x219e8d=_0x561a0c;if(_0x4a12b3)return _0x10c012['status'](0xcc)[_0x219e8d('0x60')]();})[_0x561a0c('0x6')](handleEntityNotFound(_0x10c012,null))['catch'](handleError(_0x10c012,null));};