"use client"; import { useCallback, useEffect, useMemo, useState } from "react"; import { useParams } from "next/navigation"; import { LandingNav } from "@/components/landing/LandingNav"; import { buildDriverEntries, buildJreEntries, fetchAgentRegistry, formatSize, type AgentRegistry, type JreDisplayEntry, } from "@/lib/agentRegistry"; import { AlertTriangle, Cpu, Database, Download, Loader2, Search, X } from "lucide-react"; const i18n = { en: { title: "Offline Driver Downloads", subtitle: "Download database drivers and JRE packages for offline use. Search for the exact resource your air-gapped environment needs.", drivers: "Database Drivers", driversDesc: "JDBC driver JAR files for each supported database type.", jre: "Java Runtime (JRE)", jreDesc: "JRE packages used by agent-based database drivers. Required for Oracle, SQL Server, and other agent-managed connections.", loading: "Loading driver catalog...", error: "Unable to load driver catalog. Please check your network connection.", retry: "Retry", download: "Download", version: "Version", size: "Size", requiresJre: "Requires JRE", platform: "Platform", search: "Search drivers, platforms, versions...", noResults: "No matching downloads.", showing: "Showing", of: "of", clearSearch: "Clear search", downloadHint: "For air-gapped environments: download these files on an internet-connected machine, then transfer them to the offline machine and import them in DBX from Settings > Driver Manager.", }, cn: { title: "离线驱动下载", subtitle: "下载数据库驱动和 JRE 离线包。搜索内网环境需要的资源,在有网机器下载后传输。", drivers: "数据库驱动", driversDesc: "每种支持的数据库类型对应的 JDBC 驱动 JAR 文件。", jre: "Java 运行时 (JRE)", jreDesc: "Agent 驱动所需的 JRE 环境,Oracle、SQL Server 等数据库通过 Agent 连接时需要。", loading: "正在加载驱动列表...", error: "加载驱动列表失败,请检查网络连接。", retry: "重试", download: "下载", version: "版本", size: "大小", requiresJre: "依赖 JRE", platform: "平台", search: "搜索驱动、平台、版本...", noResults: "没有匹配的下载项。", showing: "显示", of: "/", clearSearch: "清空搜索", downloadHint: "内网环境使用说明:在有网的电脑上下载这些文件,然后传输到内网机器,在 DBX 的“设置 > 驱动管理”中导入。", }, }; type ActiveTab = "drivers" | "jre"; function platformKey(j: JreDisplayEntry): string { return `${j.jreKey}-${j.platformKey}`; } function matchesSearch(values: Array, query: string): boolean { if (!query) return true; return values.filter(Boolean).join(" ").toLowerCase().includes(query); } export function DriversClient() { const params = useParams(); const rawLang = params?.lang as string | undefined; const lang: "en" | "cn" = rawLang === "cn" ? "cn" : "en"; const t = i18n[lang]; const [registry, setRegistry] = useState(null); const [loading, setLoading] = useState(true); const [error, setError] = useState(null); const [activeTab, setActiveTab] = useState("drivers"); const [searchQuery, setSearchQuery] = useState(""); const loadRegistry = useCallback(async () => { setLoading(true); setError(null); try { const data = await fetchAgentRegistry(); if (data) { setRegistry(data); } else { setError("Unable to load driver catalog"); } } catch { setError("Unable to load driver catalog"); } finally { setLoading(false); } }, []); useEffect(() => { loadRegistry(); }, [loadRegistry]); const drivers = useMemo(() => (registry ? buildDriverEntries(registry) : []), [registry]); const jres = useMemo(() => (registry ? buildJreEntries(registry) : []), [registry]); const normalizedSearch = searchQuery.trim().toLowerCase(); const filteredDrivers = useMemo( () => drivers.filter((d) => matchesSearch([d.label, d.key, d.version, d.jre, formatSize(d.jar.size)], normalizedSearch), ), [drivers, normalizedSearch], ); const filteredJres = useMemo( () => jres.filter((j) => matchesSearch( [j.platformLabel, j.platformKey, j.jreVersion, j.jreKey, formatSize(j.info.size)], normalizedSearch, ), ), [jres, normalizedSearch], ); const activeCount = activeTab === "drivers" ? filteredDrivers.length : filteredJres.length; const activeTotal = activeTab === "drivers" ? drivers.length : jres.length; return (

{t.subtitle}

{loading && (
{t.loading}
)} {error && !loading && (
{t.error}
)} {registry && !loading && ( <>
setSearchQuery(event.target.value)} placeholder={t.search} className="h-9 w-full rounded-[8px] border border-landing-line bg-black/10 pl-9 pr-9 text-sm text-landing-ink outline-none transition-colors placeholder:text-landing-muted focus:border-landing-blue" /> {searchQuery && ( )}
{t.showing} {activeCount} {t.of} {activeTotal}
{activeTab === "drivers" && ( <>

{t.driversDesc}

{filteredDrivers.map((d) => ( ))}
Driver Key {t.version} {t.requiresJre} {t.size}
{d.label} {d.key}
{d.key} {d.version} {d.jre} {formatSize(d.jar.size)} {t.download}
{filteredDrivers.length === 0 && (
{t.noResults}
)} )} {activeTab === "jre" && ( <>

{t.jreDesc}

{filteredJres.map((j) => { const key = platformKey(j); return ( ); })}
{t.platform} JRE {t.version} {t.size}
{j.platformLabel} JRE {j.jreKey}
JRE {j.jreKey} {j.jreVersion} {formatSize(j.info.size)} {t.download}
{filteredJres.length === 0 && (
{t.noResults}
)} )}
{lang === "cn" ? "离线使用说明" : "Offline Usage"}

{t.downloadHint}

)}
); }