fix: 修正 SSH 主机空状态提示与旧应用识别

This commit is contained in:
chunzhimoe 2026-04-12 17:30:49 +08:00
parent f20629f8d9
commit d98b6e310a
3 changed files with 23 additions and 9 deletions

View File

@ -7,10 +7,15 @@ export const revalidate = 60;
export default async function Home() {
let apps: SshApp[] = [];
let error: string | null = null;
let emptyStateHint = "当前还没有 SSH 主机,先去创建一台。";
try {
const allApps = await listAccessApps();
apps = filterSshApps(allApps);
if (apps.length === 0 && allApps.some((app) => app.type === "self_hosted")) {
emptyStateHint =
"当前账号下没有由 SSH Console 管理的主机;仅显示由本控制台创建或带识别标签的 SSH Access 应用。";
}
} catch (e) {
error = e instanceof Error ? e.message : "未知错误";
apps = [];
@ -30,5 +35,5 @@ export default async function Home() {
);
}
return <Dashboard apps={apps} />;
return <Dashboard apps={apps} emptyStateHint={emptyStateHint} />;
}

View File

@ -44,7 +44,13 @@ function timeAgo(dateStr: string | null): string {
return `${months} 个月前`;
}
export default function Dashboard({ apps }: { apps: SshAppData[] }) {
export default function Dashboard({
apps,
emptyStateHint = "当前还没有 SSH 主机,先去创建一台。",
}: {
apps: SshAppData[];
emptyStateHint?: string;
}) {
const [search, setSearch] = useState("");
const [selectedTag, setSelectedTag] = useState<string | null>(null);
@ -173,13 +179,13 @@ export default function Dashboard({ apps }: { apps: SshAppData[] }) {
<p className="text-lg font-medium text-[var(--text-muted)]">
</p>
<p className="text-sm mt-1">
{search || selectedTag
? "请调整搜索条件或过滤器"
: "请确认 API Token 具备 Access: Apps and Policies Read 权限"}
</p>
</div>
)}
<p className="text-sm mt-1">
{search || selectedTag
? "请调整搜索条件或过滤器"
: emptyStateHint}
</p>
</div>
)}
{/* Host cards */}
<div className="grid gap-3 sm:grid-cols-2 lg:grid-cols-3">

View File

@ -172,6 +172,7 @@ export async function listAccessApps(): Promise<AccessApp[]> {
/** Tag added to every Access app created by this console */
export const SSH_CONSOLE_TAG = "managed:ssh-console";
const LEGACY_SSH_APP_NAME_PREFIX = "SSH · ";
/**
* Identifies apps managed by this SSH console.
@ -185,6 +186,8 @@ function isSshConsoleApp(app: AccessApp): boolean {
// Legacy apps created before the tag was introduced: has a metrics: tag
// (only this console sets that pattern)
if (tags.some((t) => t.startsWith("metrics:"))) return true;
// Older apps created by this console used a stable name prefix.
if ((app.name ?? "").startsWith(LEGACY_SSH_APP_NAME_PREFIX)) return true;
return false;
}