@@ -185,11 +185,22 @@ def repository(repo: Repository, path=''):
185185 file_display_type = 'other'
186186 file_content = None
187187
188- mime = magic .Magic (mime = True )
189- detected_mime = mime .from_file (target_path )
190- if detected_mime in ['application/pdf' , 'text/xml' , "application/json" , "text/html" ]:
188+ detected_mime = magic .Magic (mime = True ).from_file (target_path )
189+
190+ # always send these as is
191+ if detected_mime in ['application/pdf' , 'text/xml' , 'application/json' , 'text/html' ]:
192+ return send_from_directory (repo_dir , normalized_path )
193+
194+ # if requested mime type matches the file mime type (i.e. image/svg+xml requested), return as is
195+ if detected_mime in request .accept_mimetypes .values ():
191196 return send_from_directory (repo_dir , normalized_path )
192- elif detected_mime .startswith ('text/' ):
197+
198+ # return js and css files as is for displaying html files
199+ # (detected mime type is not text/css, so it does not trigger previos condition)
200+ if normalized_path .endswith ('.js' ) or normalized_path .endswith ('.css' ):
201+ return send_from_directory (repo_dir , normalized_path )
202+
203+ if detected_mime .startswith ('text/' ):
193204 file_display_type = 'text'
194205 with open (target_path , 'r' , encoding = 'utf-8' , errors = 'ignore' ) as file :
195206 file_content = file .read ()
0 commit comments