From ca8e940c9bb27dff78c2d627ea7bb6645aeb1bc1 Mon Sep 17 00:00:00 2001 From: archer <545436317@qq.com> Date: Fri, 28 Apr 2023 14:01:27 +0800 Subject: [PATCH] perf: image and auth --- src/components/Layout/auth.tsx | 3 ++- src/components/Layout/index.tsx | 13 +++++++------ src/pages/api/model/share/getCollection.ts | 5 ++--- src/pages/api/model/share/getModels.ts | 7 ++----- src/pages/chat/index.tsx | 8 ++++++-- src/pages/model/detail/components/ModelEditForm.tsx | 6 +++--- src/pages/model/detail/index.tsx | 2 +- src/pages/model/share/components/list.tsx | 2 +- 8 files changed, 24 insertions(+), 22 deletions(-) diff --git a/src/components/Layout/auth.tsx b/src/components/Layout/auth.tsx index b1d9a52c0..0a6de34a2 100644 --- a/src/components/Layout/auth.tsx +++ b/src/components/Layout/auth.tsx @@ -7,7 +7,8 @@ import { useQuery } from '@tanstack/react-query'; const unAuthPage: { [key: string]: boolean } = { '/': true, - '/login': true + '/login': true, + '/model/share': true }; const Auth = ({ children }: { children: JSX.Element }) => { diff --git a/src/components/Layout/index.tsx b/src/components/Layout/index.tsx index a9796ae93..6fdfcc35c 100644 --- a/src/components/Layout/index.tsx +++ b/src/components/Layout/index.tsx @@ -20,18 +20,19 @@ const navbarList = [ link: '/', activeLink: ['/'] }, - { - label: '模型', - icon: 'model', - link: '/model/list', - activeLink: ['/model/list', '/model/detail'] - }, { label: '共享', icon: 'shareMarket', link: '/model/share', activeLink: ['/model/share'] }, + { + label: '模型', + icon: 'model', + link: '/model/list', + activeLink: ['/model/list', '/model/detail'] + }, + { label: '账号', icon: 'user', diff --git a/src/pages/api/model/share/getCollection.ts b/src/pages/api/model/share/getCollection.ts index 40c89098b..95fe72592 100644 --- a/src/pages/api/model/share/getCollection.ts +++ b/src/pages/api/model/share/getCollection.ts @@ -21,7 +21,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse< data: collections .map((item: any) => ({ _id: item.modelId?._id, - avatar: item.modelId?.avatar || '', + avatar: item.modelId?.avatar || '/icon/logo.png', name: item.modelId?.name || '', userId: item.modelId?.userId || '', share: item.modelId?.share || {}, @@ -31,8 +31,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse< }); } catch (err) { jsonRes(res, { - code: 500, - error: err + data: [] }); } } diff --git a/src/pages/api/model/share/getModels.ts b/src/pages/api/model/share/getModels.ts index 13ae72f53..f3fabd028 100644 --- a/src/pages/api/model/share/getModels.ts +++ b/src/pages/api/model/share/getModels.ts @@ -8,9 +8,6 @@ import type { ShareModelItem } from '@/types/model'; /* 获取模型列表 */ export default async function handler(req: NextApiRequest, res: NextApiResponse) { try { - // 凭证校验 - await authToken(req.headers.authorization); - const { searchText = '', pageNum = 1, @@ -28,7 +25,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse< ] }; - // 根据分享的模型 + // 获取被分享的模型 const [models, total] = await Promise.all([ Model.find(where, '_id avatar name userId share') .sort({ @@ -45,7 +42,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse< pageSize, data: models.map((item) => ({ _id: item._id, - avatar: item.avatar, + avatar: item.avatar || '/icon/logo.png', name: item.name, userId: item.userId, share: item.share, diff --git a/src/pages/chat/index.tsx b/src/pages/chat/index.tsx index 81212c768..7bee7fd1a 100644 --- a/src/pages/chat/index.tsx +++ b/src/pages/chat/index.tsx @@ -470,8 +470,12 @@ const Chat = ({ modelId, chatId }: { modelId: string; chatId: string }) => { /icon/logo.png diff --git a/src/pages/model/detail/components/ModelEditForm.tsx b/src/pages/model/detail/components/ModelEditForm.tsx index 3eb077394..46c8e78d5 100644 --- a/src/pages/model/detail/components/ModelEditForm.tsx +++ b/src/pages/model/detail/components/ModelEditForm.tsx @@ -78,14 +78,14 @@ const ModelEditForm = ({ 头像: {'avatar'} isOwner && onOpenSelectFile()} /> diff --git a/src/pages/model/detail/index.tsx b/src/pages/model/detail/index.tsx index 422d29045..96a37d3f9 100644 --- a/src/pages/model/detail/index.tsx +++ b/src/pages/model/detail/index.tsx @@ -85,7 +85,7 @@ const ModelDetail = ({ modelId }: { modelId: string }) => { try { await putModelById(data._id, { name: data.name, - avatar: data.avatar, + avatar: data.avatar || '/icon/logo.png', systemPrompt: data.systemPrompt, temperature: data.temperature, search: data.search, diff --git a/src/pages/model/share/components/list.tsx b/src/pages/model/share/components/list.tsx index 25715fc6b..e49fd2e7b 100644 --- a/src/pages/model/share/components/list.tsx +++ b/src/pages/model/share/components/list.tsx @@ -1,5 +1,5 @@ import React from 'react'; -import { Card, Box, Flex, Image, Button } from '@chakra-ui/react'; +import { Box, Flex, Image, Button } from '@chakra-ui/react'; import type { ShareModelItem } from '@/types/model'; import { useRouter } from 'next/router'; import MyIcon from '@/components/Icon';