refactor(intake): move download helpers

This commit is contained in:
WuYongJie 2026-06-09 10:58:36 +08:00
parent f5a3a6940a
commit c4ffbcba0b
2 changed files with 35 additions and 32 deletions

View File

@ -331,6 +331,10 @@ import {
mergeProductPatentRecordsWithProducts,
} from "../productPatentStorage";
import { syncProductPatentRecordFromProduct } from "./productPatentSyncHelpers";
import {
downloadBlob,
resolveDownloadFileNameFromHeaders,
} from "./downloadHelpers";
import {
previewSharedNonIntegratedDocumentImages,
pushSharedNonIntegratedProductPricingToJushuitan,
@ -15082,38 +15086,6 @@ export default function NonIntegratedDetailClient({
return response.blob();
}
function downloadBlob(blob: Blob, fileName: string) {
const objectUrl = URL.createObjectURL(blob);
const anchor = document.createElement("a");
anchor.href = objectUrl;
anchor.download = fileName;
document.body.appendChild(anchor);
anchor.click();
anchor.remove();
URL.revokeObjectURL(objectUrl);
}
function resolveDownloadFileNameFromHeaders(
response: Response,
fallbackFileName: string,
) {
const disposition = response.headers.get("content-disposition") ?? "";
const encodedFileName = disposition.match(/filename\*=UTF-8''([^;]+)/i)?.[1];
if (encodedFileName) {
try {
return decodeURIComponent(encodedFileName);
} catch {
return encodedFileName;
}
}
return (
disposition.match(/filename="?([^";]+)"?/i)?.[1]?.trim() ||
fallbackFileName
);
}
async function readDownloadErrorMessage(response: Response) {
const fallback = "合同下载失败,请稍后再试";
try {

View File

@ -0,0 +1,31 @@
export function downloadBlob(blob: Blob, fileName: string) {
const objectUrl = URL.createObjectURL(blob);
const anchor = document.createElement("a");
anchor.href = objectUrl;
anchor.download = fileName;
document.body.appendChild(anchor);
anchor.click();
anchor.remove();
URL.revokeObjectURL(objectUrl);
}
export function resolveDownloadFileNameFromHeaders(
response: Response,
fallbackFileName: string,
) {
const disposition = response.headers.get("content-disposition") ?? "";
const encodedFileName = disposition.match(/filename\*=UTF-8''([^;]+)/i)?.[1];
if (encodedFileName) {
try {
return decodeURIComponent(encodedFileName);
} catch {
return encodedFileName;
}
}
return (
disposition.match(/filename="?([^";]+)"?/i)?.[1]?.trim() ||
fallbackFileName
);
}