mirror of
https://github.com/Rain-kl/OpenFlare.git
synced 2026-10-14 02:46:37 +08:00
feat: 增强更新功能,支持开发版本的自我升级检查;优化仪表板和应用日志页面的用户界面
This commit is contained in:
@@ -124,8 +124,9 @@ func fetchLatestRelease(ctx context.Context) (*githubReleaseResponse, error) {
|
||||
|
||||
func buildLatestServerReleaseView(release *githubReleaseResponse) *LatestServerRelease {
|
||||
currentVersion := strings.TrimSpace(common.Version)
|
||||
isDevBuild := currentVersion == "" || strings.EqualFold(currentVersion, "dev")
|
||||
hasUpdate := false
|
||||
if release != nil {
|
||||
if release != nil && !isDevBuild {
|
||||
hasUpdate = isVersionNewer(currentVersion, release.TagName)
|
||||
}
|
||||
|
||||
@@ -136,7 +137,7 @@ func buildLatestServerReleaseView(release *githubReleaseResponse) *LatestServerR
|
||||
view := &LatestServerRelease{
|
||||
CurrentVersion: currentVersion,
|
||||
HasUpdate: hasUpdate,
|
||||
UpgradeSupported: runtime.GOOS != "windows",
|
||||
UpgradeSupported: !isDevBuild && runtime.GOOS != "windows",
|
||||
InProgress: inProgress,
|
||||
}
|
||||
if release != nil {
|
||||
|
||||
@@ -63,3 +63,25 @@ func TestBuildLatestServerReleaseView(t *testing.T) {
|
||||
t.Fatalf("unexpected tag name: %s", view.TagName)
|
||||
}
|
||||
}
|
||||
|
||||
func TestBuildLatestServerReleaseViewDevBuild(t *testing.T) {
|
||||
originalVersion := common.Version
|
||||
common.Version = "dev"
|
||||
t.Cleanup(func() {
|
||||
common.Version = originalVersion
|
||||
serverUpgradeState.Lock()
|
||||
serverUpgradeState.inProgress = false
|
||||
serverUpgradeState.Unlock()
|
||||
})
|
||||
|
||||
view := buildLatestServerReleaseView(&githubReleaseResponse{
|
||||
TagName: "v0.5.0",
|
||||
})
|
||||
|
||||
if view.HasUpdate {
|
||||
t.Fatal("expected dev build not to report update availability")
|
||||
}
|
||||
if view.UpgradeSupported {
|
||||
t.Fatal("expected dev build not to support self-upgrade")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ export default function DashboardPage() {
|
||||
<div className='space-y-6'>
|
||||
<PageHeader
|
||||
title='ATSFlare 管理端'
|
||||
description='新版前端已统一承接全部页面入口和迁移期兼容路由,当前可继续推进联调与回归。'
|
||||
description='集中展示系统核心数据概览,快速导航至各功能模块进行管理和配置。'
|
||||
/>
|
||||
<DashboardOverview />
|
||||
</div>
|
||||
|
||||
@@ -44,7 +44,8 @@ function SidebarIcon({ icon }: { icon: NavigationIconKey }) {
|
||||
<svg {...commonProps}>
|
||||
<circle cx='12' cy='12' r='8.5'/>
|
||||
<path d='M3.5 12h17'/>
|
||||
<path d='M12 3.5c2.4 2.2 3.8 5.2 3.8 8.5S14.4 18.3 12 20.5C9.6 18.3 8.2 15.3 8.2 12S9.6 5.7 12 3.5Z' />
|
||||
<path
|
||||
d='M12 3.5c2.4 2.2 3.8 5.2 3.8 8.5S14.4 18.3 12 20.5C9.6 18.3 8.2 15.3 8.2 12S9.6 5.7 12 3.5Z'/>
|
||||
</svg>
|
||||
);
|
||||
case 'domain':
|
||||
@@ -91,7 +92,8 @@ function SidebarIcon({ icon }: { icon: NavigationIconKey }) {
|
||||
return (
|
||||
<svg {...commonProps}>
|
||||
<circle cx='12' cy='12' r='3.5'/>
|
||||
<path d='M12 3.5v2.2M12 18.3v2.2M20.5 12h-2.2M5.7 12H3.5M18.1 5.9l-1.6 1.6M7.5 16.5l-1.6 1.6M18.1 18.1l-1.6-1.6M7.5 7.5 5.9 5.9' />
|
||||
<path
|
||||
d='M12 3.5v2.2M12 18.3v2.2M20.5 12h-2.2M5.7 12H3.5M18.1 5.9l-1.6 1.6M7.5 16.5l-1.6 1.6M18.1 18.1l-1.6-1.6M7.5 7.5 5.9 5.9'/>
|
||||
</svg>
|
||||
);
|
||||
}
|
||||
@@ -129,7 +131,8 @@ function SidebarNavItem({
|
||||
: 'border-transparent text-[var(--foreground-secondary)] hover:border-[var(--border-default)] hover:bg-[var(--surface-muted)] hover:text-[var(--foreground-primary)]',
|
||||
)}
|
||||
>
|
||||
<span className='flex h-8 w-8 shrink-0 items-center justify-center rounded-xl bg-[var(--control-background)] text-[var(--foreground-primary)]'>
|
||||
<span
|
||||
className='flex h-8 w-8 shrink-0 items-center justify-center rounded-xl bg-[var(--control-background)] text-[var(--foreground-primary)]'>
|
||||
<SidebarIcon icon={item.icon}/>
|
||||
</span>
|
||||
{showLabel ? <span className='min-w-0 flex-1 text-sm font-medium'>{item.label}</span> : null}
|
||||
@@ -168,8 +171,10 @@ function SidebarContent({
|
||||
|
||||
return (
|
||||
<div className='flex h-full flex-col gap-5'>
|
||||
<div className='flex items-center gap-3 rounded-2xl border border-[var(--border-default)] bg-[var(--surface-muted)] px-3 py-3'>
|
||||
<div className='flex h-10 w-10 items-center justify-center rounded-2xl bg-[var(--brand-primary-soft)] text-sm font-semibold text-[var(--brand-primary)]'>
|
||||
<div
|
||||
className='flex items-center gap-3 rounded-2xl border border-[var(--border-default)] bg-[var(--surface-muted)] px-3 py-3'>
|
||||
<div
|
||||
className='flex h-10 w-10 items-center justify-center rounded-2xl bg-[var(--brand-primary-soft)] text-sm font-semibold text-[var(--brand-primary)]'>
|
||||
AF
|
||||
</div>
|
||||
{showLabel ? (
|
||||
@@ -196,8 +201,9 @@ function SidebarContent({
|
||||
</nav>
|
||||
|
||||
{showLabel ? (
|
||||
<div className='rounded-2xl border border-[var(--status-success-border)] bg-[var(--status-success-soft)] px-3 py-3 text-xs leading-6 text-[var(--status-success-foreground)]'>
|
||||
总览页现在承接各模块摘要,侧栏只保留稳定导航。
|
||||
<div
|
||||
className='rounded-2xl border border-[var(--status-success-border)] bg-[var(--status-success-soft)] px-3 py-3 text-xs leading-6 text-[var(--status-success-foreground)]'>
|
||||
已连接 ATSFlare Server
|
||||
</div>
|
||||
) : null}
|
||||
</div>
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
'use client';
|
||||
|
||||
import Link from 'next/link';
|
||||
import { useQuery, useQueryClient } from '@tanstack/react-query';
|
||||
import { useEffect, useMemo, useState } from 'react';
|
||||
|
||||
@@ -88,6 +89,14 @@ export function ApplyLogsPage() {
|
||||
<PageHeader
|
||||
title='应用记录'
|
||||
description='查看节点应用版本的成功或失败记录,支持按 node_id 过滤并查看单条详情。'
|
||||
action={
|
||||
<Link
|
||||
href='/node'
|
||||
className='inline-flex items-center justify-center rounded-2xl border border-[var(--border-default)] bg-[var(--control-background)] px-4 py-3 text-sm font-medium text-[var(--foreground-primary)] transition hover:bg-[var(--control-background-hover)]'
|
||||
>
|
||||
返回节点页
|
||||
</Link>
|
||||
}
|
||||
/>
|
||||
|
||||
{feedback ? <InlineMessage tone='info' message={feedback} /> : null}
|
||||
|
||||
@@ -15,6 +15,7 @@ import { PageHeader } from '@/components/layout/page-header';
|
||||
import { AppModal } from '@/components/ui/app-modal';
|
||||
import { AppCard } from '@/components/ui/app-card';
|
||||
import { StatusBadge } from '@/components/ui/status-badge';
|
||||
import { getPublicStatus } from '@/features/auth/api/public';
|
||||
import {
|
||||
createNode,
|
||||
deleteNode,
|
||||
@@ -134,6 +135,56 @@ function getUpdateMode(node: NodeItem) {
|
||||
return { label: '手动更新', variant: 'info' as const };
|
||||
}
|
||||
|
||||
function parseVersionParts(version: string) {
|
||||
const normalized = version.trim().replace(/^v/i, '');
|
||||
if (!normalized || normalized.toLowerCase() === 'unknown') {
|
||||
return null;
|
||||
}
|
||||
|
||||
return normalized.split('.').map((segment) => {
|
||||
const matched = segment.trim().match(/^\d+/);
|
||||
return matched ? Number.parseInt(matched[0], 10) : 0;
|
||||
});
|
||||
}
|
||||
|
||||
function isOlderVersion(current: string, target: string) {
|
||||
const currentParts = parseVersionParts(current);
|
||||
const targetParts = parseVersionParts(target);
|
||||
if (!currentParts || !targetParts) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const maxLength = Math.max(currentParts.length, targetParts.length);
|
||||
for (let index = 0; index < maxLength; index += 1) {
|
||||
const currentPart = currentParts[index] ?? 0;
|
||||
const targetPart = targetParts[index] ?? 0;
|
||||
if (currentPart < targetPart) {
|
||||
return true;
|
||||
}
|
||||
if (currentPart > targetPart) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
function shouldShowManualUpdate(agentVersion: string, serverVersion: string) {
|
||||
const normalizedServerVersion = serverVersion.trim();
|
||||
const normalizedAgentVersion = agentVersion.trim();
|
||||
|
||||
if (
|
||||
!normalizedServerVersion ||
|
||||
normalizedServerVersion.toLowerCase() === 'dev' ||
|
||||
!normalizedAgentVersion ||
|
||||
normalizedAgentVersion.toLowerCase() === 'unknown'
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return isOlderVersion(normalizedAgentVersion, normalizedServerVersion);
|
||||
}
|
||||
|
||||
function getServerUrl(value: string) {
|
||||
return value.trim().replace(/\/+$/, '');
|
||||
}
|
||||
@@ -175,6 +226,11 @@ export function NodesPage() {
|
||||
queryFn: getNodes,
|
||||
});
|
||||
|
||||
const publicStatusQuery = useQuery({
|
||||
queryKey: ['public-status'],
|
||||
queryFn: getPublicStatus,
|
||||
});
|
||||
|
||||
useEffect(() => {
|
||||
if (typeof window !== 'undefined' && !serverUrl) {
|
||||
setServerUrl(window.location.origin);
|
||||
@@ -246,6 +302,7 @@ export function NodesPage() {
|
||||
|
||||
const nodes = useMemo(() => nodesQuery.data ?? [], [nodesQuery.data]);
|
||||
const normalizedServerUrl = getServerUrl(serverUrl);
|
||||
const serverVersion = publicStatusQuery.data?.version ?? '';
|
||||
|
||||
const selectedNodeFromList = useMemo(() => {
|
||||
if (!selectedNode) {
|
||||
@@ -348,7 +405,6 @@ export function NodesPage() {
|
||||
|
||||
<AppCard
|
||||
title="节点列表"
|
||||
description="展示心跳、最近应用结果、版本信息与更新状态,可直接执行管理动作。"
|
||||
action={
|
||||
<SecondaryButton
|
||||
type="button"
|
||||
@@ -391,6 +447,10 @@ export function NodesPage() {
|
||||
<tbody className="divide-y divide-[var(--border-default)]">
|
||||
{nodes.map((node) => {
|
||||
const updateMode = getUpdateMode(node);
|
||||
const showManualUpdate = shouldShowManualUpdate(
|
||||
node.agent_version || '',
|
||||
serverVersion,
|
||||
);
|
||||
|
||||
return (
|
||||
<tr key={node.id} className="align-top">
|
||||
@@ -465,6 +525,7 @@ export function NodesPage() {
|
||||
</td>
|
||||
<td className="px-3 py-4">
|
||||
<div className="flex flex-wrap gap-2">
|
||||
{showManualUpdate ? (
|
||||
<PrimaryButton
|
||||
type="button"
|
||||
onClick={() =>
|
||||
@@ -476,8 +537,9 @@ export function NodesPage() {
|
||||
}
|
||||
className="px-3 py-2 text-xs"
|
||||
>
|
||||
立即更新
|
||||
升级
|
||||
</PrimaryButton>
|
||||
) : null}
|
||||
<SecondaryButton
|
||||
type="button"
|
||||
onClick={() => handleOpenDeployModal(node)}
|
||||
|
||||
@@ -1,12 +1,22 @@
|
||||
import { dashboardNavigation } from '@/lib/constants/navigation';
|
||||
import type { NavigationItem } from '@/types/navigation';
|
||||
|
||||
export function isPathActive(pathname: string, href: string) {
|
||||
if (href === '/') {
|
||||
return pathname === '/';
|
||||
const navigationPathAliases: Record<string, string> = {
|
||||
'/apply-log': '/node',
|
||||
};
|
||||
|
||||
function normalizeNavigationPath(pathname: string) {
|
||||
return navigationPathAliases[pathname] ?? pathname;
|
||||
}
|
||||
|
||||
return pathname === href || pathname.startsWith(`${href}/`);
|
||||
export function isPathActive(pathname: string, href: string) {
|
||||
const normalizedPathname = normalizeNavigationPath(pathname);
|
||||
|
||||
if (href === '/') {
|
||||
return normalizedPathname === '/';
|
||||
}
|
||||
|
||||
return normalizedPathname === href || normalizedPathname.startsWith(`${href}/`);
|
||||
}
|
||||
|
||||
export function isNavigationItemActive(pathname: string, item: NavigationItem): boolean {
|
||||
|
||||
Reference in New Issue
Block a user