(res, data)
| 416 | * @returns |
| 417 | */ |
| 418 | const getFilename = async (res, data) => { |
| 419 | const contentDisposition = res.headers.get('content-disposition') |
| 420 | |
| 421 | if (contentDisposition) { |
| 422 | const matches = contentDisposition.match(/filename="(.+)"/) |
| 423 | if (matches?.[1]) { |
| 424 | return matches[1] |
| 425 | } |
| 426 | } |
| 427 | |
| 428 | let filename = filenameFromPath(res) |
| 429 | if (!path.extname(filename)) { |
| 430 | const ext = getExtFromMime(res) |
| 431 | if (ext) { |
| 432 | filename = `${filename}.${ext}` |
| 433 | } |
| 434 | } |
| 435 | |
| 436 | return filename |
| 437 | } |
| 438 | |
| 439 | /** |
| 440 | * Main function to download and optionally save the file |
no test coverage detected
searching dependent graphs…