From 9797935c73cf85c4fb9a29c67c429965c14456d2 Mon Sep 17 00:00:00 2001 From: -LAN- Date: Thu, 17 Oct 2024 17:37:33 +0800 Subject: [PATCH] feat(file-download): add inline or attachment option for file previews - Introduced 'as_attachment' argument to specify download mode. - Enables flexible file display as inline or attachment. - Enhances user control over file preview behavior. --- api/controllers/files/tool_files.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/api/controllers/files/tool_files.py b/api/controllers/files/tool_files.py index c36e226a69..fb457663ee 100644 --- a/api/controllers/files/tool_files.py +++ b/api/controllers/files/tool_files.py @@ -16,6 +16,7 @@ class ToolFilePreviewApi(Resource): parser.add_argument("timestamp", type=str, required=True, location="args") parser.add_argument("nonce", type=str, required=True, location="args") parser.add_argument("sign", type=str, required=True, location="args") + parser.add_argument("as_attachment", type=bool, defaule=False, required=False, location="args") args = parser.parse_args() @@ -43,10 +44,11 @@ class ToolFilePreviewApi(Resource): direct_passthrough=True, headers={ "Content-Length": str(tool_file.size), - "Content-Disposition": f"attachment; filename={tool_file.name}", }, ) - if tool_file.mimetype.startswith("image"): + if args["as_attachment"]: + response.headers["Content-Disposition"] = f"attachment; filename={tool_file.name}" + else: response.headers["Content-Disposition"] = f"inline; filename={tool_file.name}" return response