diff --git a/kobo/hub/views.py b/kobo/hub/views.py index 69a79998..d109f00e 100644 --- a/kobo/hub/views.py +++ b/kobo/hub/views.py @@ -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: @@ -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)