(contentDisposition: string)
| 253 | } |
| 254 | |
| 255 | function extractFilename(contentDisposition: string) { |
| 256 | if (!contentDisposition) return null |
| 257 | |
| 258 | // 处理 URL 编码的文件名 |
| 259 | const urlEncodedMatch = |
| 260 | contentDisposition.match(/filename=([^;]*)/i) || |
| 261 | contentDisposition.match(/filename\*=UTF-8''([^;]*)/i) |
| 262 | if (urlEncodedMatch && urlEncodedMatch[1]) { |
| 263 | try { |
| 264 | return decodeURIComponent(urlEncodedMatch[1].replace(/"/g, '')) |
| 265 | } catch (e) { |
| 266 | console.error('解码URL编码文件名失败:', e) |
| 267 | } |
| 268 | } |
| 269 | |
| 270 | // 处理 Base64 编码的文件名 |
| 271 | const base64Part = contentDisposition.match(/=\?utf-8\?b\?(.*?)\?=/i)?.[1] |
| 272 | if (base64Part) { |
| 273 | try { |
| 274 | const decoded = decodeURIComponent(escape(atob(base64Part))) |
| 275 | const filenameMatch = decoded.match(/filename="(.*?)"/i) |
| 276 | return filenameMatch ? filenameMatch[1] : null |
| 277 | } catch (e) { |
| 278 | console.error('解码Base64文件名失败:', e) |
| 279 | } |
| 280 | } |
| 281 | |
| 282 | return null |
| 283 | } |
| 284 | |
| 285 | export const exportFile: ( |
| 286 | fileName: string, |
no test coverage detected