fix:launchpad config yaml boolean (#4715)

Signed-off-by: jingyang <3161362058@qq.com>
This commit is contained in:
jingyang
2024-04-30 10:52:27 +08:00
committed by GitHub
parent 18464891fc
commit c723346d6e
9 changed files with 59 additions and 54 deletions
@@ -17,6 +17,7 @@ export const getUserQuota = () =>
export const postAuthCname = (data: AuthCnamePrams) => POST('/api/platform/authCname', data);
// abandoned
export const getPlatformEnv = () => GET<EnvResponse>('/api/platform/getEnv');
export const updateDesktopGuide = (payload: UpdateUserGuideParams) =>
@@ -1,12 +1,12 @@
import { getPlatformEnv, getPriceBonus, getUserAccount, updateDesktopGuide } from '@/api/platform';
import { getInitData, getPriceBonus, getUserAccount, updateDesktopGuide } from '@/api/platform';
import { GUIDE_LAUNCHPAD_DETAIL_KEY, GUIDE_LAUNCHPAD_GIFT_KEY } from '@/constants/account';
import { formatMoney } from '@/utils/tools';
import { Flex, FlexProps, Icon, Text } from '@chakra-ui/react';
import { DriveStep, driver } from '@sealos/driver';
import { useTranslation } from 'next-i18next';
import { useEffect, useMemo, useState } from 'react';
import { sealosApp } from 'sealos-desktop-sdk/app';
import { DriverStarIcon } from './useDriver';
import { formatMoney } from '@/utils/tools';
export default function useDriver() {
const { t, i18n } = useTranslation();
@@ -294,7 +294,7 @@ export default function useDriver() {
useEffect(() => {
const handleUserGuide = async () => {
try {
const systemEnv = await getPlatformEnv();
const { guideEnabled } = await getInitData();
const userAccount = await getUserAccount();
const bonus = await getPriceBonus();
@@ -318,7 +318,7 @@ export default function useDriver() {
setActivity(activity);
}
if (systemEnv.guideEnabled && userAccount?.metadata?.annotations) {
if (guideEnabled && userAccount?.metadata?.annotations) {
const showGiftStep = !!userAccount.metadata.annotations?.[GUIDE_LAUNCHPAD_GIFT_KEY];
const isGuided = !!userAccount.metadata.annotations?.[GUIDE_LAUNCHPAD_DETAIL_KEY];
if (!isGuided) {
@@ -1,4 +1,4 @@
import { getPlatformEnv, getUserAccount, updateDesktopGuide } from '@/api/platform';
import { getInitData, getUserAccount, updateDesktopGuide } from '@/api/platform';
import { GUIDE_LAUNCHPAD_CREATE_KEY } from '@/constants/account';
import { Flex, FlexProps, Icon, Text } from '@chakra-ui/react';
import { driver } from '@sealos/driver';
@@ -45,9 +45,9 @@ export default function useDriver() {
useEffect(() => {
const handleUserGuide = async () => {
try {
const systemEnv = await getPlatformEnv();
const { guideEnabled } = await getInitData();
const userAccount = await getUserAccount();
if (systemEnv.guideEnabled && userAccount?.metadata?.annotations) {
if (guideEnabled && userAccount?.metadata?.annotations) {
const isGuided = !!userAccount.metadata.annotations?.[GUIDE_LAUNCHPAD_CREATE_KEY];
if (!isGuided) {
startGuide();
@@ -16,7 +16,6 @@ import NProgress from 'nprogress'; //nprogress module
import { useEffect, useState } from 'react';
import { EVENT_NAME } from 'sealos-desktop-sdk';
import { createSealosApp, sealosApp } from 'sealos-desktop-sdk/app';
import { getPlatformEnv } from '@/api/platform';
import '@/styles/reset.scss';
import 'nprogress/nprogress.css';
import '@sealos/driver/src/driver.css';
@@ -5,7 +5,7 @@ import type { NextApiRequest, NextApiResponse } from 'next';
export default async function handler(req: NextApiRequest, res: NextApiResponse<ApiResp>) {
try {
if (!global.AppConfig.common.guideEnabled) return jsonRes(res, { data: null });
if (global.AppConfig.common.guideEnabled !== 'true') return jsonRes(res, { data: null });
const kubeconfig = await authSession(req.headers);
const domain = global.AppConfig.cloud.domain;
console.log(`https://${domain}/api/v1alpha/account/getAccount`);
@@ -7,7 +7,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse<
jsonRes<EnvResponse>(res, {
data: {
domain: global.AppConfig.cloud.domain || 'cloud.sealos.io',
guideEnabled: global.AppConfig.common.guideEnabled
guideEnabled: global.AppConfig.common.guideEnabled === 'true'
}
});
}
@@ -13,58 +13,63 @@ export type Response = {
SHOW_EVENT_ANALYZE: boolean;
FORM_SLIDER_LIST_CONFIG: FormSliderListType;
CURRENCY: Coin;
guideEnabled: boolean;
};
export const defaultAppConfig: AppConfigType = {
cloud: {
domain: 'cloud.sealos.io',
port: ''
},
common: {
guideEnabled: false,
apiEnabled: false
},
launchpad: {
ingressTlsSecretName: 'wildcard-cert',
eventAnalyze: {
enabled: false,
fastGPTKey: ''
},
components: {
monitor: {
url: 'http://launchpad-monitor.sealos.svc.cluster.local:8428'
}
},
appResourceFormSliderConfig: {
default: {
cpu: [100, 200, 500, 1000, 2000, 3000, 4000, 8000],
memory: [64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384]
}
}
}
};
// export const defaultAppConfig: AppConfigType = {
// cloud: {
// domain: 'cloud.sealos.io',
// port: ''
// },
// common: {
// guideEnabled: false,
// apiEnabled: false
// },
// launchpad: {
// ingressTlsSecretName: 'wildcard-cert',
// eventAnalyze: {
// enabled: false,
// fastGPTKey: ''
// },
// components: {
// monitor: {
// url: 'http://launchpad-monitor.sealos.svc.cluster.local:8428'
// }
// },
// appResourceFormSliderConfig: {
// default: {
// cpu: [100, 200, 500, 1000, 2000, 3000, 4000, 8000],
// memory: [64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384]
// }
// }
// }
// };
export default async function handler(req: NextApiRequest, res: NextApiResponse) {
try {
if (!global.AppConfig) {
if (!global.AppConfig || process.env.NODE_ENV !== 'production') {
const filename =
process.env.NODE_ENV === 'development' ? 'data/config.yaml.local' : '/app/data/config.yaml';
const res: any = yaml.load(readFileSync(filename, 'utf-8'));
console.log(res);
global.AppConfig = res;
}
jsonRes<Response>(res, {
data: {
SEALOS_DOMAIN: global.AppConfig.cloud.domain,
DOMAIN_PORT: global.AppConfig.cloud.port?.toString() || '',
INGRESS_SECRET: global.AppConfig.launchpad.ingressTlsSecretName,
SHOW_EVENT_ANALYZE: global.AppConfig.launchpad.eventAnalyze.enabled === 'true',
FORM_SLIDER_LIST_CONFIG: global.AppConfig.launchpad.appResourceFormSliderConfig,
guideEnabled: global.AppConfig.common.guideEnabled === 'true',
CURRENCY: Coin.shellCoin
}
});
} catch (error) {
console.log('error: /api/platform/getInitData', error);
global.AppConfig = defaultAppConfig;
jsonRes(res, {
code: 500,
error: 'Missing necessary configuration files'
});
}
jsonRes<Response>(res, {
data: {
SEALOS_DOMAIN: global.AppConfig.cloud.domain,
DOMAIN_PORT: global.AppConfig.cloud.port?.toString() || '',
INGRESS_SECRET: global.AppConfig.launchpad.ingressTlsSecretName,
SHOW_EVENT_ANALYZE: global.AppConfig.launchpad.eventAnalyze.enabled,
FORM_SLIDER_LIST_CONFIG: global.AppConfig.launchpad.appResourceFormSliderConfig,
CURRENCY: Coin.shellCoin
}
});
}
@@ -37,6 +37,6 @@ export const serverLoadInitData = () => {
SEALOS_DOMAIN = global.AppConfig.cloud.domain || 'cloud.sealos.io';
DOMAIN_PORT = global.AppConfig.cloud.port || '';
INGRESS_SECRET = global.AppConfig.cloud.domain || 'wildcard-cert';
SHOW_EVENT_ANALYZE = global.AppConfig.launchpad.eventAnalyze.enabled;
SHOW_EVENT_ANALYZE = global.AppConfig.launchpad.eventAnalyze.enabled === 'true';
} catch (error) {}
};
+3 -3
View File
@@ -23,13 +23,13 @@ export type AppConfigType = {
port?: string;
};
common: {
guideEnabled: boolean;
apiEnabled: boolean;
guideEnabled: string;
apiEnabled: string;
};
launchpad: {
ingressTlsSecretName: string;
eventAnalyze: {
enabled: boolean;
enabled: string;
fastGPTKey?: string;
};
components: {