diff --git a/app/src/components/common/AttachmentPreview.tsx b/app/src/components/common/AttachmentPreview.tsx index d4a171b..e45d5c3 100644 --- a/app/src/components/common/AttachmentPreview.tsx +++ b/app/src/components/common/AttachmentPreview.tsx @@ -2,6 +2,7 @@ import { useEffect, useState } from 'react'; import { Download, Loader2 } from 'lucide-react'; import { Button, Dialog, useToast } from '@/components/ui'; import { readFull } from '@/lib/att-cache'; +import { attachmentDownload } from '@/lib/api'; import type { Attachment } from '@/lib/types'; export type AttKind = 'image' | 'pdf' | 'text' | 'audio' | 'video' | 'docx' | 'xlsx' | 'other'; @@ -23,14 +24,6 @@ function b64ToUint8(dataB64: string): Uint8Array { return Uint8Array.from(atob(dataB64), c => c.charCodeAt(0)) as Uint8Array; } -function forceDownload(fileName: string, mime: string | undefined | null, dataB64: string) { - const url = URL.createObjectURL(new Blob([b64ToUint8(dataB64)], { type: mime || 'application/octet-stream' })); - const a = document.createElement('a'); - a.href = url; - a.download = fileName; - a.click(); - setTimeout(() => URL.revokeObjectURL(url), 60_000); -} const KIND_LABEL: Record = { image: '图片', pdf: 'PDF 文档', text: '文本文件', audio: '音频', video: '视频', @@ -109,22 +102,17 @@ export function AttachmentPreview({ att, onClose }: { att: Attachment | null; on footer={att ? ( <>