@@ -33,16 +33,15 @@ module.exports = function() {
3333
3434 global . apiTracker . log ( appId , "File / Save" , req . url , sdk ) ;
3535 } else {
36- _getFileStream ( req ) . then ( function ( result ) {
37-
38- global . keys . fileUrl = global . keys . myURL + "/file/" ;
39-
40- return global . fileService . upload ( appId , result . fileStream , result . contentType , result . fileObj ) ;
41-
42- } ) . then ( function ( file ) {
43- return res . status ( 200 ) . send ( file ) ;
44- } , function ( err ) {
45- return res . status ( 500 ) . send ( err ) ;
36+ global . appService . isMasterKey ( appId , appKey ) . then ( function ( isMasterKey ) {
37+ _getFileStream ( req ) . then ( function ( result ) {
38+ global . keys . fileUrl = global . keys . myURL + "/file/" ;
39+ return global . fileService . upload ( appId , result . fileStream , result . contentType , result . fileObj , customHelper . getAccessList ( req ) , isMasterKey ) ;
40+ } ) . then ( function ( file ) {
41+ return res . status ( 200 ) . send ( file ) ;
42+ } , function ( err ) {
43+ return res . status ( 500 ) . send ( err ) ;
44+ } ) ;
4645 } ) ;
4746
4847 global . apiTracker . log ( appId , "File / Upload" , req . url , sdk ) ;
@@ -59,16 +58,18 @@ module.exports = function() {
5958
6059 var appId = req . params . appId ;
6160 var fileObj = req . body . fileObj ;
61+ var appKey = req . body . key ;
6262 var sdk = req . body . sdk || "REST" ;
6363 global . keys . fileUrl = global . keys . myURL + "/file/" ;
64-
65- global . fileService . delete ( appId , fileObj , customHelper . getAccessList ( req ) ) . then ( function ( file ) {
66- console . log ( "File successfully deleted." ) ;
67- return res . status ( 200 ) . send ( null ) ;
68- } , function ( err ) {
69- console . log ( "Error deletig file." ) ;
70- console . log ( err ) ;
71- return res . status ( 500 ) . send ( err ) ;
64+ global . appService . isMasterKey ( appId , appKey ) . then ( function ( isMasterKey ) {
65+ global . fileService . delete ( appId , fileObj , customHelper . getAccessList ( req ) , isMasterKey ) . then ( function ( file ) {
66+ console . log ( "File successfully deleted." ) ;
67+ return res . status ( 200 ) . send ( null ) ;
68+ } , function ( err ) {
69+ console . log ( "Error deletig file." ) ;
70+ console . log ( err ) ;
71+ return res . status ( 500 ) . send ( err ) ;
72+ } ) ;
7273 } ) ;
7374
7475 global . apiTracker . log ( appId , "File / Delete" , req . url , sdk ) ;
@@ -83,8 +84,8 @@ function _getFile(req, res) {
8384
8485 console . log ( '+++++++++ In get File Service API ++++++++' ) ;
8586 var appId = req . params . appId ;
86-
8787 var fileId = req . params . fileId ;
88+ var appKey = req . body . key ;
8889 var sdk = req . body . sdk || "REST" ;
8990 var resizeWidth = req . query . resizeWidth ;
9091 var resizeHeight = req . query . resizeHeight ;
@@ -103,39 +104,42 @@ function _getFile(req, res) {
103104 if ( ! fileId ) {
104105 return res . status ( 400 ) . send ( "File ID is Required" ) ;
105106 }
107+ global . appService . isMasterKey ( appId , appKey ) . then ( function ( isMasterKey ) {
108+ global . fileService . getFile ( appId , fileId , customHelper . getAccessList ( req ) , isMasterKey ) . then ( function ( file ) {
106109
107- global . fileService . getFile ( appId , fileId , customHelper . getAccessList ( req ) ) . then ( function ( file ) {
110+ if ( typeof resizeWidth === 'undefined' && typeof resizeHeight === 'undefined' && typeof quality === 'undefined' && typeof opacity === 'undefined' && typeof scale === 'undefined' && typeof containWidth === 'undefined' && typeof containHeight === 'undefined' && typeof rDegs === 'undefined' && typeof bSigma === 'undefined' ) {
108111
109- if ( typeof resizeWidth === 'undefined' && typeof resizeHeight === 'undefined' && typeof quality === 'undefined' && typeof opacity === 'undefined' && typeof scale === 'undefined' && typeof containWidth === 'undefined' && typeof containHeight === 'undefined' && typeof rDegs === 'undefined' && typeof bSigma === 'undefined' && typeof cropX === 'undefined' && typeof cropY === 'undefined' && typeof cropW && typeof cropH === 'undefined' ) {
112+ var fileStream = global . mongoService . document . getFileStreamById ( appId , file . _id ) ;
110113
111- var fileStream = global . mongoService . document . getFileStreamById ( appId , file . _id ) ;
114+ res . set ( 'Content-Type' , file . contentType ) ;
115+ res . set ( 'Content-Disposition' , 'inline; filename="' + file . filename + '"' ) ;
112116
113- res . set ( 'Content-Type' , file . contentType ) ;
114- res . set ( 'Content-Disposition' , 'inline; filename="' + file . filename + '"' ) ;
117+ fileStream . on ( "error" , function ( err ) {
118+ res . send ( 500 , "Got error while processing stream " + err . message ) ;
119+ res . end ( ) ;
120+ } ) ;
115121
116- fileStream . on ( "error" , function ( err ) {
117- res . send ( 500 , "Got error while processing stream " + err . message ) ;
118- res . end ( ) ;
119- } ) ;
122+ fileStream . on ( 'end' , function ( ) {
123+ res . end ( ) ;
124+ } ) ;
120125
121- fileStream . on ( 'end' , function ( ) {
122- res . end ( ) ;
123- } ) ;
126+ fileStream . pipe ( res ) ;
124127
125- fileStream . pipe ( res ) ;
126-
127- } else {
128- console . log ( '+++++ Proccesing Image ++++++++' ) ;
129- global . fileService . processImage ( appId , file , resizeWidth , resizeHeight , cropX , cropY , cropW , cropH , quality , opacity , scale , containWidth , containHeight , rDegs , bSigma ) . then ( function ( file ) {
130- return res . status ( 200 ) . send ( file ) ;
131- } , function ( err ) {
132- return res . status ( 500 ) . send ( err ) ;
133- } ) ;
134- }
128+ } else {
129+ console . log ( '+++++ Proccesing Image ++++++++' ) ;
130+ global . fileService . processImage ( appId , file , resizeWidth , resizeHeight , cropX , cropY , cropW , cropH , quality , opacity , scale , containWidth , containHeight , rDegs , bSigma ) . then ( function ( file ) {
131+ return res . status ( 200 ) . send ( file ) ;
132+ } , function ( err ) {
133+ return res . status ( 500 ) . send ( err ) ;
134+ } ) ;
135+ }
135136
137+ } , function ( err ) {
138+ return res . status ( 500 ) . send ( err ) ;
139+ } ) ;
136140 } , function ( err ) {
137141 return res . status ( 500 ) . send ( err ) ;
138- } ) ;
142+ } )
139143
140144 global . apiTracker . log ( appId , "File / Get" , req . url , sdk ) ;
141145}
0 commit comments