Feature: Website - show default OS (#2790)

* Feature: Website - show default OS

* add os fallback

* Update ScriptItem.tsx

* Update Buttons.tsx

* Update Buttons.tsx

* fix duplicate type check

* fix import deps

* add refreshccw
This commit is contained in:
CanbiZ 2025-03-03 09:50:21 +01:00 committed by GitHub
parent 705ad208d7
commit 9570c9199a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 40 additions and 10 deletions

View File

@ -28,6 +28,10 @@ function ScriptItem({
setSelectedScript(null); setSelectedScript(null);
}; };
const defaultInstallMethod = item.install_methods?.[0];
const os = defaultInstallMethod?.resources?.os || "Proxmox Node";
const version = defaultInstallMethod?.resources?.version || "";
return ( return (
<div className="mr-7 mt-0 flex w-full min-w-fit"> <div className="mr-7 mt-0 flex w-full min-w-fit">
<div className="flex w-full min-w-fit"> <div className="flex w-full min-w-fit">
@ -60,6 +64,9 @@ function ScriptItem({
<p className="w-full text-sm text-muted-foreground"> <p className="w-full text-sm text-muted-foreground">
Date added: {extractDate(item.date_created)} Date added: {extractDate(item.date_created)}
</p> </p>
<p className="text-sm text-muted-foreground">
Default OS: {os} {version}
</p>
</div> </div>
<div className="flex gap-5"> <div className="flex gap-5">
<DefaultSettings item={item} /> <DefaultSettings item={item} />

View File

@ -1,14 +1,22 @@
import { Button } from "@/components/ui/button"; import { Button } from "@/components/ui/button";
import { basePath } from "@/config/siteConfig"; import { basePath } from "@/config/siteConfig";
import { Script } from "@/lib/types"; import { Script } from "@/lib/types";
import { BookOpenText, Code, Globe } from "lucide-react"; import { BookOpenText, Code, Globe, RefreshCcw } from "lucide-react";
import Link from "next/link"; import Link from "next/link";
const generateSourceUrl = (slug: string, type: string) => { const generateInstallSourceUrl = (slug: string) => {
const baseUrl = `https://raw.githubusercontent.com/community-scripts/${basePath}/main`; const baseUrl = `https://raw.githubusercontent.com/community-scripts/${basePath}/main`;
return type === "ct" return `${baseUrl}/install/${slug}-install.sh`;
? `${baseUrl}/install/${slug}-install.sh` };
: `${baseUrl}/${type}/${slug}.sh`;
const generateSourceUrl = (slug: string) => {
const baseUrl = `https://raw.githubusercontent.com/community-scripts/${basePath}/main`;
return `${baseUrl}/misc/${slug}.sh`;
};
const generateUpdateUrl = (slug: string) => {
const baseUrl = `https://raw.githubusercontent.com/community-scripts/${basePath}/main`;
return `${baseUrl}/update/${slug}-update.sh`;
}; };
interface ButtonLinkProps { interface ButtonLinkProps {
@ -29,6 +37,11 @@ const ButtonLink = ({ href, icon, text }: ButtonLinkProps) => (
); );
export default function Buttons({ item }: { item: Script }) { export default function Buttons({ item }: { item: Script }) {
const isCtOrDefault = ["ct"].includes(item.type);
const installSourceUrl = isCtOrDefault ? generateInstallSourceUrl(item.slug) : null;
const updateSourceUrl = isCtOrDefault ? generateUpdateUrl(item.slug) : null;
const sourceUrl = !isCtOrDefault ? generateSourceUrl(item.slug) : null;
const buttons = [ const buttons = [
item.website && { item.website && {
href: item.website, href: item.website,
@ -40,8 +53,18 @@ export default function Buttons({ item }: { item: Script }) {
icon: <BookOpenText className="h-4 w-4" />, icon: <BookOpenText className="h-4 w-4" />,
text: "Documentation", text: "Documentation",
}, },
{ installSourceUrl && {
href: generateSourceUrl(item.slug, item.type), href: installSourceUrl,
icon: <Code className="h-4 w-4" />,
text: "Install-Source",
},
updateSourceUrl && {
href: updateSourceUrl,
icon: <RefreshCcw className="h-4 w-4" />,
text: "Update-Source",
},
sourceUrl && {
href: sourceUrl,
icon: <Code className="h-4 w-4" />, icon: <Code className="h-4 w-4" />,
text: "Source Code", text: "Source Code",
}, },