From a9f0a3702082d572b10de429c4265d6b6ccd70d1 Mon Sep 17 00:00:00 2001 From: Liam <67254223+RealFascinated@users.noreply.github.com> Date: Mon, 14 Nov 2022 00:09:27 +0000 Subject: [PATCH] Show files --- src/pages/files/[fileId].js | 44 +++++++++++++++++++++---------------- 1 file changed, 25 insertions(+), 19 deletions(-) diff --git a/src/pages/files/[fileId].js b/src/pages/files/[fileId].js index 7a3e623..234c7df 100644 --- a/src/pages/files/[fileId].js +++ b/src/pages/files/[fileId].js @@ -1,33 +1,39 @@ -import FileModel from "../../models/FileModel"; -import UserModel from "../../models/UserModel"; +import { Button } from "@nextui-org/react"; +import Image from "next/image"; +import { getFileInfo } from "src/utils/helpers/fileHelpers"; export default function File(props) { const { isValidFile, fileData } = props; const file = JSON.parse(fileData); + let { uploader, fileId, uploadDate, contentType, fileUrl, width, height } = + file; + contentType = contentType.toLowerCase(); - console.log(file); + if (isValidFile === false) { + return "invalid file"; + } + + let toShow; + if (contentType.includes("image")) { + toShow = ( + {fileId} + ); + } else if (contentType.includes("video")) { + toShow = ; + } else { + ; + } + + return ( +
{toShow}
+ ); } export async function getServerSideProps(ctx) { let { fileId } = ctx.query; fileId = fileId.split(".")[0]; - const file = await FileModel.aggregate([ - { - $match: { - fileId: fileId, - }, - }, - { - $lookup: { - from: UserModel.collection.name, - localField: "uploader", - foreignField: "_id", - as: "uploader", - }, - }, - ]).exec(); - console.log(file.uploader); + const file = await getFileInfo(fileId); return { props: { isValidFile: file !== null,