Skip to content

Commit a0edca3

Browse files
committed
fix displaying html with css/js
1 parent c4a41ac commit a0edca3

File tree

2 files changed

+19
-8
lines changed

2 files changed

+19
-8
lines changed

src/app.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -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()

src/repository.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -238,14 +238,14 @@ def get_current_build_status(self):
238238

239239
last_record = records[0]
240240

241-
if "Build failed." in last_record[1]:
241+
if len(last_record) > 1 and "Build failed." in last_record[1]:
242242
status = "failed"
243243
for record in records:
244-
if "Build succeeded." in record[1]:
244+
if len(record) > 1 and "Build succeeded." in record[1]:
245245
break
246-
if "Build failed." in record[1]:
246+
else:
247247
last_record = record
248-
elif "Build succeeded." in last_record[1]:
248+
elif len(last_record) > 1 and "Build succeeded." in last_record[1]:
249249
status = "succeeded"
250250
else:
251251
status = "unknown"

0 commit comments

Comments
 (0)