fix agent

This commit is contained in:
ryan
2026-06-22 11:49:36 +08:00
parent 3d15c65afd
commit 53e6efa33b
4 changed files with 38 additions and 8 deletions
@@ -1,6 +1,7 @@
'use client';
import {useEffect, useMemo, useState} from 'react';
import {useQuery} from '@tanstack/react-query';
import {Copy} from 'lucide-react';
import {toast} from 'sonner';
@@ -8,7 +9,7 @@ import {Button} from '@/components/ui/button';
import {Card, CardContent, CardDescription, CardHeader, CardTitle} from '@/components/ui/card';
import {Input} from '@/components/ui/input';
import {Label} from '@/components/ui/label';
import type {NodeItem} from '@/lib/services/openflare';
import {type NodeItem, StatusService} from '@/lib/services/openflare';
import {
buildRelayDockerInstallCommand,
@@ -56,6 +57,14 @@ export function InstallCommand({
const [serverUrl, setServerUrl] = useState('');
const meta = variantMeta[variant];
const statusQuery = useQuery({
queryKey: ['openflare', 'public-status'],
queryFn: () => StatusService.getPublicStatus(),
staleTime: 5 * 60 * 1000,
});
const serverVersion = statusQuery.data?.version;
useEffect(() => {
if (typeof window !== 'undefined' && !serverUrl) {
setServerUrl(window.location.origin);
@@ -77,9 +86,9 @@ export function InstallCommand({
return '';
}
return variant === 'relay'
? buildRelayDockerInstallCommand(normalizedServerUrl, node.access_token)
: buildTunnelDockerInstallCommand(normalizedServerUrl, node.access_token);
}, [normalizedServerUrl, node.access_token, variant]);
? buildRelayDockerInstallCommand(normalizedServerUrl, node.access_token, serverVersion)
: buildTunnelDockerInstallCommand(normalizedServerUrl, node.access_token, serverVersion);
}, [normalizedServerUrl, node.access_token, variant, serverVersion]);
const handleCopy = async (value: string, message: string) => {
try {
@@ -107,6 +107,20 @@ const relayInstallerScriptUrl =
const flaredInstallerScriptUrl =
'https://raw.githubusercontent.com/Rain-kl/OpenFlare/main/scripts/install-flared.sh';
export function getImageTag(version?: string): string {
if (!version) {
return 'latest';
}
const v = version.toLowerCase();
if (v === 'dev' || v.includes('alpha') || v.includes('beta') || v.includes('rc')) {
return 'beta';
}
if (v.startsWith('v')) {
return version;
}
return 'latest';
}
export function buildRelayInstallCommand(serverUrl: string, discoveryToken: string) {
return [
`curl -fsSL ${relayInstallerScriptUrl} | bash -s -- \\`,
@@ -115,8 +129,9 @@ export function buildRelayInstallCommand(serverUrl: string, discoveryToken: stri
].join('\n');
}
export function buildRelayDockerInstallCommand(serverUrl: string, discoveryToken: string) {
const image = 'ghcr.io/rain-kl/openflare-relay:latest';
export function buildRelayDockerInstallCommand(serverUrl: string, discoveryToken: string, version?: string) {
const tag = getImageTag(version);
const image = `ghcr.io/rain-kl/openflare-relay:${tag}`;
return [
`docker pull ${image}`,
@@ -136,8 +151,9 @@ export function buildTunnelInstallCommand(serverUrl: string, tunnelToken: string
].join('\n');
}
export function buildTunnelDockerInstallCommand(serverUrl: string, tunnelToken: string) {
const image = 'ghcr.io/rain-kl/openflared:latest';
export function buildTunnelDockerInstallCommand(serverUrl: string, tunnelToken: string, version?: string) {
const tag = getImageTag(version);
const image = `ghcr.io/rain-kl/openflared:${tag}`;
return [
`docker pull ${image}`,
@@ -149,6 +165,7 @@ export function buildTunnelDockerInstallCommand(serverUrl: string, tunnelToken:
].join('\n');
}
export function formatBytes(bytes?: number | null, decimals = 1) {
if (bytes === undefined || bytes === null || !Number.isFinite(bytes)) {
return '—';