Skip to content

Commit

Permalink
feat:template git err & terminal insufficient balance (#3755)
Browse files Browse the repository at this point in the history
* fix: catch template git error

Signed-off-by: jingyang <3161362058@qq.com>

* fix:template yaml tool

Signed-off-by: jingyang <3161362058@qq.com>

* Insufficient balance

Signed-off-by: jingyang <3161362058@qq.com>

---------

Signed-off-by: jingyang <3161362058@qq.com>
  • Loading branch information
zjy365 committed Aug 23, 2023
1 parent 6ac3aa3 commit 65797c4
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 15 deletions.
16 changes: 15 additions & 1 deletion frontend/providers/template/src/pages/api/platform/getEnv.ts
@@ -1,14 +1,28 @@
import { authSession } from '@/services/backend/auth';
import { getK8s } from '@/services/backend/kubernetes';
import { jsonRes } from '@/services/backend/response';
import { ApiResp } from '@/services/kubernet';
import type { NextApiRequest, NextApiResponse } from 'next';

export default async function handler(req: NextApiRequest, res: NextApiResponse<ApiResp>) {
let user_namespace = '';

try {
const { namespace } = await getK8s({
kubeconfig: await authSession(req.headers)
});
user_namespace = namespace;
} catch (error) {
console.log(error, 'errpr-');
}

jsonRes(res, {
data: {
SEALOS_CLOUD_DOMAIN: process.env.SEALOS_CLOUD_DOMAIN || 'cloud.sealos.io',
SEALOS_CERT_SECRET_NAME: process.env.SEALOS_CERT_SECRET_NAME || 'wildcard-cert',
TEMPLATE_REPO_URL:
process.env.TEMPLATE_REPO_URL || 'https://github.com/labring-actions/templates'
process.env.TEMPLATE_REPO_URL || 'https://github.com/labring-actions/templates',
SEALOS_NAMESPACE: user_namespace || ''
}
});
}
10 changes: 4 additions & 6 deletions frontend/providers/template/src/pages/api/updateRepo.ts
Expand Up @@ -5,6 +5,8 @@ import fs from 'fs';
import JSYAML from 'js-yaml';
import type { NextApiRequest, NextApiResponse } from 'next';
import path from 'path';
import util from 'util';
const execAsync = util.promisify(exec);

const readFileList = (targetPath: string, fileList: unknown[] = [], handlePath: string) => {
// fix ci
Expand Down Expand Up @@ -37,13 +39,9 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse<
const jsonPath = path.resolve(originalPath, 'fast_deploy_template.json');

if (!fs.existsSync(targetPath)) {
exec(`git clone ${repoHttpUrl} ${targetPath}`, (error, stdout, stderr) => {
console.log(error, stdout);
});
await execAsync(`git clone ${repoHttpUrl} ${targetPath}`);
} else {
exec(`cd ${targetPath} && git pull`, (error, stdout, stderr) => {
console.log(error, stdout);
});
await execAsync(`cd ${targetPath} && git pull`);
}

if (!fs.existsSync(targetPath)) {
Expand Down
9 changes: 3 additions & 6 deletions frontend/providers/template/src/pages/develop/index.tsx
Expand Up @@ -124,8 +124,7 @@ const Develop = () => {
borderRadius={'8px'}
overflowY={'hidden'}
overflowX={'scroll'}
flex={1}
>
flex={1}>
{/* left */}
<Flex flexDirection={'column'} flex={'0 1 500px'} borderRight={'1px solid #EFF0F1'}>
<Flex
Expand All @@ -135,8 +134,7 @@ const Develop = () => {
alignItems={'center'}
backgroundColor={'#F8FAFB'}
px="36px"
borderRadius={'8px 8px 0px 0px '}
>
borderRadius={'8px 8px 0px 0px '}>
<MyIcon name="dev" color={'#24282C'} w={'24px'} h={'24px'}></MyIcon>
<Text fontWeight={'500'} fontSize={'16px'} color={'#24282C'} ml="8px">
{t('develop.Development')}
Expand Down Expand Up @@ -164,8 +162,7 @@ const Develop = () => {
alignItems={'center'}
backgroundColor={'#F8FAFB'}
pl="42px"
borderRadius={'8px 8px 0px 0px '}
>
borderRadius={'8px 8px 0px 0px '}>
<MyIcon name="eyeShow" color={'#24282C'} w={'24px'} h={'24px'}></MyIcon>
<Text fontWeight={'500'} fontSize={'16px'} color={'#24282C'} ml="8px">
{t('develop.Preview')}
Expand Down
Expand Up @@ -26,7 +26,7 @@ export const jsonRes = (
} else if (error?.code && error.code in ERROR_TEXT) {
msg = ERROR_TEXT[error.code];
}
console.log('jsonRes error: ', error);
console.error('jsonRes error------------\n ', error);
}

res.json({
Expand Down
5 changes: 5 additions & 0 deletions frontend/providers/terminal/src/pages/error.tsx
@@ -0,0 +1,5 @@
import { Box } from '@chakra-ui/react';

export default function ErrPage() {
return <Box h="100%" w="100%" background={'#2b2b2b'}></Box>;
}
19 changes: 18 additions & 1 deletion frontend/providers/terminal/src/pages/index.tsx
@@ -1,7 +1,7 @@
import Terminal from '@/components/terminal';
import request from '@/service/request';
import useSessionStore from '@/stores/session';
import { Box, Flex, Spinner } from '@chakra-ui/react';
import { Box, Flex, Spinner, useToast } from '@chakra-ui/react';
import { useQuery } from '@tanstack/react-query';
import { useEffect, useState } from 'react';
import { createSealosApp, sealosApp } from 'sealos-desktop-sdk/app';
Expand All @@ -15,6 +15,7 @@ export default function Index(props: ServiceEnv) {
const { setSession, isUserLogin } = useSessionStore();
const [url, setUrl] = useState('');
const [isLoading, setIsLoading] = useState(true);
const toast = useToast();

useEffect(() => {
return createSealosApp();
Expand Down Expand Up @@ -48,6 +49,22 @@ export default function Index(props: ServiceEnv) {
.catch((err) => {});
}
},
onError(err: any) {
if ((err?.data?.code === 500, err?.data?.data)) {
const reason = err?.data?.data?.body?.reason;
if (reason.startsWith('40001')) {
setIsLoading(false);
toast({
position: 'top',
description: 'Insufficient balance',
status: 'error',
duration: 8000,
isClosable: true
});
setUrl('/error');
}
}
},
refetchInterval: url === '' ? 500 : false,
enabled: url === ''
});
Expand Down

0 comments on commit 65797c4

Please sign in to comment.