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() { export default async function Home() {
let apps: SshApp[] = []; let apps: SshApp[] = [];
let error: string | null = null; let error: string | null = null;
let emptyStateHint = "当前还没有 SSH 主机,先去创建一台。";
try { try {
const allApps = await listAccessApps(); const allApps = await listAccessApps();
apps = filterSshApps(allApps); apps = filterSshApps(allApps);
if (apps.length === 0 && allApps.some((app) => app.type === "self_hosted")) {
emptyStateHint =
"当前账号下没有由 SSH Console 管理的主机;仅显示由本控制台创建或带识别标签的 SSH Access 应用。";
}
} catch (e) { } catch (e) {
error = e instanceof Error ? e.message : "未知错误"; error = e instanceof Error ? e.message : "未知错误";
apps = []; 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} 个月前`; 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 [search, setSearch] = useState("");
const [selectedTag, setSelectedTag] = useState<string | null>(null); const [selectedTag, setSelectedTag] = useState<string | null>(null);
@ -176,7 +182,7 @@ export default function Dashboard({ apps }: { apps: SshAppData[] }) {
<p className="text-sm mt-1"> <p className="text-sm mt-1">
{search || selectedTag {search || selectedTag
? "请调整搜索条件或过滤器" ? "请调整搜索条件或过滤器"
: "请确认 API Token 具备 Access: Apps and Policies Read 权限"} : emptyStateHint}
</p> </p>
</div> </div>
)} )}

View File

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