Skip to content

Commit

Permalink
feat: download function
Browse files Browse the repository at this point in the history
  • Loading branch information
mlhiter committed Dec 12, 2024
1 parent 53dea53 commit a375974
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { DevboxDetailType } from '@/types/devbox'
import { useEnvStore } from '@/stores/env'
import { useDevboxStore } from '@/stores/devbox'
import { useRuntimeStore } from '@/stores/runtime'
import { downLoadBlob } from '@/utils/tools'

const BasicInfo = () => {
const t = useTranslations()
Expand All @@ -33,28 +34,6 @@ const BasicInfo = () => {
})
}, [devboxDetail?.sshConfig?.sshUser, devboxDetail.sshPort, env.sealosDomain, toast, t])

const handleDownloadConfig = useCallback(
async (config: DevboxDetailType['sshConfig']) => {
setLoading(true)

const privateKey = config?.sshPrivateKey as string

const blob = new Blob([privateKey], { type: 'application/octet-stream' })
const url = window.URL.createObjectURL(blob)
const a = document.createElement('a')
a.style.display = 'none'
a.href = url
a.download = devboxDetail.name
document.body.appendChild(a)
a.click()
window.URL.revokeObjectURL(url)
document.body.removeChild(a)

setLoading(false)
},
[devboxDetail]
)

return (
<Flex borderRadius="lg" bg={'white'} p={4} flexDirection={'column'} h={'100%'}>
{/* basic info */}
Expand Down Expand Up @@ -205,7 +184,13 @@ const BasicInfo = () => {
color={'grayModern.600'}
w={'16px'}
h={'16px'}
onClick={() => handleDownloadConfig(devboxDetail?.sshConfig)}
onClick={() =>
downLoadBlob(
devboxDetail?.sshConfig?.sshPrivateKey as string,
'application/octet-stream',
`${devboxDetail?.name}`
)
}
/>
</Flex>
</Tooltip>
Expand Down
23 changes: 21 additions & 2 deletions frontend/providers/devbox/components/modals/SshConnectModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import {
windowsScriptsTemplate
} from '@/constants/scripts'
import { JetBrainsGuideData } from '../IDEButton'
import { downLoadBlob } from '@/utils/tools'

const systemList = ['Windows', 'Mac', 'Linux']

Expand Down Expand Up @@ -122,8 +123,10 @@ const SshConnectModal = ({
</Text>
<Button
leftIcon={<MyIcon name="download" color={'grayModern.500'} w={'16px'} />}
w={'fit-content'}
bg={'white'}
w={'fit-content'}
size={'sm'}
py={4}
color={'grayModern.600'}
border={'1px solid'}
borderColor={'grayModern.200'}
Expand All @@ -133,6 +136,17 @@ const SshConnectModal = ({
'& svg': {
color: 'brightBlue.600'
}
}}
onClick={() => {
if (script.platform === 'Windows') {
downLoadBlob(
script.script,
'text/plain',
`${jetbrainsGuideData.configHost}.ps1`
)
} else {
downLoadBlob(script.script, 'text/plain', `${jetbrainsGuideData.configHost}.sh`)
}
}}>
{t('download_scripts')}
</Button>
Expand Down Expand Up @@ -166,6 +180,7 @@ const SshConnectModal = ({
color={'grayModern.600'}
borderRadius={'5px'}
borderWidth={1}
py={4}
size={'sm'}
_hover={{
color: 'brightBlue.600',
Expand All @@ -174,7 +189,11 @@ const SshConnectModal = ({
}
}}
onClick={() => {
window.open('https://code-with-me.jetbrains.com/remoteDev', '_blank')
downLoadBlob(
jetbrainsGuideData.privateKey,
'application/octet-stream',
`${jetbrainsGuideData.configHost}`
)
}}>
{t('download_private_key')}
</Button>
Expand Down

0 comments on commit a375974

Please sign in to comment.