Enhance InstallCommand component to support Gitea as an alternative source for installation scripts. Added informational alert for Gitea usage and refactored command generation logic to accommodate the new option. (#5464)
This commit is contained in:
parent
69e14c8fca
commit
72e7bda418
@ -1,17 +1,20 @@
|
|||||||
import CodeCopyButton from "@/components/ui/code-copy-button";
|
import CodeCopyButton from "@/components/ui/code-copy-button";
|
||||||
import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs";
|
import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs";
|
||||||
|
import { Alert, AlertDescription } from "@/components/ui/alert";
|
||||||
|
import { Info } from "lucide-react";
|
||||||
import { basePath } from "@/config/siteConfig";
|
import { basePath } from "@/config/siteConfig";
|
||||||
import { Script } from "@/lib/types";
|
import { Script } from "@/lib/types";
|
||||||
import { getDisplayValueFromType } from "../ScriptInfoBlocks";
|
import { getDisplayValueFromType } from "../ScriptInfoBlocks";
|
||||||
|
|
||||||
const getInstallCommand = (scriptPath = "", isAlpine = false) => {
|
const getInstallCommand = (scriptPath = "", isAlpine = false, useGitea = false) => {
|
||||||
const url = `https://raw.githubusercontent.com/community-scripts/${basePath}/main/${scriptPath}`;
|
const githubUrl = `https://raw.githubusercontent.com/community-scripts/${basePath}/main/${scriptPath}`;
|
||||||
return isAlpine ? `bash -c "$(curl -fsSL ${url})"` : `bash -c "$(curl -fsSL ${url})"`;
|
const giteaUrl = `https://git.community-scripts.org/community-scripts/${basePath}/raw/branch/main/${scriptPath}`;
|
||||||
|
const url = useGitea ? giteaUrl : githubUrl;
|
||||||
|
return `bash -c "$(curl -fsSL ${url})"`;
|
||||||
};
|
};
|
||||||
|
|
||||||
export default function InstallCommand({ item }: { item: Script }) {
|
export default function InstallCommand({ item }: { item: Script }) {
|
||||||
const alpineScript = item.install_methods.find((method) => method.type === "alpine");
|
const alpineScript = item.install_methods.find((method) => method.type === "alpine");
|
||||||
|
|
||||||
const defaultScript = item.install_methods.find((method) => method.type === "default");
|
const defaultScript = item.install_methods.find((method) => method.type === "default");
|
||||||
|
|
||||||
const renderInstructions = (isAlpine = false) => (
|
const renderInstructions = (isAlpine = false) => (
|
||||||
@ -49,9 +52,20 @@ export default function InstallCommand({ item }: { item: Script }) {
|
|||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const renderGiteaInfo = () => (
|
||||||
|
<Alert className="mt-3 mb-3">
|
||||||
|
<Info className="h-4 w-4" />
|
||||||
|
<AlertDescription className="text-sm">
|
||||||
|
<strong>When to use Gitea:</strong> GitHub may have issues including slow connections, delayed updates after bug
|
||||||
|
fixes, no IPv6 support, API rate limits (60/hour). Use our Gitea mirror as a reliable alternative when
|
||||||
|
experiencing these issues.
|
||||||
|
</AlertDescription>
|
||||||
|
</Alert>
|
||||||
|
);
|
||||||
|
|
||||||
|
const renderScriptTabs = (useGitea = false) => {
|
||||||
|
if (alpineScript) {
|
||||||
return (
|
return (
|
||||||
<div className="p-4">
|
|
||||||
{alpineScript ? (
|
|
||||||
<Tabs defaultValue="default" className="mt-2 w-full max-w-4xl">
|
<Tabs defaultValue="default" className="mt-2 w-full max-w-4xl">
|
||||||
<TabsList>
|
<TabsList>
|
||||||
<TabsTrigger value="default">Default</TabsTrigger>
|
<TabsTrigger value="default">Default</TabsTrigger>
|
||||||
@ -59,19 +73,40 @@ export default function InstallCommand({ item }: { item: Script }) {
|
|||||||
</TabsList>
|
</TabsList>
|
||||||
<TabsContent value="default">
|
<TabsContent value="default">
|
||||||
{renderInstructions()}
|
{renderInstructions()}
|
||||||
<CodeCopyButton>{getInstallCommand(defaultScript?.script)}</CodeCopyButton>
|
<CodeCopyButton>{getInstallCommand(defaultScript?.script, false, useGitea)}</CodeCopyButton>
|
||||||
</TabsContent>
|
</TabsContent>
|
||||||
<TabsContent value="alpine">
|
<TabsContent value="alpine">
|
||||||
{renderInstructions(true)}
|
{renderInstructions(true)}
|
||||||
<CodeCopyButton>{getInstallCommand(alpineScript.script, true)}</CodeCopyButton>
|
<CodeCopyButton>{getInstallCommand(alpineScript.script, true, useGitea)}</CodeCopyButton>
|
||||||
</TabsContent>
|
</TabsContent>
|
||||||
</Tabs>
|
</Tabs>
|
||||||
) : defaultScript?.script ? (
|
);
|
||||||
|
} else if (defaultScript?.script) {
|
||||||
|
return (
|
||||||
<>
|
<>
|
||||||
{renderInstructions()}
|
{renderInstructions()}
|
||||||
<CodeCopyButton>{getInstallCommand(defaultScript.script)}</CodeCopyButton>
|
<CodeCopyButton>{getInstallCommand(defaultScript.script, false, useGitea)}</CodeCopyButton>
|
||||||
</>
|
</>
|
||||||
) : null}
|
);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="p-4">
|
||||||
|
<Tabs defaultValue="github" className="w-full max-w-4xl">
|
||||||
|
<TabsList>
|
||||||
|
<TabsTrigger value="github">GitHub</TabsTrigger>
|
||||||
|
<TabsTrigger value="gitea">Gitea</TabsTrigger>
|
||||||
|
</TabsList>
|
||||||
|
<TabsContent value="github">
|
||||||
|
{renderScriptTabs(false)}
|
||||||
|
</TabsContent>
|
||||||
|
<TabsContent value="gitea">
|
||||||
|
{renderGiteaInfo()}
|
||||||
|
{renderScriptTabs(true)}
|
||||||
|
</TabsContent>
|
||||||
|
</Tabs>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user