From 610639e63b681233471a5c94ecdaa038d4ea272a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Zaoral?= Date: Mon, 31 Jul 2023 17:26:44 +0200 Subject: [PATCH] hub: move filename resolution to _streamed_log_response ... 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. --- kobo/hub/views.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) 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)