feat: add inline PDF viewer for Custom_PDF objects
Add a /pdf proxy route that forces Content-Disposition inline so PDFs render instead of downloading, and a web viewer that embeds the document in an iframe with a standalone open-in-new-tab link.
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
import type { TTSObject } from '@tts/shared';
|
||||
import { pdfUrl } from '@tts/http';
|
||||
|
||||
/**
|
||||
* A PDF document (`Custom_PDF`). Renders the document inline in an iframe and
|
||||
* offers a standalone link to open it in a new tab. The URL is routed through
|
||||
* the proxy `/pdf` endpoint, which forces `Content-Disposition: inline` so the
|
||||
* browser displays the PDF instead of downloading it.
|
||||
*/
|
||||
export default function PdfViewer({ object }: { object: TTSObject }) {
|
||||
const url = object.CustomPDF?.PDFUrl;
|
||||
|
||||
if (!url) {
|
||||
return (
|
||||
<p className="text-sm text-zinc-500">
|
||||
This object has no PDF URL.
|
||||
</p>
|
||||
);
|
||||
}
|
||||
|
||||
const proxied = pdfUrl(url);
|
||||
|
||||
return (
|
||||
<div className="space-y-3">
|
||||
<div className="flex items-center justify-between gap-2">
|
||||
<p className="truncate font-mono text-xs text-zinc-500">{url}</p>
|
||||
<a
|
||||
href={proxied}
|
||||
target="_blank"
|
||||
rel="noreferrer"
|
||||
className="shrink-0 rounded-lg bg-zinc-100 px-3 py-1.5 text-sm font-medium text-zinc-900 hover:bg-zinc-300"
|
||||
>
|
||||
Open PDF in new tab
|
||||
</a>
|
||||
</div>
|
||||
<iframe
|
||||
src={proxied}
|
||||
title="PDF preview"
|
||||
className="h-[70vh] w-full rounded-lg border border-zinc-800 bg-zinc-950"
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -9,6 +9,7 @@ const TileViewer = lazy(() => import('./TileViewer'));
|
||||
const TokenViewer = lazy(() => import('./TokenViewer'));
|
||||
const CardViewer = lazy(() => import('./CardViewer'));
|
||||
const CustomModelViewer = lazy(() => import('./CustomModelViewer'));
|
||||
const PdfViewer = lazy(() => import('./PdfViewer'));
|
||||
|
||||
registerViewer('Tile', TileViewer);
|
||||
registerViewer('Custom_Tile', TileViewer);
|
||||
@@ -20,4 +21,5 @@ registerViewer('DeckCustom', CardViewer);
|
||||
registerViewer('Custom_Deck', CardViewer);
|
||||
registerViewer('Custom_Model', CustomModelViewer);
|
||||
registerViewer('Custom_Model_Bag', CustomModelViewer);
|
||||
registerViewer('Custom_Model_Infinite_Bag', CustomModelViewer);
|
||||
registerViewer('Custom_Model_Infinite_Bag', CustomModelViewer);
|
||||
registerViewer('Custom_PDF', PdfViewer);
|
||||
Reference in New Issue
Block a user