Spaces:
Sleeping
Sleeping
Update web/src/components/ChatArea.tsx
Browse files
web/src/components/ChatArea.tsx
CHANGED
|
@@ -173,9 +173,36 @@ function FileViewerContent({ file }: { file: File }) {
|
|
| 173 |
}
|
| 174 |
|
| 175 |
if (isPdfFile(file.name)) {
|
|
|
|
|
|
|
|
|
|
|
|
|
| 176 |
return (
|
| 177 |
<div className="w-full h-[70vh] border rounded-lg overflow-hidden">
|
| 178 |
-
<
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 179 |
</div>
|
| 180 |
);
|
| 181 |
}
|
|
|
|
| 173 |
}
|
| 174 |
|
| 175 |
if (isPdfFile(file.name)) {
|
| 176 |
+
// 强制给 pdf MIME,避免 file.type 为空导致 Chrome 拦截
|
| 177 |
+
const pdfBlob = new Blob([file], { type: "application/pdf" });
|
| 178 |
+
const pdfUrl = URL.createObjectURL(pdfBlob);
|
| 179 |
+
|
| 180 |
return (
|
| 181 |
<div className="w-full h-[70vh] border rounded-lg overflow-hidden">
|
| 182 |
+
<object data={pdfUrl} type="application/pdf" className="w-full h-full">
|
| 183 |
+
<div className="p-3 space-y-2">
|
| 184 |
+
<div className="text-sm text-muted-foreground">
|
| 185 |
+
PDF preview is blocked by your browser. Please open it in a new tab or download.
|
| 186 |
+
</div>
|
| 187 |
+
<div className="flex gap-2">
|
| 188 |
+
<a
|
| 189 |
+
href={pdfUrl}
|
| 190 |
+
target="_blank"
|
| 191 |
+
rel="noreferrer"
|
| 192 |
+
className="inline-flex items-center justify-center h-9 px-3 rounded-md border hover:bg-muted"
|
| 193 |
+
>
|
| 194 |
+
Open in new tab
|
| 195 |
+
</a>
|
| 196 |
+
<a
|
| 197 |
+
href={pdfUrl}
|
| 198 |
+
download={file.name}
|
| 199 |
+
className="inline-flex items-center justify-center h-9 px-3 rounded-md border hover:bg-muted"
|
| 200 |
+
>
|
| 201 |
+
Download
|
| 202 |
+
</a>
|
| 203 |
+
</div>
|
| 204 |
+
</div>
|
| 205 |
+
</object>
|
| 206 |
</div>
|
| 207 |
);
|
| 208 |
}
|