Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
chat-query-app
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Labels
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Jobs
Commits
Open sidebar
jaden
chat-query-app
Commits
59cc9afd
Commit
59cc9afd
authored
Mar 18, 2025
by
王昆
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
get db type from plugins
parent
4e7249e6
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
53 additions
and
42 deletions
+53
-42
chat-query/components/import_modal.js
chat-query/components/import_modal.js
+53
-42
No files found.
chat-query/components/import_modal.js
View file @
59cc9afd
import
{
Modal
,
Notification
,
Select
,
Tabs
,
Spin
}
from
'
@arco-design/web-react
'
;
import
{
Parser
}
from
'
@dbml/core
'
;
import
{
useRef
,
useState
}
from
'
react
'
;
import
{
use
Callback
,
use
Ref
,
useState
}
from
'
react
'
;
import
{
nanoid
}
from
'
nanoid
'
;
import
Editor
from
'
@monaco-editor/react
'
;
import
graphState
from
'
../hooks/use-graph-state
'
;
...
...
@@ -434,29 +434,28 @@ export default function ImportModal({ showModal, onCloseModal, cb = _p => { }, t
const
[
dbList
,
setDbList
]
=
useState
([]);
const
searchParams
=
useSearchParams
();
const
applicationId
=
searchParams
.
get
(
'
applicationId
'
);
const
organizationId
=
searchParams
.
get
(
'
organizationId
'
);
useEffect
(()
=>
{
if
(
type
===
5
&&
applicationId
)
{
setLoading
(
true
);
// 开始加载时显示loading
fetch
(
`/ziwei/api/v1/datasources?applicationId=
${
applicationId
}
`
,
{
const
fetchDatasources
=
useCallback
(
async
(
applicationId
,
organizationId
)
=>
{
try
{
const
[
response
,
pluginsResponse
]
=
await
Promise
.
all
([
fetch
(
`/ziwei/api/v1/datasources?applicationId=
${
applicationId
}
`
,
{
method
:
"
GET
"
,
credentials
:
"
include
"
,
}).
finally
(()
=>
{
setLoading
(
false
);
// 请求完成后隐藏loading
})
.
then
(
res
=>
res
.
json
())
.
then
(
async
data
=>
{
}),
fetch
(
`/ziwei/api/v1/plugins?organizationId==
${
organizationId
}
`
,
{
method
:
"
GET
"
,
credentials
:
"
include
"
,
})]);
const
data
=
await
response
.
json
();
const
plugins
=
await
pluginsResponse
.
json
();
const
pluginsMap
=
_
.
keyBy
(
plugins
?.
data
,
'
id
'
);
if
(
data
?.
data
&&
Array
.
isArray
(
data
?.
data
))
{
const
formattedData
=
await
Promise
.
all
(
data
.
data
.
map
(
async
item
=>
{
// 从 datasourceConfiguration 中获取连接信息
return
await
Promise
.
all
(
data
.
data
.
map
(
async
item
=>
{
const
endpoint
=
item
.
datasourceConfiguration
?.
endpoints
?.[
0
]
||
{};
// 获取认证信息,包含加密的密钥
const
auth
=
item
.
datasourceConfiguration
?.
authentication
||
{};
// 如果存在加密密钥,需要进行解密
if
(
auth
.
privateKey
&&
auth
.
encryptedAesKey
)
{
try
{
// 解密密码
auth
.
password
=
await
decryptMessage
(
auth
.
privateKey
,
auth
.
encryptedAesKey
)
auth
.
password
=
await
decryptMessage
(
auth
.
privateKey
,
auth
.
encryptedAesKey
);
}
catch
(
error
)
{
console
.
error
(
'
Failed to decrypt keys:
'
,
error
);
Message
.
error
(
t
(
'
Failed to decrypt database credentials
'
));
...
...
@@ -470,18 +469,30 @@ export default function ImportModal({ showModal, onCloseModal, cb = _p => { }, t
password
:
auth
.
password
||
''
,
database
:
auth
.
databaseName
||
''
,
name
:
item
.
name
||
''
,
client
:
item
.
dbType
===
1
?
'
oracle
'
:
'
mysql2
'
// 根据 dbType 判断数据库类型
client
:
pluginsMap
[
item
.
pluginId
]?.
name
===
'
Oracle
'
?
'
oracle
'
:
'
mysql2
'
};
}));
}
return
[];
}
catch
(
error
)
{
console
.
error
(
'
Error fetching datasources:
'
,
error
);
Message
.
error
(
t
(
'
Failed to fetch datasources
'
));
return
[];
}
},
[
t
])
useEffect
(()
=>
{
if
(
type
===
5
&&
applicationId
)
{
setLoading
(
true
);
fetchDatasources
(
applicationId
,
organizationId
)
.
then
(
formattedData
=>
{
setDbList
(
formattedData
);
if
(
formattedData
.
length
>
0
)
{
form
.
setFieldsValue
(
formattedData
[
0
]);
}
}
})
.
catch
(
error
=>
{
console
.
error
(
'
Error fetching datasources:
'
,
error
);
Message
.
error
(
t
(
'
Failed to fetch datasources
'
));
.
finally
(()
=>
{
setLoading
(
false
);
});
}
},
[
type
,
applicationId
]);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment