mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-24 04:10:15 +01:00
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.
This commit is contained in:
parent
d844754edf
commit
4f7992917b
1 changed files with 5 additions and 4 deletions
|
|
@ -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' };
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue