Skip to content

Commit 07ce1e5

Browse files
authored
fix(toolkit): fix download file (#748)
fix download file
1 parent ca5ab66 commit 07ce1e5

File tree

1 file changed

+9
-7
lines changed
  • src/interfaces/assistants_web/src/components/Markdown/tags

1 file changed

+9
-7
lines changed

src/interfaces/assistants_web/src/components/Markdown/tags/Anchor.tsx

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,21 @@ import { ComponentPropsWithoutRef } from 'react';
66
import { Icon } from '@/components/UI';
77
import { useOutputFiles } from '@/stores';
88

9-
export const Anchor: Component<ComponentPropsWithoutRef<'a'> & ExtraProps> = ({ children }) => {
9+
export const Anchor: Component<ComponentPropsWithoutRef<'a'> & ExtraProps> = ({
10+
children,
11+
node,
12+
}) => {
1013
const { outputFiles } = useOutputFiles();
14+
const nodeHref = node?.properties.href;
15+
16+
if (typeof children === 'string' && typeof nodeHref === 'string') {
17+
const outputFile = Object.entries(outputFiles).find(([key]) => nodeHref.includes(key))?.[1];
1118

12-
if (typeof children === 'string') {
13-
const snakeCaseUrl = children.replace(/\s/g, '_').toLowerCase();
14-
const outputFile = Object.entries(outputFiles).find(([key]) =>
15-
key.startsWith(snakeCaseUrl)
16-
)?.[1];
1719
const downloadUrl = outputFile?.downloadUrl;
1820

1921
if (downloadUrl) {
2022
return (
21-
<a href={downloadUrl} download={snakeCaseUrl} className="flex items-center gap-1">
23+
<a href={downloadUrl} download={outputFile.name} className="flex items-center gap-1">
2224
{children}
2325
<Icon name="download" />
2426
</a>

0 commit comments

Comments
 (0)