From 4f7992917be1937488cfae3fd9eeb6acec2b3d07 Mon Sep 17 00:00:00 2001 From: Bastian Seipp Date: Thu, 13 Nov 2025 23:55:58 +0100 Subject: [PATCH] fix: correct file_id extraction in markdown file download links The markdown link handler was incorrectly extracting file_id and filename from URLs in the format files/{userId}/{file_id}. The .pop() method was applied twice in reverse order, causing the userId to be assigned to the file_id variable and the actual file_id to be used as filename. This caused downloads to fail with 404 errors as the API was called with /api/files/download/{userId}/{userId} instead of the correct /api/files/download/{userId}/{file_id}. Fixed by directly accessing parts[2] to get the file_id and using the link text (children) as the filename. Also added children to the useMemo dependency array to properly track changes. --- .../Chat/Messages/Content/MarkdownComponents.tsx | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/client/src/components/Chat/Messages/Content/MarkdownComponents.tsx b/client/src/components/Chat/Messages/Content/MarkdownComponents.tsx index ed69c677b2..5d08c980d0 100644 --- a/client/src/components/Chat/Messages/Content/MarkdownComponents.tsx +++ b/client/src/components/Chat/Messages/Content/MarkdownComponents.tsx @@ -90,12 +90,13 @@ export const a: React.ElementType = memo(({ href, children }: TAnchorProps) => { if (match && match[0]) { const path = match[0]; const parts = path.split('/'); - const name = parts.pop(); - const file_id = parts.pop(); - return { file_id, filename: name, filepath: path }; + // parts = ['files', userId, file_id] or ['outputs', userId, file_id] + const file_id = parts[2]; // Get the file_id (third element) + const filename = typeof children === 'string' ? children : file_id; // Use link text as filename + return { file_id, filename, filepath: path }; } return { file_id: '', filename: '', filepath: '' }; - }, [user?.id, href]); + }, [user?.id, href, children]); const { refetch: downloadFile } = useFileDownload(user?.id ?? '', file_id); const props: { target?: string; onClick?: React.MouseEventHandler } = { target: '_new' };