diff --git a/Dockerfile b/Dockerfile index ee5e92d62..254990db0 100644 --- a/Dockerfile +++ b/Dockerfile @@ -55,7 +55,6 @@ USER nextjs EXPOSE 3000 ENV PORT 3000 -ENV MAX_USER '' ENV AXIOS_PROXY_HOST '' ENV AXIOS_PROXY_PORT '' ENV MONGODB_URI '' diff --git a/src/api/chat.ts b/src/api/chat.ts index 912a166d1..bfdf7c6ee 100644 --- a/src/api/chat.ts +++ b/src/api/chat.ts @@ -5,8 +5,7 @@ import type { InitChatResponse } from './response/chat'; /** * 获取一个聊天框的ID */ -export const getChatSiteId = (modelId: string, isShare = false) => - GET(`/chat/generate?modelId=${modelId}&isShare=${isShare ? 'true' : 'false'}`); +export const getChatSiteId = (modelId: string) => GET(`/chat/generate?modelId=${modelId}`); /** * 获取初始化聊天内容 diff --git a/src/pages/api/chat/generate.ts b/src/pages/api/chat/generate.ts index 5c3e93239..3a1c72da1 100644 --- a/src/pages/api/chat/generate.ts +++ b/src/pages/api/chat/generate.ts @@ -1,15 +1,13 @@ import type { NextApiRequest, NextApiResponse } from 'next'; import { jsonRes } from '@/service/response'; -import { connectToDatabase, Model, Chat } from '@/service/mongo'; +import { connectToDatabase, Chat } from '@/service/mongo'; import { authToken } from '@/service/utils/tools'; -import type { ModelSchema } from '@/types/mongoSchema'; /* 获取我的模型 */ export default async function handler(req: NextApiRequest, res: NextApiResponse) { try { - const { modelId, isShare = 'false' } = req.query as { + const { modelId } = req.query as { modelId: string; - isShare?: 'true' | 'false'; }; const { authorization } = req.headers; @@ -26,23 +24,10 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse< await connectToDatabase(); - // 获取模型配置 - const model = await Model.findOne({ - _id: modelId, - userId - }); - - if (!model) { - throw new Error('模型不存在'); - } - // 创建 chat 数据 const response = await Chat.create({ userId, modelId, - expiredTime: Date.now() + model.security.expiredTime, - loadAmount: model.security.maxLoadAmount, - isShare: isShare === 'true', content: [] }); diff --git a/src/pages/api/user/sendEmail.ts b/src/pages/api/user/sendEmail.ts index 4a2b727b7..cc1dab09a 100644 --- a/src/pages/api/user/sendEmail.ts +++ b/src/pages/api/user/sendEmail.ts @@ -16,15 +16,6 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse) await connectToDatabase(); - // 注册人数限流 - if (type === EmailTypeEnum.register) { - const maxCount = process.env.MAX_USER ? +process.env.MAX_USER : Infinity; - const userCount = await User.count(); - if (userCount >= maxCount) { - throw new Error('当前注册用户已满,请等待名额~'); - } - } - let code = ''; for (let i = 0; i < 6; i++) { code += Math.floor(Math.random() * 10); diff --git a/src/pages/chat/components/SlideBar.tsx b/src/pages/chat/components/SlideBar.tsx index 04cb4f4df..9cecd7ce5 100644 --- a/src/pages/chat/components/SlideBar.tsx +++ b/src/pages/chat/components/SlideBar.tsx @@ -281,7 +281,7 @@ const SlideBar = ({ mr={3} onClick={async () => { copyData( - `${location.origin}/chat?chatId=${await getChatSiteId(modelId, true)}`, + `${location.origin}/chat?chatId=${await getChatSiteId(modelId)}`, '已复制分享链接' ); onCloseShare(); diff --git a/src/pages/chat/index.tsx b/src/pages/chat/index.tsx index 4d2a29e90..54311de35 100644 --- a/src/pages/chat/index.tsx +++ b/src/pages/chat/index.tsx @@ -351,6 +351,7 @@ const Chat = ({ chatId }: { chatId: string }) => { isClosable: true, duration: 5000 }); + router.push('/model/list'); }, onSettled() { setLoading(false); diff --git a/src/service/models/chat.ts b/src/service/models/chat.ts index 513d15087..9a1b8f0f5 100644 --- a/src/service/models/chat.ts +++ b/src/service/models/chat.ts @@ -15,21 +15,17 @@ const ChatSchema = new Schema({ expiredTime: { // 过期时间 type: Number, - required: true + default: Date.now() }, loadAmount: { // 剩余加载次数 type: Number, - required: true + default: -1 }, updateTime: { type: Date, default: () => new Date() }, - isShare: { - type: Boolean, - default: false - }, content: { type: [ { diff --git a/src/service/utils/chat.ts b/src/service/utils/chat.ts index f86980746..616200a26 100644 --- a/src/service/utils/chat.ts +++ b/src/service/utils/chat.ts @@ -26,13 +26,9 @@ export const authChat = async (chatId: string, authorization?: string) => { } // 凭证校验 - if (!chat.isShare) { - const userId = await authToken(authorization); - if (userId !== String(chat.userId._id)) { - return Promise.reject('无权使用该对话'); - } - } else if (chat.loadAmount === 0 || chat.expiredTime <= Date.now()) { - return Promise.reject('聊天框已过期'); + const userId = await authToken(authorization); + if (userId !== String(chat.userId._id)) { + return Promise.reject('无权使用该对话'); } // 获取 user 的 apiKey diff --git a/src/types/mongoSchema.d.ts b/src/types/mongoSchema.d.ts index 227c28025..8abed41ac 100644 --- a/src/types/mongoSchema.d.ts +++ b/src/types/mongoSchema.d.ts @@ -93,7 +93,6 @@ export interface ChatSchema { expiredTime: number; loadAmount: number; updateTime: Date; - isShare: boolean; content: ChatItemType[]; } export interface ChatPopulate extends ChatSchema {