From 994e958df00e641798bcae8858f5cdcf9e0565c2 Mon Sep 17 00:00:00 2001 From: Bram Suurd Date: Wed, 6 Nov 2024 19:51:28 +0100 Subject: [PATCH] Refactor source URL generation in `Buttons` component to enhance clarity and streamline the installation script logic --- .../_components/ScriptItems/Buttons.tsx | 40 ++++++------------- 1 file changed, 12 insertions(+), 28 deletions(-) diff --git a/frontend/src/app/scripts/_components/ScriptItems/Buttons.tsx b/frontend/src/app/scripts/_components/ScriptItems/Buttons.tsx index fac97c85..765e8c16 100644 --- a/frontend/src/app/scripts/_components/ScriptItems/Buttons.tsx +++ b/frontend/src/app/scripts/_components/ScriptItems/Buttons.tsx @@ -1,33 +1,17 @@ import { Button } from "@/components/ui/button"; import { Script } from "@/lib/types"; -import { BookOpenText, Code, ExternalLink, Globe } from "lucide-react"; +import { BookOpenText, Code, Globe } from "lucide-react"; import Link from "next/link"; -import { useMemo } from "react"; + +const generateSourceUrl = (slug: string, type: string) => { + if (type === "ct") { + return `https://raw.githubusercontent.com/community-scripts/ProxmoxVE/main/install/${slug}-install.sh`; + } else { + return `https://raw.githubusercontent.com/community-scripts/ProxmoxVE/main/${type}/${slug}.sh`; + } +}; export default function Buttons({ item }: { item: Script }) { - const pattern = useMemo( - () => - /(https:\/\/github\.com\/community-scripts\/ProxmoxVE\/raw\/main\/(ct|misc|vm)\/([^\/]+)\.sh)/, - [], - ); - - const transformUrlToInstallScript = (url: string): string => { - if (url.includes("/pve/")) { - return url; - } else if (url.includes("/ct/")) { - return url.replace("/ct/", "/install/").replace(/\.sh$/, "-install.sh"); - } - return url; - }; - - const sourceUrl = useMemo(() => { - if (item.install_methods[0]?.script) { - const match = item.install_methods[0].script.match(pattern); - return match ? transformUrlToInstallScript(match[0]) : null; - } - return null; - }, [item.install_methods, pattern]); - return (
{item.website && ( @@ -49,16 +33,16 @@ export default function Buttons({ item }: { item: Script }) { )} - {item.install_methods[0]?.script && sourceUrl && ( + { - )} + }
); }