From 915c5f0a86cf45c62bc577cbcbc1d319ee03637c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E5=AE=B6=E5=90=8D?= Date: Sat, 30 May 2026 09:49:20 +0800 Subject: [PATCH] fix: infer json extension for downloads --- shortcuts/common/download_path.go | 27 +++++++++++++------------- shortcuts/common/download_path_test.go | 8 ++++++++ 2 files changed, 22 insertions(+), 13 deletions(-) diff --git a/shortcuts/common/download_path.go b/shortcuts/common/download_path.go index 24059f8d0..8a1f26af7 100644 --- a/shortcuts/common/download_path.go +++ b/shortcuts/common/download_path.go @@ -28,19 +28,20 @@ var downloadMimeToExt = map[string]string{ "application/vnd.openxmlformats-officedocument.presentationml.presentation": ".pptx", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet": ".xlsx", "application/vnd.openxmlformats-officedocument.wordprocessingml.document": ".docx", - "application/xml": ".xml", - "application/zip": ".zip", - "image/bmp": ".bmp", - "image/gif": ".gif", - "image/jpeg": ".jpg", - "image/png": ".png", - "image/svg+xml": ".svg", - "image/webp": ".webp", - "text/csv": ".csv", - "text/html": ".html", - "text/plain": ".txt", - "text/xml": ".xml", - "video/mp4": ".mp4", + "application/json": ".json", + "application/xml": ".xml", + "application/zip": ".zip", + "image/bmp": ".bmp", + "image/gif": ".gif", + "image/jpeg": ".jpg", + "image/png": ".png", + "image/svg+xml": ".svg", + "image/webp": ".webp", + "text/csv": ".csv", + "text/html": ".html", + "text/plain": ".txt", + "text/xml": ".xml", + "video/mp4": ".mp4", } // ResolveDownloadFileName returns a sanitized filename from Content-Disposition, diff --git a/shortcuts/common/download_path_test.go b/shortcuts/common/download_path_test.go index 100eb9ccd..644678256 100644 --- a/shortcuts/common/download_path_test.go +++ b/shortcuts/common/download_path_test.go @@ -76,6 +76,14 @@ func TestAutoAppendDownloadExtension(t *testing.T) { }, want: "artifact.csv", }, + { + name: "appends json extension from content type", + path: "artifact", + header: http.Header{ + "Content-Type": []string{"application/json; charset=utf-8"}, + }, + want: "artifact.json", + }, { name: "appends extension from content disposition when content type is generic", path: "artifact",