Files
ctms/frontend/src/utils/contentDisposition.ts
T
chengchengzhou7 4863ade45b
Client Quality Gates / Shared client and Web (push) Has been cancelled
Client Quality Gates / macOS Desktop (push) Has been cancelled
build(release): 加固 v0.1.0 桌面发布链路 (#3)
2026-07-17 09:36:16 +08:00

21 lines
773 B
TypeScript

export const getHttpHeaderString = (value: unknown): string | undefined => {
if (typeof value === "string") return value;
if (Array.isArray(value) && value.every((item) => typeof item === "string")) {
return value.join(", ");
}
return undefined;
};
export const getContentDispositionFilename = (header?: string | null): string | null => {
if (!header) return null;
const encoded = /filename\*\s*=\s*UTF-8''([^;]+)/i.exec(header)?.[1];
if (encoded) {
try {
return decodeURIComponent(encoded.trim().replace(/^"|"$/g, ""));
} catch {
// Fall through to the ASCII filename when the RFC 5987 value is malformed.
}
}
return /filename\s*=\s*"([^"]+)"|filename\s*=\s*([^;]+)/i.exec(header)?.slice(1).find(Boolean)?.trim() || null;
};