import { Button } from "@nextui-org/react"; import moment from "moment/moment"; import Image from "next/image"; import Link from "next/link"; import { getFileInfo } from "src/utils/helpers/fileHelpers"; import { formatBytes } from "src/utils/helpers/stringHelpers"; import { downloadURI } from "src/utils/helpers/webUtils"; export default function File(props) { const { isValidFile, fileData } = props; const file = JSON.parse(fileData); let { fileId, originalFileName, uploadDate, contentType, fileUrl, width, height, ext, size, } = file; let toShow; if (!isValidFile) { toShow = ( <>

Invalid File

); } if (isValidFile) { contentType = contentType.toLowerCase(); if (contentType.includes("image")) { toShow = ( {fileId} ); } if (contentType.includes("video")) { toShow = ; } } return (
{isValidFile ? (

{originalFileName} ({fileId}.{ext})

{moment(uploadDate).format("MMMM Do YYYY, h:mm:ss a")}

{formatBytes(size)}

) : null}
{toShow}
); } export async function getServerSideProps(ctx) { let { fileId } = ctx.query; fileId = fileId.split(".")[0]; const file = await getFileInfo(fileId); return { props: { isValidFile: file !== null, fileData: JSON.stringify(file || []), }, }; }