perf: image and auth
This commit is contained in:
parent
75073a64fb
commit
ca8e940c9b
@ -7,7 +7,8 @@ import { useQuery } from '@tanstack/react-query';
|
|||||||
|
|
||||||
const unAuthPage: { [key: string]: boolean } = {
|
const unAuthPage: { [key: string]: boolean } = {
|
||||||
'/': true,
|
'/': true,
|
||||||
'/login': true
|
'/login': true,
|
||||||
|
'/model/share': true
|
||||||
};
|
};
|
||||||
|
|
||||||
const Auth = ({ children }: { children: JSX.Element }) => {
|
const Auth = ({ children }: { children: JSX.Element }) => {
|
||||||
|
|||||||
@ -20,18 +20,19 @@ const navbarList = [
|
|||||||
link: '/',
|
link: '/',
|
||||||
activeLink: ['/']
|
activeLink: ['/']
|
||||||
},
|
},
|
||||||
{
|
|
||||||
label: '模型',
|
|
||||||
icon: 'model',
|
|
||||||
link: '/model/list',
|
|
||||||
activeLink: ['/model/list', '/model/detail']
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
label: '共享',
|
label: '共享',
|
||||||
icon: 'shareMarket',
|
icon: 'shareMarket',
|
||||||
link: '/model/share',
|
link: '/model/share',
|
||||||
activeLink: ['/model/share']
|
activeLink: ['/model/share']
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
label: '模型',
|
||||||
|
icon: 'model',
|
||||||
|
link: '/model/list',
|
||||||
|
activeLink: ['/model/list', '/model/detail']
|
||||||
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
label: '账号',
|
label: '账号',
|
||||||
icon: 'user',
|
icon: 'user',
|
||||||
|
|||||||
@ -21,7 +21,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse<
|
|||||||
data: collections
|
data: collections
|
||||||
.map((item: any) => ({
|
.map((item: any) => ({
|
||||||
_id: item.modelId?._id,
|
_id: item.modelId?._id,
|
||||||
avatar: item.modelId?.avatar || '',
|
avatar: item.modelId?.avatar || '/icon/logo.png',
|
||||||
name: item.modelId?.name || '',
|
name: item.modelId?.name || '',
|
||||||
userId: item.modelId?.userId || '',
|
userId: item.modelId?.userId || '',
|
||||||
share: item.modelId?.share || {},
|
share: item.modelId?.share || {},
|
||||||
@ -31,8 +31,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse<
|
|||||||
});
|
});
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
jsonRes(res, {
|
jsonRes(res, {
|
||||||
code: 500,
|
data: []
|
||||||
error: err
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -8,9 +8,6 @@ import type { ShareModelItem } from '@/types/model';
|
|||||||
/* 获取模型列表 */
|
/* 获取模型列表 */
|
||||||
export default async function handler(req: NextApiRequest, res: NextApiResponse<any>) {
|
export default async function handler(req: NextApiRequest, res: NextApiResponse<any>) {
|
||||||
try {
|
try {
|
||||||
// 凭证校验
|
|
||||||
await authToken(req.headers.authorization);
|
|
||||||
|
|
||||||
const {
|
const {
|
||||||
searchText = '',
|
searchText = '',
|
||||||
pageNum = 1,
|
pageNum = 1,
|
||||||
@ -28,7 +25,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse<
|
|||||||
]
|
]
|
||||||
};
|
};
|
||||||
|
|
||||||
// 根据分享的模型
|
// 获取被分享的模型
|
||||||
const [models, total] = await Promise.all([
|
const [models, total] = await Promise.all([
|
||||||
Model.find(where, '_id avatar name userId share')
|
Model.find(where, '_id avatar name userId share')
|
||||||
.sort({
|
.sort({
|
||||||
@ -45,7 +42,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse<
|
|||||||
pageSize,
|
pageSize,
|
||||||
data: models.map((item) => ({
|
data: models.map((item) => ({
|
||||||
_id: item._id,
|
_id: item._id,
|
||||||
avatar: item.avatar,
|
avatar: item.avatar || '/icon/logo.png',
|
||||||
name: item.name,
|
name: item.name,
|
||||||
userId: item.userId,
|
userId: item.userId,
|
||||||
share: item.share,
|
share: item.share,
|
||||||
|
|||||||
@ -470,8 +470,12 @@ const Chat = ({ modelId, chatId }: { modelId: string; chatId: string }) => {
|
|||||||
<Menu autoSelect={false}>
|
<Menu autoSelect={false}>
|
||||||
<MenuButton as={Box} mr={media(4, 1)} cursor={'pointer'}>
|
<MenuButton as={Box} mr={media(4, 1)} cursor={'pointer'}>
|
||||||
<Image
|
<Image
|
||||||
src={item.obj === 'Human' ? '/icon/human.png' : chatData.avatar}
|
src={
|
||||||
alt="/icon/logo.png"
|
item.obj === 'Human'
|
||||||
|
? '/icon/human.png'
|
||||||
|
: chatData.avatar || '/icon/logo.png'
|
||||||
|
}
|
||||||
|
alt="avatar"
|
||||||
width={media(30, 20)}
|
width={media(30, 20)}
|
||||||
height={media(30, 20)}
|
height={media(30, 20)}
|
||||||
/>
|
/>
|
||||||
|
|||||||
@ -78,14 +78,14 @@ const ModelEditForm = ({
|
|||||||
头像:
|
头像:
|
||||||
</Box>
|
</Box>
|
||||||
<Image
|
<Image
|
||||||
src={getValues('avatar')}
|
src={getValues('avatar') || '/icon/logo.png'}
|
||||||
alt={'avatar'}
|
alt={'avatar'}
|
||||||
w={['28px', '36px']}
|
w={['28px', '36px']}
|
||||||
h={['28px', '36px']}
|
h={['28px', '36px']}
|
||||||
objectFit={'cover'}
|
objectFit={'cover'}
|
||||||
cursor={'pointer'}
|
cursor={isOwner ? 'pointer' : 'default'}
|
||||||
title={'点击切换头像'}
|
title={'点击切换头像'}
|
||||||
onClick={onOpenSelectFile}
|
onClick={() => isOwner && onOpenSelectFile()}
|
||||||
/>
|
/>
|
||||||
</Flex>
|
</Flex>
|
||||||
<FormControl mt={4}>
|
<FormControl mt={4}>
|
||||||
|
|||||||
@ -85,7 +85,7 @@ const ModelDetail = ({ modelId }: { modelId: string }) => {
|
|||||||
try {
|
try {
|
||||||
await putModelById(data._id, {
|
await putModelById(data._id, {
|
||||||
name: data.name,
|
name: data.name,
|
||||||
avatar: data.avatar,
|
avatar: data.avatar || '/icon/logo.png',
|
||||||
systemPrompt: data.systemPrompt,
|
systemPrompt: data.systemPrompt,
|
||||||
temperature: data.temperature,
|
temperature: data.temperature,
|
||||||
search: data.search,
|
search: data.search,
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
import React from 'react';
|
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 type { ShareModelItem } from '@/types/model';
|
||||||
import { useRouter } from 'next/router';
|
import { useRouter } from 'next/router';
|
||||||
import MyIcon from '@/components/Icon';
|
import MyIcon from '@/components/Icon';
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user