mirror of
https://github.com/saltbo/zpan.git
synced 2026-09-17 16:39:27 +08:00
* refactor(storage): remove custom host downloads * test(download): cover private signed URLs end to end
10 lines
537 B
TypeScript
10 lines
537 B
TypeScript
// Builds an RFC 6266 `Content-Disposition` for forced downloads.
|
|
//
|
|
// The plain `filename=` parameter stays ASCII for broad user-agent compatibility.
|
|
// Non-ASCII names (Chinese, emoji, …) are carried losslessly by the percent-encoded
|
|
// `filename*=UTF-8''` form, which every modern browser prefers.
|
|
export function attachmentContentDisposition(name: string): string {
|
|
const asciiFallback = name.replace(/[^\x20-\x7e]|["\\]/g, '_')
|
|
return `attachment; filename="${asciiFallback}"; filename*=UTF-8''${encodeURIComponent(name)}`
|
|
}
|