Skip to content

Commit

Permalink
hub: move filename resolution to _streamed_log_response
Browse files Browse the repository at this point in the history
... because it is only used by this function and we can't use file_path
on its own to reconstruct the name of the requested log.
  • Loading branch information
lzaoral committed Aug 23, 2023
1 parent ce4fcff commit 610639e
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions kobo/hub/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,11 @@ def _trim_log(text):
return '<...trimmed, download required for full log>' + subtext


def _streamed_log_response(file_path, offset, as_attachment):
def _streamed_log_response(task, log_name, offset, as_attachment):
file_path = task.logs._get_absolute_log_path(log_name)
if not os.path.isfile(file_path) and not file_path.endswith(".gz"):
file_path = task.logs._get_absolute_log_path(log_name + ".gz")

mimetype = mimetypes.guess_type(file_path)[0] or 'application/octet-stream'

try:
Expand Down Expand Up @@ -191,16 +195,12 @@ def task_log(request, id, log_name):

task = get_object_or_404(Task, id=id)

file_path = task.logs._get_absolute_log_path(log_name)
if not os.path.isfile(file_path) and not file_path.endswith(".gz"):
file_path = task.logs._get_absolute_log_path(log_name + ".gz")

offset = int(request.GET.get("offset", 0))

request_format = request.GET.get("format")

if request_format == "raw" or log_name.endswith(".html") or log_name.endswith(".htm"):
return _streamed_log_response(file_path, offset, as_attachment=(request_format == 'raw'))
return _streamed_log_response(task, log_name, offset, as_attachment=(request_format == 'raw'))

return _rendered_log_response(request, task, log_name)

Expand Down

0 comments on commit 610639e

Please sign in to comment.