f616d15319b673ab51903cf361448a9e511f73f2
[motion-next.git] / server / api / squareRecording / squareRecording.controller.js
1 const a605_0x50c2=['uniqueid','query','type','key','send','order','filter','offset','limit','recording','path','decryptFile','filename','Content-Range','%s.cypher','findOne','VIRTUAL','destroy','show','unlink','intersection','where','model','filters','fields','message','cancellazione\x20fisica\x20documento\x20%s','map','length','savePath','\x22\x20trovato\x20eseguo\x20la\x20cancellazione','then','keys','catch','includeAll','name','SquareRecording\x20not\x20found','../../mysqldb','sequelize','update','isNil','status','extname','unlinkSync','existsSync','index','params','Not\x20found','sort','like','../../components/parsers/qs','rawAttributes','attributes','util','../../config/environment','download','json','merge','SquareRecording','body','include','rows','count','lodash'];(function(_0x5ddb27,_0x50c2f0){const _0x443b3b=function(_0x2d84e9){while(--_0x2d84e9){_0x5ddb27['push'](_0x5ddb27['shift']());}};_0x443b3b(++_0x50c2f0);}(a605_0x50c2,0x6e));const a605_0x443b=function(_0x5ddb27,_0x50c2f0){_0x5ddb27=_0x5ddb27-0x0;let _0x443b3b=a605_0x50c2[_0x5ddb27];return _0x443b3b;};const _0x23858a=a605_0x443b;'use strict';const util=require(_0x23858a('0x7')),path=require(_0x23858a('0x1c')),fs=require('fs'),_=require(_0x23858a('0x11')),qs=require(_0x23858a('0x4')),logger=require('../../config/logger')('api'),config=require(_0x23858a('0x8')),db=require(_0x23858a('0x37'))['db'],{Op,ValidationError}=require(_0x23858a('0x38')),{InternalError}=require('error-middleware/errors');function respondWithResult(_0x2d84e9,_0x5c02fe){return _0x5c02fe=_0x5c02fe||0xc8,function(_0x3f523e){const _0x4f256a=a605_0x443b;if(_0x3f523e)return _0x2d84e9['status'](_0x5c02fe)[_0x4f256a('0xa')](_0x3f523e);};}function respondWithFilteredResult(_0x48cf65,_0x276c9a){return function(_0x5aef8b){const _0x3432a3=a605_0x443b;if(_0x5aef8b){const _0x4e7e44=_0x5aef8b[_0x3432a3('0x10')],_0x7f4e05=_0x276c9a[_0x3432a3('0x19')];let _0xd84ccf=_0x276c9a[_0x3432a3('0x19')]+_0x276c9a[_0x3432a3('0x1a')],_0x4e9c8b;return _0xd84ccf>=_0x4e7e44?(_0xd84ccf=_0x4e7e44,_0x4e9c8b=0xc8):_0x4e9c8b=0xce,_0x48cf65[_0x3432a3('0x3b')](_0x4e9c8b),_0x48cf65['set'](_0x3432a3('0x1f'),_0x7f4e05+'-'+_0xd84ccf+'/'+_0x4e7e44)[_0x3432a3('0xa')](_0x5aef8b);}return null;};}function saveUpdates(_0x774445){return function(_0x2a7b40){const _0x3741c5=a605_0x443b;if(_0x2a7b40)return _0x2a7b40[_0x3741c5('0x39')](_0x774445)[_0x3741c5('0x31')](function(_0x56da5f){return _0x56da5f;});return null;};}function handleEntityNotFound(_0x28e818){return function(_0x4b9e6a){return!_0x4b9e6a&&_0x28e818['sendStatus'](0x194),_0x4b9e6a;};}function handleError(_0x563d2f,_0x1c1655){return _0x1c1655=_0x1c1655||0x1f4,function(_0x22d86c){const _0xdaae27=a605_0x443b;logger['error'](_0x22d86c['stack']),_0x22d86c[_0xdaae27('0x35')]&&delete _0x22d86c[_0xdaae27('0x35')],_0x563d2f[_0xdaae27('0x3b')](_0x1c1655)[_0xdaae27('0x16')](_0x22d86c);};}exports[_0x23858a('0x3f')]=function(_0x1a535e,_0x1322e2){const _0x598ca1=_0x23858a;let _0x2c2218={};const _0x247013={},_0x4e7b1d={'count':0x0,'rows':[]},_0x4f98b7=_[_0x598ca1('0x2d')](db[_0x598ca1('0xc')][_0x598ca1('0x5')],function(_0x2677e7){const _0x5bfd96=_0x598ca1;return{'name':_0x2677e7['fieldName'],'type':_0x2677e7[_0x5bfd96('0x14')][_0x5bfd96('0x15')]};});_0x247013[_0x598ca1('0x28')]=_[_0x598ca1('0x2d')](_0x4f98b7,_0x598ca1('0x35')),_0x247013['query']=_[_0x598ca1('0x32')](_0x1a535e[_0x598ca1('0x13')]),_0x247013[_0x598ca1('0x29')]=_[_0x598ca1('0x26')](_0x247013[_0x598ca1('0x28')],_0x247013[_0x598ca1('0x13')]),_0x2c2218[_0x598ca1('0x6')]=_[_0x598ca1('0x26')](_0x247013['model'],qs[_0x598ca1('0x2a')](_0x1a535e[_0x598ca1('0x13')][_0x598ca1('0x2a')])),_0x2c2218['attributes']=_0x2c2218['attributes'][_0x598ca1('0x2e')]?_0x2c2218[_0x598ca1('0x6')]:_0x247013[_0x598ca1('0x28')];typeof _0x1a535e['query']['nolimit']==='undefined'&&(_0x2c2218[_0x598ca1('0x1a')]=qs[_0x598ca1('0x1a')](_0x1a535e['query']['limit']),_0x2c2218['offset']=qs['offset'](_0x1a535e[_0x598ca1('0x13')]['offset']));_0x2c2218[_0x598ca1('0x17')]=qs[_0x598ca1('0x2')](_0x1a535e[_0x598ca1('0x13')][_0x598ca1('0x2')]),_0x2c2218[_0x598ca1('0x27')]=qs[_0x598ca1('0x29')](_['pick'](_0x1a535e[_0x598ca1('0x13')],_0x247013[_0x598ca1('0x29')]),_0x4f98b7);_0x1a535e['query'][_0x598ca1('0x18')]&&(_0x2c2218['where']=_[_0x598ca1('0xb')](_0x2c2218[_0x598ca1('0x27')],{[Op['or']]:_[_0x598ca1('0x2d')](_0x4f98b7,function(_0x15bbf8){const _0x29c0c1=_0x598ca1;if(_0x15bbf8[_0x29c0c1('0x14')]!==_0x29c0c1('0x22')){const _0x476491={};return _0x476491[_0x15bbf8[_0x29c0c1('0x35')]]={[Op[_0x29c0c1('0x3')]]:'%'+_0x1a535e[_0x29c0c1('0x13')][_0x29c0c1('0x18')]+'%'},_0x476491;}})}));_0x2c2218=_['merge']({},_0x2c2218,_0x1a535e['options']);const _0x3fe9a6={'where':_0x2c2218[_0x598ca1('0x27')]};return db['SquareRecording'][_0x598ca1('0x10')](_0x3fe9a6)[_0x598ca1('0x31')](function(_0x17e5cf){const _0x2fc6b4=_0x598ca1;return _0x4e7b1d['count']=_0x17e5cf,_0x1a535e[_0x2fc6b4('0x13')][_0x2fc6b4('0x34')]&&(_0x2c2218['include']=[{'all':!![]}]),db[_0x2fc6b4('0xc')]['findAll'](_0x2c2218);})[_0x598ca1('0x31')](function(_0x58ba74){const _0x5dc215=_0x598ca1;return _0x4e7b1d[_0x5dc215('0xf')]=_0x58ba74,_0x4e7b1d;})[_0x598ca1('0x31')](respondWithFilteredResult(_0x1322e2,_0x2c2218))[_0x598ca1('0x33')](handleError(_0x1322e2,null));},exports[_0x23858a('0x24')]=function(_0x39acca,_0x1cad77){const _0x3bf73c=_0x23858a;let _0x4e5d04={'raw':!![],'where':{'id':_0x39acca[_0x3bf73c('0x0')]['id']}};const _0x163502={};return _0x163502[_0x3bf73c('0x28')]=_[_0x3bf73c('0x32')](db['SquareRecording'][_0x3bf73c('0x5')]),_0x163502['query']=_['keys'](_0x39acca[_0x3bf73c('0x13')]),_0x163502['filters']=_['intersection'](_0x163502['model'],_0x163502[_0x3bf73c('0x13')]),_0x4e5d04[_0x3bf73c('0x6')]=_[_0x3bf73c('0x26')](_0x163502[_0x3bf73c('0x28')],qs[_0x3bf73c('0x2a')](_0x39acca['query'][_0x3bf73c('0x2a')])),_0x4e5d04[_0x3bf73c('0x6')]=_0x4e5d04[_0x3bf73c('0x6')][_0x3bf73c('0x2e')]?_0x4e5d04[_0x3bf73c('0x6')]:_0x163502[_0x3bf73c('0x28')],_0x39acca['query'][_0x3bf73c('0x34')]&&(_0x4e5d04[_0x3bf73c('0xe')]=[{'all':!![]}]),_0x4e5d04=_[_0x3bf73c('0xb')]({},_0x4e5d04,_0x39acca['options']),db['SquareRecording'][_0x3bf73c('0x21')](_0x4e5d04)['then'](handleEntityNotFound(_0x1cad77,null))[_0x3bf73c('0x31')](respondWithResult(_0x1cad77,null))['catch'](handleError(_0x1cad77,null));},exports['create']=function(_0x5e3f7b,_0x26cd6a){const _0x5ef044=_0x23858a;return db[_0x5ef044('0xc')]['create'](_0x5e3f7b[_0x5ef044('0xd')],{})['then'](respondWithResult(_0x26cd6a,0xc9))[_0x5ef044('0x33')](handleError(_0x26cd6a,null));},exports[_0x23858a('0x39')]=function(_0x4213eb,_0x1ec217){const _0x559ebe=_0x23858a;return _0x4213eb['body']['id']&&delete _0x4213eb['body']['id'],db[_0x559ebe('0xc')][_0x559ebe('0x21')]({'where':{'id':_0x4213eb[_0x559ebe('0x0')]['id']}})[_0x559ebe('0x31')](handleEntityNotFound(_0x1ec217,null))[_0x559ebe('0x31')](saveUpdates(_0x4213eb[_0x559ebe('0xd')],null))['then'](respondWithResult(_0x1ec217,null))[_0x559ebe('0x33')](handleError(_0x1ec217,null));},exports['download']=function(_0x29c3a4,_0x48a5b0){const _0x5026ec=_0x23858a,_0x8e4d0f=require('../../components/encryptor');let _0x39951e=![];const _0x346ebb={};return _0x29c3a4[_0x5026ec('0x13')]['type']&&_0x29c3a4['query'][_0x5026ec('0x14')]==='uniqueid'?_0x346ebb[_0x5026ec('0x12')]=_0x29c3a4[_0x5026ec('0x0')]['id']:_0x346ebb['id']=_0x29c3a4['params']['id'],db['SquareRecording'][_0x5026ec('0x21')]({'where':_0x346ebb,'attributes':['id',_0x5026ec('0x2f'),'filename'],'raw':!![]})['then'](handleEntityNotFound(_0x48a5b0,null))['then'](function(_0x44db1a){const _0x1648e5=_0x5026ec;if(_0x44db1a){const _0x3a12e2=_0x44db1a[_0x1648e5('0x2f')],_0x7bc08e=util['format'](_0x1648e5('0x20'),_0x3a12e2);if(fs[_0x1648e5('0x3e')](_0x7bc08e))return _0x39951e=!![],_0x8e4d0f[_0x1648e5('0x1d')](_0x7bc08e,_0x3a12e2,config['secrets'][_0x1648e5('0x1b')])[_0x1648e5('0x31')](function(){return _0x44db1a;});return _0x44db1a;}})[_0x5026ec('0x31')](function(_0x5a455e){const _0x9ed62f=_0x5026ec;if(_0x5a455e){const _0x3fedef=_0x5a455e['savePath'];if(!fs[_0x9ed62f('0x3e')](_0x3fedef))throw new ValidationError(_0x9ed62f('0x36'));return _0x5a455e[_0x9ed62f('0x1e')]?_0x48a5b0[_0x9ed62f('0x9')](_0x3fedef,_0x5a455e[_0x9ed62f('0x1e')]+path[_0x9ed62f('0x3c')](_0x3fedef),function(){_0x39951e&&fs['unlink'](_0x3fedef);}):_0x48a5b0[_0x9ed62f('0x9')](_0x3fedef,function(){const _0x2a8fac=_0x9ed62f;_0x39951e&&fs[_0x2a8fac('0x25')](_0x3fedef);});}})[_0x5026ec('0x33')](function(_0x46627d){const _0x132dc8=_0x5026ec;if(_0x46627d[_0x132dc8('0x2b')]===_0x132dc8('0x36'))_0x48a5b0[_0x132dc8('0x3b')](0x194)[_0x132dc8('0x16')](_0x132dc8('0x1'));else return handleError(_0x48a5b0,null);});},exports['destroy']=function(_0x53334f,_0x2ccf94){const _0x19e297=_0x23858a;return db[_0x19e297('0xc')]['findOne']({'where':{'id':_0x53334f[_0x19e297('0x0')]['id']}})[_0x19e297('0x31')](function(_0x2475f8){if(!_0x2475f8)throw new ReferenceError('Entity\x20not\x20found');return _0x2475f8;})['then'](function(_0x5118be){const _0x4a49c9=_0x19e297;let _0x9e518=_0x5118be[_0x4a49c9('0x2f')];return logger['info'](_0x4a49c9('0x2c'),_0x9e518),!_[_0x4a49c9('0x3a')](_0x5118be['savePath'])&&fs[_0x4a49c9('0x3e')](_0x9e518)&&(logger['info']('File:\x20\x22'+_0x9e518+_0x4a49c9('0x30')),fs[_0x4a49c9('0x3d')](_0x9e518)),_0x9e518=_0x9e518+'.cypher',!_[_0x4a49c9('0x3a')](_0x5118be[_0x4a49c9('0x2f')])&&fs[_0x4a49c9('0x3e')](_0x9e518)&&(logger['info']('File:\x20\x22'+_0x9e518+_0x4a49c9('0x30')),fs['unlinkSync'](_0x9e518)),_0x5118be;})[_0x19e297('0x31')](function(_0x751afb){const _0x1974ad=_0x19e297;if(!_0x751afb)throw new InternalError();return _0x751afb[_0x1974ad('0x23')]();})['then'](function(){_0x2ccf94['status'](0xcc)['end']();})['catch'](handleError(_0x2ccf94,null));};