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
@@ -6,6 +6,19 @@ import { getApiKey, getBaseUrlValue } from '../client'
*/
export function getDownloadUrl(filePath: string, fileName?: string): string {
const base = getBaseUrlValue()
// Guard: if filePath is already a full download URL, extract the real path
// to prevent double-wrapping (/api/hermes/download?path=/api/hermes/download?path=...)
if (filePath.startsWith('/api/hermes/download?')) {
try {
const parsed = new URL(filePath, 'http://localhost')
const realPath = parsed.searchParams.get('path')
if (realPath) filePath = realPath
} catch {
// fall through with original filePath
}
}
// Decode the path first in case it's already encoded (e.g., from AI responses)
// URLSearchParams will encode it again, so we need to start with decoded text
const decodedPath = decodeURIComponent(filePath)