perf: unlogin user fetch data (#3775)
* model config * feat: normalization embedding * perf: unlogin user fetch data
This commit is contained in:
@@ -6,6 +6,20 @@ import { getDownloadStream, getFileById } from '@fastgpt/service/common/file/gri
|
||||
import { CommonErrEnum } from '@fastgpt/global/common/error/code/common';
|
||||
import { stream2Encoding } from '@fastgpt/service/common/file/gridfs/utils';
|
||||
|
||||
const previewableExtensions = [
|
||||
'jpg',
|
||||
'jpeg',
|
||||
'png',
|
||||
'gif',
|
||||
'bmp',
|
||||
'webp',
|
||||
'txt',
|
||||
'log',
|
||||
'csv',
|
||||
'md',
|
||||
'json'
|
||||
];
|
||||
|
||||
// Abandoned, use: file/read/[filename].ts
|
||||
export default async function handler(req: NextApiRequest, res: NextApiResponse<any>) {
|
||||
try {
|
||||
@@ -39,7 +53,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse<
|
||||
})();
|
||||
|
||||
const extension = file.filename.split('.').pop() || '';
|
||||
const disposition = ['html', 'htm'].includes(extension) ? 'attachment' : 'inline';
|
||||
const disposition = previewableExtensions.includes(extension) ? 'inline' : 'attachment';
|
||||
|
||||
res.setHeader('Content-Type', `${file.contentType}; charset=${encoding}`);
|
||||
res.setHeader('Cache-Control', 'public, max-age=31536000');
|
||||
|
||||
@@ -6,6 +6,19 @@ import { getDownloadStream, getFileById } from '@fastgpt/service/common/file/gri
|
||||
import { CommonErrEnum } from '@fastgpt/global/common/error/code/common';
|
||||
import { stream2Encoding } from '@fastgpt/service/common/file/gridfs/utils';
|
||||
|
||||
const previewableExtensions = [
|
||||
'jpg',
|
||||
'jpeg',
|
||||
'png',
|
||||
'gif',
|
||||
'bmp',
|
||||
'webp',
|
||||
'txt',
|
||||
'log',
|
||||
'csv',
|
||||
'md',
|
||||
'json'
|
||||
];
|
||||
export default async function handler(req: NextApiRequest, res: NextApiResponse<any>) {
|
||||
try {
|
||||
await connectToDatabase();
|
||||
@@ -38,7 +51,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse<
|
||||
})();
|
||||
|
||||
const extension = file.filename.split('.').pop() || '';
|
||||
const disposition = ['html', 'htm'].includes(extension) ? 'attachment' : 'inline';
|
||||
const disposition = previewableExtensions.includes(extension) ? 'inline' : 'attachment';
|
||||
|
||||
res.setHeader('Content-Type', `${file.contentType}; charset=${encoding}`);
|
||||
res.setHeader('Cache-Control', 'public, max-age=31536000');
|
||||
|
||||
@@ -3,6 +3,7 @@ import { ApiRequestProps } from '@fastgpt/service/type/next';
|
||||
import { NextAPI } from '@/service/middleware/entry';
|
||||
import { InitDateResponse } from '@/global/common/api/systemRes';
|
||||
import { SystemModelItemType } from '@fastgpt/service/core/ai/type';
|
||||
import { authCert } from '@fastgpt/service/support/permission/auth/common';
|
||||
|
||||
async function handler(
|
||||
req: ApiRequestProps<{}, { bufferId?: string }>,
|
||||
@@ -24,22 +25,36 @@ async function handler(
|
||||
requestAuth: undefined
|
||||
})) as SystemModelItemType[];
|
||||
|
||||
// If bufferId is the same as the current bufferId, return directly
|
||||
if (bufferId && global.systemInitBufferId && global.systemInitBufferId === bufferId) {
|
||||
try {
|
||||
await authCert({ req, authToken: true });
|
||||
// If bufferId is the same as the current bufferId, return directly
|
||||
if (bufferId && global.systemInitBufferId && global.systemInitBufferId === bufferId) {
|
||||
return {
|
||||
bufferId: global.systemInitBufferId,
|
||||
systemVersion: global.systemVersion
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
bufferId: global.systemInitBufferId,
|
||||
systemVersion: global.systemVersion || '0.0.0'
|
||||
feConfigs: global.feConfigs,
|
||||
subPlans: global.subPlans,
|
||||
systemVersion: global.systemVersion,
|
||||
activeModelList,
|
||||
defaultModels: global.systemDefaultModel
|
||||
};
|
||||
} catch (error) {
|
||||
const unAuthBufferId = global.systemInitBufferId ? `unAuth_${global.systemInitBufferId}` : '';
|
||||
if (bufferId && unAuthBufferId === bufferId) {
|
||||
return {
|
||||
bufferId: unAuthBufferId
|
||||
};
|
||||
}
|
||||
return {
|
||||
bufferId: unAuthBufferId,
|
||||
feConfigs: global.feConfigs
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
bufferId: global.systemInitBufferId,
|
||||
feConfigs: global.feConfigs,
|
||||
subPlans: global.subPlans,
|
||||
systemVersion: global.systemVersion || '0.0.0',
|
||||
activeModelList,
|
||||
defaultModels: global.systemDefaultModel
|
||||
};
|
||||
}
|
||||
|
||||
export default NextAPI(handler);
|
||||
|
||||
@@ -42,7 +42,7 @@ const Login = ({ ChineseRedirectUrl }: { ChineseRedirectUrl: string }) => {
|
||||
const router = useRouter();
|
||||
const { t } = useTranslation();
|
||||
const { lastRoute = '' } = router.query as { lastRoute: string };
|
||||
const { feConfigs, llmModelList } = useSystemStore();
|
||||
const { feConfigs } = useSystemStore();
|
||||
const [pageType, setPageType] = useState<`${LoginPageTypeEnum}`>(LoginPageTypeEnum.passwordLogin);
|
||||
const { setUserInfo } = useUserStore();
|
||||
const { setLastChatAppId } = useChatStore();
|
||||
@@ -63,16 +63,6 @@ const Login = ({ ChineseRedirectUrl }: { ChineseRedirectUrl: string }) => {
|
||||
(res: ResLogin) => {
|
||||
setUserInfo(res.user);
|
||||
|
||||
// Check that the model is available
|
||||
if (res.user.username === 'root' && llmModelList?.length === 0) {
|
||||
toast({
|
||||
status: 'warning',
|
||||
title: t('login:model_not_config')
|
||||
});
|
||||
router.push('/account/model');
|
||||
return;
|
||||
}
|
||||
|
||||
const decodeLastRoute = decodeURIComponent(lastRoute);
|
||||
// 检查是否是当前的 route
|
||||
const navigateTo =
|
||||
@@ -81,7 +71,7 @@ const Login = ({ ChineseRedirectUrl }: { ChineseRedirectUrl: string }) => {
|
||||
router.push(navigateTo);
|
||||
}, 300);
|
||||
},
|
||||
[setUserInfo, llmModelList?.length, lastRoute, toast, t, router]
|
||||
[setUserInfo, lastRoute, router]
|
||||
);
|
||||
|
||||
const DynamicComponent = useMemo(() => {
|
||||
|
||||
Reference in New Issue
Block a user