diff --git a/apps/desktop/src/lib/navicatImport.ts b/apps/desktop/src/lib/navicatImport.ts index a090109040..399732f973 100644 --- a/apps/desktop/src/lib/navicatImport.ts +++ b/apps/desktop/src/lib/navicatImport.ts @@ -9,6 +9,7 @@ type ParsedNode = { }; const typeMap: Record = { + // String type identifiers (from Navicat ConnType / DatabaseType attributes) mysql: { dbType: "mysql", profile: "mysql", label: "MySQL", port: 3306, user: "root" }, mariadb: { dbType: "mysql", profile: "mariadb", label: "MariaDB", port: 3306, user: "root" }, postgresql: { dbType: "postgres", profile: "postgres", label: "PostgreSQL", port: 5432, user: "postgres" }, @@ -22,6 +23,21 @@ const typeMap: Record { const rawType = getAny(node.values, ["type", "connType", "connectionType", "databaseType", "driver", "dbType"]); - const profile = inferProfile(rawType, node.tag); - if (!profile) return null; + const portValue = Number(getAny(node.values, ["port", "serverPort"])); + const port = Number.isFinite(portValue) && portValue > 0 ? portValue : undefined; + const profile = inferProfile(rawType, node.tag, port); + if (!profile) { + const name = getAny(node.values, ["name", "connectionName", "connName", "caption", "title"]) || "(unnamed)"; + console.warn( + `[Navicat Import] 跳过无法识别类型的连接: "${name}" (type="${rawType}", tag="${node.tag}", port=${port ?? "N/A"})`, + ); + return null; + } const name = getAny(node.values, ["name", "connectionName", "connName", "caption", "title"]) || @@ -132,7 +165,6 @@ async function parseConnection(node: ParsedNode): Promise 0 ? portValue : profile.port, + port: port || profile.port, username, password, database: database || undefined,