fix: prevent double-wrapping of download URLs in MarkdownRenderer (#529)

Co-authored-by: Hango Liang <Hango>
Co-authored-by: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
hangox
2026-05-08 19:55:33 +08:00
committed by GitHub
parent 4859c32045
commit 866ae3d23d
2 changed files with 29 additions and 0 deletions
@@ -305,6 +305,22 @@ async function handleMarkdownClick(event: MouseEvent): Promise<void> {
return
}
// Full download URL: open directly (already has /api/hermes/download?path=...)
if (href.startsWith('/api/hermes/download?')) {
event.preventDefault()
event.stopPropagation()
const linkText = link.textContent || ''
const fileName = linkText.startsWith('File: ') ? linkText.slice(6).trim() : linkText.trim()
message.info(t('download.downloading'))
// Parse the real file path from the existing query param
const url = new URL(href, window.location.origin)
const realPath = url.searchParams.get('path') || href
downloadFile(realPath, fileName || undefined).catch((err: Error) => {
message.error(err.message || t('download.downloadFailed'))
})
return
}
// File path links: intercept and download
if (href.startsWith('/')) {
event.preventDefault()