import { Table } from "react-daisyui"; import { useBrowseObjects } from "./hooks"; import { dayjs, readableBytes } from "@/lib/utils"; import mime from "mime/lite"; import { Object } from "./types"; import { API_URL } from "@/lib/api"; import { FileArchive, FileIcon, FileType, Folder } from "lucide-react"; import { useBucketContext } from "../context"; import ObjectActions from "./object-actions"; import GotoTopButton from "@/components/ui/goto-top-btn"; type Props = { prefix?: string; onPrefixChange?: (prefix: string) => void; }; const ObjectList = ({ prefix, onPrefixChange }: Props) => { const { bucketName } = useBucketContext(); const { data } = useBrowseObjects(bucketName, { prefix, limit: 1000 }); const onObjectClick = (object: Object) => { window.open(API_URL + object.viewUrl, "_blank"); }; return (
Name Size Last Modified {!data?.prefixes?.length && !data?.objects?.length && ( )} {data?.prefixes.map((prefix) => ( ))} {data?.objects.map((object, idx) => { const extIdx = object.objectKey.lastIndexOf("."); const filename = extIdx >= 0 ? object.objectKey.substring(0, extIdx) : object.objectKey; const ext = extIdx >= 0 ? object.objectKey.substring(extIdx) : null; return ( = data.objects.length - 2} /> ); })}
No objects
onPrefixChange?.(prefix)} > {prefix .substring(0, prefix.lastIndexOf("/")) .split("/") .pop()}
onObjectClick(object)} > {filename} {ext && {ext}} {readableBytes(object.size)} {dayjs(object.lastModified).fromNow()}
); }; type FilePreviewProps = { ext?: string | null; object: Object; }; const FilePreview = ({ ext, object }: FilePreviewProps) => { const type = mime.getType(ext || "")?.split("/")[0]; let Icon = FileIcon; if ( ["zip", "rar", "7z", "iso", "tar", "gz", "bz2", "xz"].includes(ext || "") ) { Icon = FileArchive; } if (type === "image") { return ( {object.objectKey} ); } if (type === "text") { Icon = FileType; } return ( ); }; export default ObjectList;