import { useParams } from 'common'
import { AlertCircle, LoaderCircle, X } from 'lucide-react'
import SVG from 'react-inlinesvg'
import { Button } from 'ui'
import { StorageItemWithColumn } from '../Storage.types'
import { useFetchFileUrlQuery } from '../StorageExplorer/useFetchFileUrlQuery'
import { useBucketFilePickerStateSnapshot } from './BucketFilePickerState'
import { BASE_PATH } from '@/lib/constants'
import { formatBytes } from '@/lib/helpers'
const PREVIEW_SIZE_LIMIT = 10 * 1024 * 1024 // 10MB
const PreviewFile = ({ item }: { item: StorageItemWithColumn }) => {
const { ref: projectRef } = useParams()
const { bucket, columns } = useBucketFilePickerStateSnapshot()
const path = columns.slice(0, item.columnIndex).concat(item.name).join('/')
const { data: previewUrl, isPending: isLoading } = useFetchFileUrlQuery({
path,
projectRef: projectRef!,
bucket,
})
// if the size is not available, we set it to be greater than the max size
const size = +(item.metadata?.size ?? PREVIEW_SIZE_LIMIT + 1)
const mimeType = item.metadata?.mimetype
const isSkipped = !!mimeType && !!size && size > PREVIEW_SIZE_LIMIT
if (isLoading) {
return (
)
}
if (isSkipped) {
return (
)
}
if (!mimeType || !previewUrl) {
return (