Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 16 additions & 10 deletions src/components/chat/messages/MessageFile.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import React from 'react';
import { Button } from '@evoapi/design-system/button';
import { Download, FileText, File, Image, Music, Video } from 'lucide-react';
import { toast } from 'sonner';
import { Attachment } from '@/types/chat/api';
import { useLanguage } from '@/hooks/useLanguage';
import { openAttachmentInNewTab } from '@/components/chat/messages/utils/openAttachmentInNewTab';
Expand All @@ -13,16 +12,23 @@ interface MessageFileProps {
const MessageFile: React.FC<MessageFileProps> = ({ attachments }) => {
const { t } = useLanguage('chat');

const downloadFile = (attachment: Attachment) => {
const result = openAttachmentInNewTab({
url: attachment.data_url,
filename: attachment.fallback_title || t('messages.messageFile.fileFallback'),
});
const downloadFile = async (attachment: Attachment) => {
const url = attachment.data_url?.trim();
if (!url) return;

if (result === 'download-fallback') {
toast.info(t('messages.messageImage.downloadStarted'), {
description: attachment.fallback_title || t('messages.messageFile.fileFallbackTitle'),
});
const filename = attachment.fallback_title || t('messages.messageFile.fileFallback');

try {
const response = await fetch(url, { mode: 'cors' });
const blob = await response.blob();
const blobUrl = URL.createObjectURL(blob);
const link = document.createElement('a');
link.href = blobUrl;
link.download = filename;
link.click();
URL.revokeObjectURL(blobUrl);
} catch {
openAttachmentInNewTab({ url, filename });
Comment on lines +30 to +31
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question: Consider whether to restore user feedback for the download fallback path.

Previously, when openAttachmentInNewTab fell back to a download flow, we showed a downloadStarted toast. With this change, that feedback is lost if the direct fetch fails and we call openAttachmentInNewTab. If you want to preserve that behavior, consider either propagating a signal from openAttachmentInNewTab or showing a generic info toast in this catch branch.

}
};

Expand Down