From 2eed08023882e2e3af913c8e005cbc180939629a Mon Sep 17 00:00:00 2001 From: ZareMate <0.zaremate@gmail.com> Date: Tue, 15 Apr 2025 09:26:54 +0200 Subject: [PATCH] other fix to embeds --- src/app/share/[id].tsx | 53 ------------------------------------------ src/app/share/page.tsx | 51 +++++++++++++++++++++++++++++++++------- 2 files changed, 42 insertions(+), 62 deletions(-) delete mode 100644 src/app/share/[id].tsx diff --git a/src/app/share/[id].tsx b/src/app/share/[id].tsx deleted file mode 100644 index fc6f084..0000000 --- a/src/app/share/[id].tsx +++ /dev/null @@ -1,53 +0,0 @@ -// pages/share/[id].tsx - -import Head from "next/head"; -import type { GetServerSideProps } from "next"; - -interface FileDetails { - name: string; - size: number; - owner: string; - uploadDate: string; - id: string; - url: string; -} - -export const getServerSideProps: GetServerSideProps = async (context) => { - const id = context.query.id as string; - - const res = await fetch(`${process.env.NEXT_PUBLIC_BASE_URL}/api/share?id=${id}`); - if (!res.ok) { - return { - notFound: true, - }; - } - - const fileDetails: FileDetails = await res.json(); - - return { - props: { - fileDetails, - }, - }; -}; - -export default function SharePage({ fileDetails }: { fileDetails: FileDetails }) { - return ( - <> - - {fileDetails.name} - - - - - - - -
-

File: {fileDetails.name}

-

Size: {(fileDetails.size / 1024).toFixed(2)} KB

-

Uploaded by: {fileDetails.owner}

-
- - ); -} diff --git a/src/app/share/page.tsx b/src/app/share/page.tsx index 6972539..105a378 100644 --- a/src/app/share/page.tsx +++ b/src/app/share/page.tsx @@ -5,6 +5,7 @@ import { useEffect, useState } from "react"; import { useSearchParams, useRouter } from "next/navigation"; import toast, { Toaster } from "react-hot-toast"; import Head from "next/head"; +import { number } from "zod"; // import { SharePage } from "~/components/SharePage"; @@ -51,6 +52,47 @@ function UploadsPage() { void fetchFileDetails(); // Use `void` to mark the promise as intentionally ignored }, [fileId]); + // set page og meta tags + useEffect(() => { + if (fileDetails) { + const ogTitle = `File Details: ${fileDetails.name}`; + // proper size conversion + const sizeInKB = fileDetails.size / 1024; + const sizeInMB = sizeInKB / 1024; + const sizeInGB = sizeInMB / 1024; + let sizeDescription: string = `${sizeInKB.toFixed(2)} KB`; + if (sizeInMB >= 1) { + sizeDescription = `${sizeInMB.toFixed(2)} MB`; + } else if (sizeInGB >= 1) { + sizeDescription = `${sizeInGB.toFixed(2)} GB`; + } + const ogDescription = `File Name: ${fileDetails.name}, Size: ${sizeDescription}, Owner: ${fileDetails.owner}, Upload Date: ${new Date(fileDetails.uploadDate).toLocaleString()}`; + + document.title = ogTitle; + // if meta og tags are not present, create them + if (!document.querySelector('meta[name="description"]')) { + const metaDescription = document.createElement("meta"); + metaDescription.name = "description"; + document.head.appendChild(metaDescription); + } + if (!document.querySelector('meta[property="og:title"]')) { + const metaOgTitle = document.createElement("meta"); + metaOgTitle.setAttribute("property", "og:title"); + document.head.appendChild(metaOgTitle); + } + if (!document.querySelector('meta[property="og:description"]')) { + const metaOgDescription = document.createElement("meta"); + metaOgDescription.setAttribute("property", "og:description"); + document.head.appendChild(metaOgDescription); + } + document.querySelector('meta[name="description"]')?.setAttribute("content", ogDescription); + document.querySelector('meta[property="og:title"]')?.setAttribute("content", ogTitle); + document.querySelector('meta[property="og:description"]')?.setAttribute("content", ogDescription); + + + } + }, [fileDetails]); + const handleDownload = async () => { try { if (!fileDetails) { @@ -138,15 +180,6 @@ function UploadsPage() { return (
- - - - - - - - -