From 2e54d3b13e15fe50b4e93d305e9c773c2a210fed Mon Sep 17 00:00:00 2001 From: mlhiter <3076438032@qq.com> Date: Mon, 13 Jan 2025 11:46:46 +0800 Subject: [PATCH] fix: detail sshConnection bug --- frontend/providers/devbox/api/devbox.ts | 7 --- .../detail/[name]/components/BasicInfo.tsx | 26 +++++------ .../detail/[name]/components/Version.tsx | 1 - .../app/api/getSSHConnectionInfo/route.ts | 2 - .../devbox/app/api/getSSHRuntimeInfo/route.ts | 43 ------------------- 5 files changed, 14 insertions(+), 65 deletions(-) delete mode 100644 frontend/providers/devbox/app/api/getSSHRuntimeInfo/route.ts diff --git a/frontend/providers/devbox/api/devbox.ts b/frontend/providers/devbox/api/devbox.ts index 4d16c48ecdf..944194fd078 100644 --- a/frontend/providers/devbox/api/devbox.ts +++ b/frontend/providers/devbox/api/devbox.ts @@ -114,10 +114,3 @@ export const execCommandInDevboxPod = (data: { onDownloadProgress: data.onDownloadProgress, signal: data.signal }) - -export const getSSHRuntimeInfo = (data: { devboxName: string; runtimeName: string }) => - GET<{ - workingDir: string - releaseCommand: string - releaseArgs: string - }>('/api/getSSHRuntimeInfo', data) diff --git a/frontend/providers/devbox/app/[lang]/(platform)/devbox/detail/[name]/components/BasicInfo.tsx b/frontend/providers/devbox/app/[lang]/(platform)/devbox/detail/[name]/components/BasicInfo.tsx index 129b3d8c0b2..2bee4602381 100644 --- a/frontend/providers/devbox/app/[lang]/(platform)/devbox/detail/[name]/components/BasicInfo.tsx +++ b/frontend/providers/devbox/app/[lang]/(platform)/devbox/detail/[name]/components/BasicInfo.tsx @@ -5,11 +5,12 @@ import { Box, Text, Flex, Image, Spinner, Tooltip, Button } from '@chakra-ui/rea import MyIcon from '@/components/Icon' import { useEnvStore } from '@/stores/env' -import { downLoadBlob } from '@/utils/tools' import { useDevboxStore } from '@/stores/devbox' +import { getTemplateConfig } from '@/api/template' +import { getSSHConnectionInfo } from '@/api/devbox' import { JetBrainsGuideData } from '@/components/IDEButton' +import { downLoadBlob, parseTemplateConfig } from '@/utils/tools' import SshConnectModal from '@/components/modals/SshConnectModal' -import { getSSHConnectionInfo, getSSHRuntimeInfo } from '@/api/devbox' const BasicInfo = () => { const t = useTranslations() @@ -26,21 +27,22 @@ const BasicInfo = () => { const { base64PrivateKey, userName, token } = await getSSHConnectionInfo({ devboxName: devboxDetail?.name as string }) - const { workingDir } = await getSSHRuntimeInfo({ - devboxName: devboxDetail?.name as string, - runtimeName: devboxDetail?.templateName as string - }) + + const result = await getTemplateConfig(devboxDetail?.templateUid as string) + const config = parseTemplateConfig(result.template.config) + console.log('config', config) + const sshPrivateKey = Buffer.from(base64PrivateKey, 'base64').toString('utf-8') if (!devboxDetail?.sshPort) return setSshConfigData({ devboxName: devboxDetail?.name, - runtimeType: devboxDetail?.iconId, + runtimeType: devboxDetail?.templateRepositoryName, privateKey: sshPrivateKey, userName, token, - workingDir, + workingDir: config.workingDir, host: env.sealosDomain, port: devboxDetail?.sshPort.toString(), configHost: `${env.sealosDomain}_${env.namespace}_${devboxDetail?.name}` @@ -48,12 +50,12 @@ const BasicInfo = () => { setOnOpenSsHConnect(true) }, [ - devboxDetail?.iconId, devboxDetail?.name, + devboxDetail?.templateUid, devboxDetail?.sshPort, - devboxDetail?.templateName, - env.namespace, - env.sealosDomain + devboxDetail?.templateRepositoryName, + env.sealosDomain, + env.namespace ]) const handleCopySSHCommand = useCallback(() => { diff --git a/frontend/providers/devbox/app/[lang]/(platform)/devbox/detail/[name]/components/Version.tsx b/frontend/providers/devbox/app/[lang]/(platform)/devbox/detail/[name]/components/Version.tsx index 1e0fe118a98..79fd95c1750 100644 --- a/frontend/providers/devbox/app/[lang]/(platform)/devbox/detail/[name]/components/Version.tsx +++ b/frontend/providers/devbox/app/[lang]/(platform)/devbox/detail/[name]/components/Version.tsx @@ -83,7 +83,6 @@ const Version = () => { listPrivateTemplateRepositoryQuery.data?.templateRepositoryList || [] const handleDeploy = useCallback( async (version: DevboxVersionListItemType) => { - // const { releaseCommand, releaseArgs } = await getSSHRuntimeInfo(devbox.runtimeVersion) if (!devbox) return const result = await getTemplateConfig(devbox.templateUid) const config = parseTemplateConfig(result.template.config) diff --git a/frontend/providers/devbox/app/api/getSSHConnectionInfo/route.ts b/frontend/providers/devbox/app/api/getSSHConnectionInfo/route.ts index e1568e9c0bd..96738265281 100644 --- a/frontend/providers/devbox/app/api/getSSHConnectionInfo/route.ts +++ b/frontend/providers/devbox/app/api/getSSHConnectionInfo/route.ts @@ -16,8 +16,6 @@ export async function GET(req: NextRequest) { const headerList = req.headers - const { ROOT_RUNTIME_NAMESPACE } = process.env - const { k8sCore, namespace, k8sCustomObjects } = await getK8s({ kubeconfig: await authSession(headerList) }) diff --git a/frontend/providers/devbox/app/api/getSSHRuntimeInfo/route.ts b/frontend/providers/devbox/app/api/getSSHRuntimeInfo/route.ts deleted file mode 100644 index 02ff17760f0..00000000000 --- a/frontend/providers/devbox/app/api/getSSHRuntimeInfo/route.ts +++ /dev/null @@ -1,43 +0,0 @@ -import { NextRequest } from 'next/server' - -import { authSession } from '@/services/backend/auth' -import { getK8s } from '@/services/backend/kubernetes' -import { jsonRes } from '@/services/backend/response' -import { defaultEnv } from '@/stores/env' -import { KBRuntimeType } from '@/types/k8s' - -export const dynamic = 'force-dynamic' - -export async function GET(req: NextRequest) { - try { - const { searchParams } = req.nextUrl - const runtimeName = searchParams.get('runtimeName') as string - const headerList = req.headers - const { ROOT_RUNTIME_NAMESPACE } = process.env - - const { k8sCustomObjects } = await getK8s({ - kubeconfig: await authSession(headerList) - }) - - const { body: runtime } = (await k8sCustomObjects.getNamespacedCustomObject( - 'devbox.sealos.io', - 'v1alpha1', - ROOT_RUNTIME_NAMESPACE || defaultEnv.rootRuntimeNamespace, - 'runtimes', - runtimeName - )) as { body: KBRuntimeType } - - const data = { - workingDir: runtime.spec.config.workingDir, - releaseCommand: runtime.spec.config.releaseCommand.join(' '), - releaseArgs: runtime.spec.config.releaseArgs.join(' ') - } - - return jsonRes({ data }) - } catch (err: any) { - return jsonRes({ - code: 500, - error: err - }) - } -}