From 8e0f97dbc2b922ed7b83d9d2b19e266c9abeb38f Mon Sep 17 00:00:00 2001 From: dyzulk <66510723+dyzulk@users.noreply.github.com> Date: Wed, 31 Dec 2025 09:40:14 +0700 Subject: [PATCH] feat: implement mirror download for CA certificates --- src/app/(public)/HomeClient.tsx | 16 +-- .../(public)/download/ca-certificate/page.tsx | 102 ++++++++++++++++++ 2 files changed, 110 insertions(+), 8 deletions(-) create mode 100644 src/app/(public)/download/ca-certificate/page.tsx diff --git a/src/app/(public)/HomeClient.tsx b/src/app/(public)/HomeClient.tsx index 1748aa8..d6ec575 100644 --- a/src/app/(public)/HomeClient.tsx +++ b/src/app/(public)/HomeClient.tsx @@ -248,7 +248,7 @@ export default function HomeClient() {
@@ -258,7 +258,7 @@ export default function HomeClient() { {t('download_standard')} @@ -270,7 +270,7 @@ export default function HomeClient() {
@@ -280,7 +280,7 @@ export default function HomeClient() { {t('download_windows')} @@ -317,7 +317,7 @@ export default function HomeClient() {
@@ -327,7 +327,7 @@ export default function HomeClient() { {t('download_standard')} @@ -339,7 +339,7 @@ export default function HomeClient() {
@@ -349,7 +349,7 @@ export default function HomeClient() { {t('download_windows')} diff --git a/src/app/(public)/download/ca-certificate/page.tsx b/src/app/(public)/download/ca-certificate/page.tsx new file mode 100644 index 0000000..de2c12b --- /dev/null +++ b/src/app/(public)/download/ca-certificate/page.tsx @@ -0,0 +1,102 @@ +"use client"; + +import { Suspense, useEffect, useState } from "react"; +import { useSearchParams } from "next/navigation"; +import CommonGridShape from "@/components/common/CommonGridShape"; + +function DownloadMirrorContent() { + const searchParams = useSearchParams(); + const [status, setStatus] = useState("Preparing your download..."); + const [error, setError] = useState(null); + + useEffect(() => { + const serial = searchParams.get("serial"); + const format = searchParams.get("format"); + const target = searchParams.get("target"); + + if (!serial) { + setError("Missing certificate serial."); + setStatus(""); + return; + } + + // Construct backend URL + const baseUrl = process.env.NEXT_PUBLIC_BACKEND_URL; + let downloadUrl = `${baseUrl}/api/public/ca-certificates/${serial}/download`; + + // Append target if specified (windows/mac) + if (target) { + downloadUrl += `/${target}`; + } + + // Append format if specified (der) + if (format) { + downloadUrl += `?format=${format}`; + } + + // Mirroring: Redirect to the backend download URL + setStatus("Redirecting to download..."); + window.location.href = downloadUrl; + + // Optional: Auto close or go back after some time + // But usually the download happens in the background and the page stays + const timeout = setTimeout(() => { + setStatus("If your download didn't start automatically, please refresh this page."); + }, 5000); + + return () => clearTimeout(timeout); + }, [searchParams]); + + return ( +
+
+ {error ? ( +
+
+ + + +
+
+

Download Error

+

{error}

+
+ +
+ ) : ( +
+
+ + + + +
+

{status}

+

Mirroring Download from TrustLab Trust Store

+
+ )} +
+ +
+ +
+
+ ); +} + +export default function DownloadMirror() { + return ( + +
+
+ }> + + + ); +}