Show files
This commit is contained in:
parent
75b5c56190
commit
a9f0a37020
@ -1,33 +1,39 @@
|
|||||||
import FileModel from "../../models/FileModel";
|
import { Button } from "@nextui-org/react";
|
||||||
import UserModel from "../../models/UserModel";
|
import Image from "next/image";
|
||||||
|
import { getFileInfo } from "src/utils/helpers/fileHelpers";
|
||||||
|
|
||||||
export default function File(props) {
|
export default function File(props) {
|
||||||
const { isValidFile, fileData } = props;
|
const { isValidFile, fileData } = props;
|
||||||
const file = JSON.parse(fileData);
|
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 = (
|
||||||
|
<Image alt={fileId} src={fileUrl} width={width} height={height}></Image>
|
||||||
|
);
|
||||||
|
} else if (contentType.includes("video")) {
|
||||||
|
toShow = <video alt={fileId} src={fileUrl} controls></video>;
|
||||||
|
} else {
|
||||||
|
<Button>Download</Button>;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="h-screen flex items-center justify-center">{toShow}</div>
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getServerSideProps(ctx) {
|
export async function getServerSideProps(ctx) {
|
||||||
let { fileId } = ctx.query;
|
let { fileId } = ctx.query;
|
||||||
fileId = fileId.split(".")[0];
|
fileId = fileId.split(".")[0];
|
||||||
|
|
||||||
const file = await FileModel.aggregate([
|
const file = await getFileInfo(fileId);
|
||||||
{
|
|
||||||
$match: {
|
|
||||||
fileId: fileId,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
$lookup: {
|
|
||||||
from: UserModel.collection.name,
|
|
||||||
localField: "uploader",
|
|
||||||
foreignField: "_id",
|
|
||||||
as: "uploader",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
]).exec();
|
|
||||||
console.log(file.uploader);
|
|
||||||
return {
|
return {
|
||||||
props: {
|
props: {
|
||||||
isValidFile: file !== null,
|
isValidFile: file !== null,
|
||||||
|
Reference in New Issue
Block a user