cc59c754938e8a0c7255335c8fbdc7af4ac9fbf9
[motion-next.git] / server / api / attachment / attachment.controller.js
1 const a29_0x4ca6=['Attachment','status','destroy','keys','files/attachments/','map','create','filter','updatedAt','sendStatus','set','filename','offset','nolimit','filters','intersection','findOne','originalname','fieldName','fields','error','undefined','../../components/parsers/qs','findAll','pick','includeAll','count','update','path','createdAt','omit','like','attributes','include','json','mimetype','VIRTUAL','limit','sort','merge','stack','query','basename','lodash','type','where','options','join','download','length','get','../../mysqldb','rows','root','clone','Content-Range','rawAttributes','model','body','catch','api','index','file','send','name','params','then','../../config/environment'];(function(_0x12d61a,_0x4ca6b4){const _0x21a296=function(_0x37dd65){while(--_0x37dd65){_0x12d61a['push'](_0x12d61a['shift']());}};_0x21a296(++_0x4ca6b4);}(a29_0x4ca6,0x1c0));const a29_0x21a2=function(_0x12d61a,_0x4ca6b4){_0x12d61a=_0x12d61a-0x0;let _0x21a296=a29_0x4ca6[_0x12d61a];return _0x21a296;};const _0x13aa54=a29_0x21a2;'use strict';const path=require(_0x13aa54('0x38')),_=require(_0x13aa54('0x3')),qs=require(_0x13aa54('0x32')),logger=require('../../config/logger')(_0x13aa54('0x14')),config=require(_0x13aa54('0x1b')),db=require(_0x13aa54('0xb'))['db'],{Op}=require('sequelize');function respondWithResult(_0x37dd65,_0x14cd0c){return _0x14cd0c=_0x14cd0c||0xc8,function(_0x259ddb){const _0x52b163=a29_0x21a2;if(_0x259ddb)return _0x37dd65['status'](_0x14cd0c)[_0x52b163('0x3e')](_0x259ddb);};}function respondWithFilteredResult(_0x13a382,_0x499196){return function(_0x1b1f43){const _0x34a532=a29_0x21a2;if(_0x1b1f43){const _0x19a9a3=_0x1b1f43[_0x34a532('0x36')],_0x536f92=_0x499196[_0x34a532('0x28')];let _0x2d6e36=_0x499196[_0x34a532('0x28')]+_0x499196[_0x34a532('0x41')],_0x367743;return _0x2d6e36>=_0x19a9a3?(_0x2d6e36=_0x19a9a3,_0x367743=0xc8):_0x367743=0xce,_0x13a382[_0x34a532('0x1d')](_0x367743),_0x13a382[_0x34a532('0x26')](_0x34a532('0xf'),_0x536f92+'-'+_0x2d6e36+'/'+_0x19a9a3)[_0x34a532('0x3e')](_0x1b1f43);}return null;};}function saveUpdates(_0x19128c){return function(_0x28a3e5){const _0x2f55d7=a29_0x21a2;if(_0x28a3e5)return _0x28a3e5[_0x2f55d7('0x37')](_0x19128c)['then'](function(_0x46b395){return _0x46b395;});return null;};}function removeEntity(_0x3717ea){return function(_0x2f7dac){const _0x3b6ec3=a29_0x21a2;if(_0x2f7dac)return _0x2f7dac['destroy']()[_0x3b6ec3('0x1a')](function(){const _0x2e558b=_0x3b6ec3;_0x3717ea[_0x2e558b('0x1d')](0xcc)['end']();});};}function handleEntityNotFound(_0x21607f){return function(_0xa3cd87){const _0x26a164=a29_0x21a2;return!_0xa3cd87&&_0x21607f[_0x26a164('0x25')](0x194),_0xa3cd87;};}function handleError(_0x3967bd,_0x5bbd41){return _0x5bbd41=_0x5bbd41||0x1f4,function(_0x5d0877){const _0x119981=a29_0x21a2;logger[_0x119981('0x30')](_0x5d0877[_0x119981('0x0')]),_0x5d0877[_0x119981('0x18')]&&delete _0x5d0877[_0x119981('0x18')],_0x3967bd[_0x119981('0x1d')](_0x5bbd41)[_0x119981('0x17')](_0x5d0877);};}exports[_0x13aa54('0x15')]=function(_0x3e3e9f,_0x3ea189){const _0x32f696=_0x13aa54;let _0x2b434a={};const _0x22a5e0={},_0x38cde0={'count':0x0,'rows':[]},_0xd1301=_[_0x32f696('0x21')](db['Attachment'][_0x32f696('0x10')],function(_0x233db2){const _0x3a68f4=_0x32f696;return{'name':_0x233db2[_0x3a68f4('0x2e')],'type':_0x233db2[_0x3a68f4('0x4')]['key']};});_0x22a5e0[_0x32f696('0x11')]=_[_0x32f696('0x21')](_0xd1301,'name'),_0x22a5e0[_0x32f696('0x1')]=_[_0x32f696('0x1f')](_0x3e3e9f[_0x32f696('0x1')]),_0x22a5e0['filters']=_[_0x32f696('0x2b')](_0x22a5e0[_0x32f696('0x11')],_0x22a5e0['query']),_0x2b434a['attributes']=_[_0x32f696('0x2b')](_0x22a5e0[_0x32f696('0x11')],qs[_0x32f696('0x2f')](_0x3e3e9f[_0x32f696('0x1')][_0x32f696('0x2f')])),_0x2b434a[_0x32f696('0x3c')]=_0x2b434a['attributes'][_0x32f696('0x9')]?_0x2b434a[_0x32f696('0x3c')]:_0x22a5e0[_0x32f696('0x11')];typeof _0x3e3e9f[_0x32f696('0x1')][_0x32f696('0x29')]===_0x32f696('0x31')&&(_0x2b434a[_0x32f696('0x41')]=qs['limit'](_0x3e3e9f[_0x32f696('0x1')][_0x32f696('0x41')]),_0x2b434a['offset']=qs[_0x32f696('0x28')](_0x3e3e9f[_0x32f696('0x1')]['offset']));_0x2b434a['order']=qs[_0x32f696('0x42')](_0x3e3e9f[_0x32f696('0x1')]['sort']),_0x2b434a['where']=qs['filters'](_[_0x32f696('0x34')](_0x3e3e9f[_0x32f696('0x1')],_0x22a5e0[_0x32f696('0x2a')]),_0xd1301);_0x3e3e9f[_0x32f696('0x1')][_0x32f696('0x23')]&&(_0x2b434a[_0x32f696('0x5')]=_[_0x32f696('0x43')](_0x2b434a[_0x32f696('0x5')],{[Op['or']]:_[_0x32f696('0x21')](_0xd1301,function(_0x1153d6){const _0x1225d9=_0x32f696;if(_0x1153d6[_0x1225d9('0x4')]!==_0x1225d9('0x40')){const _0xbfb394={};return _0xbfb394[_0x1153d6['name']]={[Op[_0x1225d9('0x3b')]]:'%'+_0x3e3e9f[_0x1225d9('0x1')][_0x1225d9('0x23')]+'%'},_0xbfb394;}})}));_0x2b434a=_['merge']({},_0x2b434a,_0x3e3e9f['options']);const _0x444143={'where':_0x2b434a[_0x32f696('0x5')]};return db['Attachment']['count'](_0x444143)[_0x32f696('0x1a')](function(_0x268488){const _0x38d8f6=_0x32f696;return _0x38cde0[_0x38d8f6('0x36')]=_0x268488,_0x3e3e9f[_0x38d8f6('0x1')][_0x38d8f6('0x35')]&&(_0x2b434a[_0x38d8f6('0x3d')]=[{'all':!![]}]),db['Attachment'][_0x38d8f6('0x33')](_0x2b434a);})['then'](function(_0x2e69e5){const _0x124106=_0x32f696;return _0x38cde0[_0x124106('0xc')]=_0x2e69e5,_0x38cde0;})[_0x32f696('0x1a')](respondWithFilteredResult(_0x3ea189,_0x2b434a))[_0x32f696('0x13')](handleError(_0x3ea189,null));},exports['show']=function(_0x2dd5c4,_0xaea37b){const _0x2bbba3=_0x13aa54;let _0x2b4b20={'raw':!![],'where':{'id':_0x2dd5c4[_0x2bbba3('0x19')]['id']}};const _0xa92f51={};return _0xa92f51[_0x2bbba3('0x11')]=_[_0x2bbba3('0x1f')](db[_0x2bbba3('0x1c')][_0x2bbba3('0x10')]),_0xa92f51['query']=_[_0x2bbba3('0x1f')](_0x2dd5c4['query']),_0xa92f51[_0x2bbba3('0x2a')]=_[_0x2bbba3('0x2b')](_0xa92f51[_0x2bbba3('0x11')],_0xa92f51['query']),_0x2b4b20[_0x2bbba3('0x3c')]=_['intersection'](_0xa92f51[_0x2bbba3('0x11')],qs[_0x2bbba3('0x2f')](_0x2dd5c4[_0x2bbba3('0x1')][_0x2bbba3('0x2f')])),_0x2b4b20['attributes']=_0x2b4b20[_0x2bbba3('0x3c')][_0x2bbba3('0x9')]?_0x2b4b20[_0x2bbba3('0x3c')]:_0xa92f51[_0x2bbba3('0x11')],_0x2dd5c4['query']['includeAll']&&(_0x2b4b20['include']=[{'all':!![]}]),_0x2b4b20=_['merge']({},_0x2b4b20,_0x2dd5c4[_0x2bbba3('0x6')]),db['Attachment'][_0x2bbba3('0x2c')](_0x2b4b20)[_0x2bbba3('0x1a')](handleEntityNotFound(_0xaea37b,null))[_0x2bbba3('0x1a')](respondWithResult(_0xaea37b,null))[_0x2bbba3('0x13')](handleError(_0xaea37b,null));},exports[_0x13aa54('0xe')]=function(_0x360fc0,_0x3ca26c){const _0x157133=_0x13aa54;let _0x266af5={'where':{'id':_0x360fc0[_0x157133('0x19')]['id']}};const _0x376e5a={};return _0x376e5a['model']=_[_0x157133('0x1f')](db[_0x157133('0x1c')]['rawAttributes']),_0x266af5[_0x157133('0x3c')]=_[_0x157133('0x2b')](_0x376e5a['model'],qs[_0x157133('0x2f')](_0x360fc0['query'][_0x157133('0x2f')])),_0x266af5[_0x157133('0x3c')]=_0x266af5[_0x157133('0x3c')][_0x157133('0x9')]?_0x266af5['attributes']:_0x376e5a[_0x157133('0x11')],_0x360fc0[_0x157133('0x1')][_0x157133('0x35')]&&(_0x266af5[_0x157133('0x3d')]=[{'all':!![]}]),_0x266af5=_[_0x157133('0x43')]({},_0x266af5,_0x360fc0[_0x157133('0x6')]),db['Attachment'][_0x157133('0x2c')](_0x266af5)[_0x157133('0x1a')](handleEntityNotFound(_0x3ca26c,null))[_0x157133('0x1a')](function(_0x232333){const _0x21d14f=_0x157133;if(_0x232333){let _0x126757=_0x232333[_0x21d14f('0xa')]({'plain':!![]});return _0x126757=qs['omit'](_0x126757,['id',_0x21d14f('0x39'),_0x21d14f('0x24')]),_0x360fc0[_0x21d14f('0x12')]=_[_0x21d14f('0x3a')](_0x360fc0[_0x21d14f('0x12')],['id','createdAt','updatedAt']),db[_0x21d14f('0x1c')]['create'](_[_0x21d14f('0x43')](_0x126757,_0x360fc0[_0x21d14f('0x12')]),{'include':_0x360fc0[_0x21d14f('0x1')][_0x21d14f('0x35')]?[{'all':!![]}]:undefined});}})[_0x157133('0x1a')](respondWithResult(_0x3ca26c,0xc9))['catch'](handleError(_0x3ca26c,null));},exports['update']=function(_0x4f2b59,_0x137c77){const _0x17147e=_0x13aa54;return _0x4f2b59[_0x17147e('0x12')]['id']&&delete _0x4f2b59[_0x17147e('0x12')]['id'],db[_0x17147e('0x1c')][_0x17147e('0x2c')]({'where':{'id':_0x4f2b59[_0x17147e('0x19')]['id']}})[_0x17147e('0x1a')](handleEntityNotFound(_0x137c77,null))[_0x17147e('0x1a')](saveUpdates(_0x4f2b59[_0x17147e('0x12')],null))[_0x17147e('0x1a')](respondWithResult(_0x137c77,null))[_0x17147e('0x13')](handleError(_0x137c77,null));},exports[_0x13aa54('0x1e')]=function(_0x21bfce,_0x347a80){const _0x2bab38=_0x13aa54;return db[_0x2bab38('0x1c')][_0x2bab38('0x2c')]({'where':{'id':_0x21bfce[_0x2bab38('0x19')]['id']}})[_0x2bab38('0x1a')](handleEntityNotFound(_0x347a80,null))[_0x2bab38('0x1a')](removeEntity(_0x347a80,null))[_0x2bab38('0x13')](handleError(_0x347a80,null));},exports[_0x13aa54('0x22')]=function(_0x1e3412,_0x42bd6b){const _0x50c012=_0x13aa54;return _0x1e3412[_0x50c012('0x12')][_0x50c012('0x18')]=_0x1e3412[_0x50c012('0x16')][_0x50c012('0x2d')],_0x1e3412['body'][_0x50c012('0x2')]=_0x1e3412['file'][_0x50c012('0x27')],_0x1e3412[_0x50c012('0x12')][_0x50c012('0x4')]=_0x1e3412['file'][_0x50c012('0x3f')],db['Attachment']['create'](_0x1e3412[_0x50c012('0x12')])[_0x50c012('0x1a')](respondWithResult(_0x42bd6b,0xc9))['catch'](handleError(_0x42bd6b,null));},exports[_0x13aa54('0x8')]=function(_0x8fe430,_0x501bf3){const _0x4927fd=_0x13aa54;return db[_0x4927fd('0x1c')]['findOne']({'where':{'id':_0x8fe430[_0x4927fd('0x19')]['id']},'raw':!![]})[_0x4927fd('0x1a')](handleEntityNotFound(_0x501bf3,null))[_0x4927fd('0x1a')](function(_0x847b6d){const _0x21c208=_0x4927fd;if(_0x847b6d)return _0x501bf3[_0x21c208('0x8')](path[_0x21c208('0x7')](config[_0x21c208('0xd')],_0x21c208('0x20'),_0x847b6d['basename']));})[_0x4927fd('0x13')](handleError(_0x501bf3,null));};