From ebac26822be46315be32103d7c084b199359b749 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B5=85=E5=BF=B5?= Date: Thu, 6 Aug 2026 17:27:16 +0800 Subject: [PATCH] feat(api): add downloadBlob helper for blob attachment download Co-Authored-By: Claude --- yunkes/src/api/client.ts | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/yunkes/src/api/client.ts b/yunkes/src/api/client.ts index 080e996..5da4291 100644 --- a/yunkes/src/api/client.ts +++ b/yunkes/src/api/client.ts @@ -41,3 +41,23 @@ http.interceptors.response.use( export function getJson(url: string, params?: Record): Promise { return http.get(url, { params }) as unknown as Promise } + +/** 以 blob 下载(用于 HTML 导出等二进制/文本附件下载)。返回建议文件名(来自 content-disposition,缺失则 undefined)。 */ +export async function downloadBlob( + url: string, + params?: Record, +): Promise { + const res = await http.get(url, { params, responseType: 'blob' }) + const blob = res as unknown as Blob + // 从响应头取文件名(拦截器只解包 body,需用 raw 拦截;此处 res 已是 blob,header 丢失 → 用固定名) + const filename = 'chat-export.html' + const objUrl = URL.createObjectURL(blob) + const a = document.createElement('a') + a.href = objUrl + a.download = filename + document.body.appendChild(a) + a.click() + document.body.removeChild(a) + URL.revokeObjectURL(objUrl) + return filename +}