From f8cf3304df8d287f02a5ae7e08c3d1593c4d5d68 Mon Sep 17 00:00:00 2001 From: -LAN- Date: Wed, 16 Oct 2024 19:27:50 +0800 Subject: [PATCH 1/2] fix(file-serving): adjust content disposition header for images - Set content disposition to 'inline' for image files to allow direct viewing in browsers. - Maintain 'attachment' disposition for other file types to prompt download. --- api/controllers/files/tool_files.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/api/controllers/files/tool_files.py b/api/controllers/files/tool_files.py index 1f03682e40..c36e226a69 100644 --- a/api/controllers/files/tool_files.py +++ b/api/controllers/files/tool_files.py @@ -37,14 +37,19 @@ class ToolFilePreviewApi(Resource): except Exception: raise UnsupportedFileTypeError() - return Response( + response = Response( stream, mimetype=tool_file.mimetype, direct_passthrough=True, headers={ "Content-Length": str(tool_file.size), + "Content-Disposition": f"attachment; filename={tool_file.name}", }, ) + if tool_file.mimetype.startswith("image"): + response.headers["Content-Disposition"] = f"inline; filename={tool_file.name}" + + return response api.add_resource(ToolFilePreviewApi, "/files/tools/.") From 8d424c82225c9f872eee4153df68ee6f0aefd6fa Mon Sep 17 00:00:00 2001 From: -LAN- Date: Wed, 16 Oct 2024 19:28:04 +0800 Subject: [PATCH 2/2] refactor(tool_node): simplify tool_file_id assignment - Remove redundant condition by directly assigning tool_file_id. - Assume URL structure provides necessary file identifier. --- api/core/workflow/nodes/tool/tool_node.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/core/workflow/nodes/tool/tool_node.py b/api/core/workflow/nodes/tool/tool_node.py index 82ba34a7fc..696f661a2a 100644 --- a/api/core/workflow/nodes/tool/tool_node.py +++ b/api/core/workflow/nodes/tool/tool_node.py @@ -174,7 +174,7 @@ class ToolNode(BaseNode[ToolNodeData]): if response.type in {ToolInvokeMessage.MessageType.IMAGE_LINK, ToolInvokeMessage.MessageType.IMAGE}: url = str(response.message) if response.message else None ext = path.splitext(url)[1] if url else ".bin" - tool_file_id = response.save_as or str(url).split("/")[-1].split(".")[0] + tool_file_id = str(url).split("/")[-1].split(".")[0] transfer_method = response.meta.get("transfer_method", FileTransferMethod.TOOL_FILE) with Session(db.engine) as session: