MCPcopy
hub / github.com/1Panel-dev/MaxKB / extractFilename

Function extractFilename

ui/src/request/index.ts:255–283  ·  view source on GitHub ↗
(contentDisposition: string)

Source from the content-addressed store, hash-verified

253}
254
255function 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
285export const exportFile: (
286 fileName: string,

Callers 2

exportFileFunction · 0.85
exportFilePostFunction · 0.85

Calls 2

replaceMethod · 0.80
errorMethod · 0.45

Tested by

no test coverage detected