import { ArrowSquareOutIcon, FileIcon, HourglassIcon } from "@phosphor-icons/react"; import type { DataType, FileRef, OutputValue } from "../lib/types"; const isRef = (v: unknown): v is FileRef => !!v && typeof v === "object" && typeof (v as FileRef).url === "string"; const isImageUrl = (u: string) => /\.(png|jpe?g|webp|gif|avif|bmp|svg)(\?|$)/i.test(u); const isAudioUrl = (u: string) => /\.(mp3|wav|ogg|flac|m4a|aac|opus)(\?|$)/i.test(u); const isVideoUrl = (u: string) => /\.(mp4|webm|mov|mkv)(\?|$)/i.test(u); const kindOf = (ref: FileRef, hint: DataType): "image" | "audio" | "video" | "file" => { const m = ref.mime ?? ""; if (m.startsWith("image/") || isImageUrl(ref.url)) return "image"; if (m.startsWith("audio/") || isAudioUrl(ref.url)) return "audio"; if (m.startsWith("video/") || isVideoUrl(ref.url)) return "video"; if (hint === "image" || hint === "audio" || hint === "video") return hint; return "file"; }; function FileView({ file, hint }: { file: FileRef; hint: DataType }) { const kind = kindOf(file, hint); const open = ( e.stopPropagation()}> ); switch (kind) { case "image": return ( <> {file.name {open} ); case "audio": return ( <>