12 lines
425 B
TypeScript
12 lines
425 B
TypeScript
import type { AxiosResponse } from "axios";
|
|
|
|
export function parseFilenameFromResponse(response: AxiosResponse): string {
|
|
const contentDisposition = response.headers["content-disposition"];
|
|
if (!contentDisposition) return "download";
|
|
|
|
const filenameMatch = contentDisposition.match(/filename\*=UTF-8''([^;]+)/);
|
|
if (!filenameMatch?.[1]) return "download";
|
|
|
|
return decodeURIComponent(filenameMatch[1]);
|
|
}
|