Files
DeepTutor/web/lib/content-disposition.ts
Qiu 506cea9d4f feat(desktop): finish Windows chat file actions (#3051)
Continues #2978 and closes #2887. Includes the original Windows file actions, integrates the changes with dev, and adds an explicit default-app action.

Co-authored-by: Botong Wu <2048400180@qq.com>
2026-11-28 13:09:15 -03:00

18 lines
541 B
TypeScript

/** Read the RFC 5987 filename first to preserve non-ASCII names. */
export function filenameFromDisposition(
header: string | null,
fallback = "export",
): string {
if (!header) return fallback;
const encoded = /filename\*=UTF-8''([^;]+)/i.exec(header);
if (encoded?.[1]) {
try {
return decodeURIComponent(encoded[1].trim());
} catch {
// Malformed percent-encoding — fall through to the plain form.
}
}
const plain = /filename="?([^";]+)"?/i.exec(header);
return plain?.[1]?.trim() || fallback;
}