mirror of
https://github.com/labring/FastGPT.git
synced 2025-12-26 04:32:50 +00:00
Some checks failed
Build FastGPT images in Personal warehouse / build-fastgpt-images (push) Waiting to run
Deploy image by kubeconfig / build-fastgpt-docs-images (push) Has been cancelled
Deploy image to vercel / deploy-production (push) Has been cancelled
Deploy image by kubeconfig / update-docs-image (push) Has been cancelled
* feishu app release (#85) * Revert "lafAccount add pat & re request when token invalid (#76)" (#77) This reverts commit 83d85dfe37adcaef4833385ea52ee79fd84720be. * perf: workflow ux * system config * feat: feishu app release * chore: sovle the conflicts files; fix the feishu entry * fix: rename Feishu interface to FeishuType * fix: fix type problem in app.ts * fix: type problem * fix: style problem --------- Co-authored-by: Archer <545436317@qq.com> * perf: publish channel code * change system variable position (#94) * perf: workflow context * perf: variable select * hide publish * perf: simple edit auto refresh * perf: simple edit data refresh * fix: target handle --------- Co-authored-by: Finley Ge <32237950+FinleyGe@users.noreply.github.com> Co-authored-by: heheer <71265218+newfish-cmyk@users.noreply.github.com>
83 lines
2.3 KiB
TypeScript
83 lines
2.3 KiB
TypeScript
import { useEffect, useState } from 'react';
|
||
import { clientInitData } from '@/web/common/system/staticData';
|
||
import { useTranslation } from 'next-i18next';
|
||
import { useRouter } from 'next/router';
|
||
import { useSystemStore } from '@/web/common/system/useSystemStore';
|
||
import type { FastGPTFeConfigsType } from '@fastgpt/global/common/system/types/index.d';
|
||
import { change2DefaultLng, setLngStore } from '@/web/common/utils/i18n';
|
||
import { useMemoizedFn, useMount } from 'ahooks';
|
||
|
||
export const useInitApp = () => {
|
||
const router = useRouter();
|
||
const { hiId } = router.query as { hiId?: string };
|
||
const { i18n } = useTranslation();
|
||
const { loadGitStar, setInitd, feConfigs } = useSystemStore();
|
||
const [scripts, setScripts] = useState<FastGPTFeConfigsType['scripts']>([]);
|
||
const [title, setTitle] = useState(process.env.SYSTEM_NAME || 'AI');
|
||
|
||
const initFetch = useMemoizedFn(async () => {
|
||
const {
|
||
feConfigs: { scripts, isPlus, show_git, systemTitle }
|
||
} = await clientInitData();
|
||
|
||
setTitle(systemTitle || 'FastGPT');
|
||
|
||
// log fastgpt
|
||
if (!isPlus) {
|
||
console.log(
|
||
'%cWelcome to FastGPT',
|
||
'font-family:Arial; color:#3370ff ; font-size:18px; font-weight:bold;',
|
||
`GitHub:https://github.com/labring/FastGPT`
|
||
);
|
||
}
|
||
if (show_git) {
|
||
loadGitStar();
|
||
}
|
||
|
||
setScripts(scripts || []);
|
||
setInitd();
|
||
});
|
||
|
||
const initUserLanguage = useMemoizedFn(() => {
|
||
// get default language
|
||
const targetLng = change2DefaultLng(i18n.language);
|
||
if (targetLng) {
|
||
setLngStore(targetLng);
|
||
router.replace(router.asPath, undefined, { locale: targetLng });
|
||
}
|
||
});
|
||
|
||
useMount(() => {
|
||
initFetch();
|
||
initUserLanguage();
|
||
|
||
const errorTrack = (event: ErrorEvent) => {
|
||
window.umami?.track('windowError', {
|
||
device: {
|
||
userAgent: navigator.userAgent,
|
||
platform: navigator.platform,
|
||
appName: navigator.appName
|
||
},
|
||
error: event,
|
||
url: location.href
|
||
});
|
||
};
|
||
// add window error track
|
||
window.addEventListener('error', errorTrack);
|
||
|
||
return () => {
|
||
window.removeEventListener('error', errorTrack);
|
||
};
|
||
});
|
||
|
||
useEffect(() => {
|
||
hiId && localStorage.setItem('inviterId', hiId);
|
||
}, [hiId]);
|
||
|
||
return {
|
||
feConfigs,
|
||
scripts,
|
||
title
|
||
};
|
||
};
|