import { client } from '@/ui/api/client' import { Download } from 'lucide-react' import React, { useImperativeHandle } from 'react' import { FileViewerProps, MediaController } from '../types' export const DefaultViewer = React.forwardRef( ({ file, shareId, children, allowDownload = true }, ref) => { // Implement no-op media controller useImperativeHandle(ref, () => ({ play: () => {}, pause: () => {}, seekTo: () => {}, })) const handleDownload = async () => { const key = file.media?.original?.key if (!key || !file.id) return try { const res = shareId ? await client.api.shares[':shareId'].files[':fileId']['download-url'].$post({ param: { shareId, fileId: file.id }, json: { key }, }) : await client.api.files['download-url'].$post({ json: { key, assetId: file.id }, }) if (!res.ok) return const { url } = await res.json() const link = document.createElement('a') link.href = url link.download = '' document.body.appendChild(link) link.click() document.body.removeChild(link) } catch { // silently fail } } return (
{children}

Preview unavailable

{allowDownload && ( )}
) }, ) export default DefaultViewer