refactor: Transform source URL to install script URL in ScriptItem component

This commit is contained in:
Bram Suurd
2024-06-08 21:51:19 +02:00
parent 8939e93acb
commit 230841dcd7

View File

@@ -58,13 +58,24 @@ function ScriptItem({
}, [item, pattern]);
const sourceUrl = useMemo(() => {
const transformUrlToInstallScript = (url: string) => {
if (url.includes("/misc/") || url.includes("/vm/")) {
return url;
} else if (url.includes("/ct/")) {
return url.replace("/ct/", "/install/").replace(/\.sh$/, "-install.sh");
}
return url;
};
if (installCommand) {
const match = installCommand.match(pattern);
return match ? match[0] : null;
return match ? transformUrlToInstallScript(match[0]) : null;
}
return null;
}, [installCommand, pattern]);
const handleCopy = (type: string, value: any) => {
navigator.clipboard.writeText(value);