11import  os 
22
3- from  tornado .web  import  authenticated , HTTPError , RequestHandler 
4- from  tornado  import  iostream 
3+ from  tornado .web  import  HTTPError , RequestHandler 
54from  tornado .gen  import  coroutine 
65
76from  qiita_core .util  import  execute_as_transaction 
8- from  qiita_pet .handlers .download  import  BaseHandlerDownload 
9- from  qiita_db .handlers .oauth2  import  OauthBaseHandler , authenticate_oauth 
7+ from  qiita_db .handlers .oauth2  import  authenticate_oauth 
108from  qiita_core .qiita_settings  import  qiita_config 
119
10+ 
1211class  FetchFileFromCentralHandler (RequestHandler ):
1312    @authenticate_oauth  
1413    @coroutine  
@@ -22,8 +21,8 @@ def get(self, requested_filepath):
2221        # canonic version of base_data_dir 
2322        basedatadir  =  os .path .abspath (qiita_config .base_data_dir )
2423
25-         # TODO: can we somehow check, if the requesting client (which should be   
26-         #       one of the plugins) was started from a user that actually has   
24+         # TODO: can we somehow check, if the requesting client (which should be 
25+         #       one of the plugins) was started from a user that actually has 
2726        #       access to the requested file? 
2827
2928        if  not  filepath .startswith (basedatadir ):
@@ -38,11 +37,11 @@ def get(self, requested_filepath):
3837            raise  HTTPError (403 , reason = (
3938                "The requested file is not present in Qiita's BASE_DATA_DIR!" ))
4039
41-         # delivery of the file via nginx requires replacing the basedatadir   
42-         # with the prefix defined in the nginx configuration for the   
40+         # delivery of the file via nginx requires replacing the basedatadir 
41+         # with the prefix defined in the nginx configuration for the 
4342        # base_data_dir, '/protected/' by default 
4443        protected_filepath  =  filepath .replace (basedatadir , '/protected' )
45-          
44+ 
4645        self .set_header ('Content-Type' , 'application/octet-stream' )
4746        self .set_header ('Content-Transfer-Encoding' , 'binary' )
4847        self .set_header ('X-Accel-Redirect' , protected_filepath )
@@ -54,6 +53,7 @@ def get(self, requested_filepath):
5453                            protected_filepath ))
5554        self .finish ()
5655
56+ 
5757class  PushFileToCentralHandler (RequestHandler ):
5858    @authenticate_oauth  
5959    @coroutine  
@@ -74,7 +74,7 @@ def post(self):
7474                filepath  =  os .path .join (filespath , file ['filename' ])
7575                # remove leading / 
7676                if  filepath .startswith (os .sep ):
77-                     filepath  =  filepath [len (os .sep ):]  
77+                     filepath  =  filepath [len (os .sep ):]
7878                filepath  =  os .path .abspath (os .path .join (basedatadir , filepath ))
7979
8080                if  os .path .exists (filepath ):
@@ -88,7 +88,7 @@ def post(self):
8888                    stored_files .append (filepath )
8989
9090        self .write ("Stored %i files into BASE_DATA_DIR of Qiita:\n %s\n "  %  (
91-             len (stored_files ),  
91+             len (stored_files ),
9292            '\n ' .join (map (lambda  x : ' - %s'  %  x , stored_files ))))
9393
9494        self .finish ()
0 commit comments