mirror of
https://github.com/HKUDS/DeepTutor.git
synced 2026-12-02 01:19:31 +08:00
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>
18 lines
541 B
TypeScript
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;
|
|
}
|