import { client } from '@/ui/api/client' import { m } from '@/ui/paraglide/messages.js' import { Download, AlertCircle } 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 } } const isFailed = file.status === 'failed' const errorMessage = file.media?.error return (
{children}
{isFailed ? (

{m.media_processing_failed()}

{m.media_processing_failed_desc()}

{errorMessage && (
{errorMessage}
)}
) : (

Preview unavailable

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