fix: 去除share

This commit is contained in:
archer
2023-04-08 11:51:51 +08:00
parent e1c7503611
commit 33154a9c19
9 changed files with 10 additions and 44 deletions

View File

@@ -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 ''

View File

@@ -5,8 +5,7 @@ import type { InitChatResponse } from './response/chat';
/**
* 获取一个聊天框的ID
*/
export const getChatSiteId = (modelId: string, isShare = false) =>
GET<string>(`/chat/generate?modelId=${modelId}&isShare=${isShare ? 'true' : 'false'}`);
export const getChatSiteId = (modelId: string) => GET<string>(`/chat/generate?modelId=${modelId}`);
/**
* 获取初始化聊天内容

View File

@@ -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<any>) {
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<ModelSchema>({
_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: []
});

View File

@@ -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);

View File

@@ -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();

View File

@@ -351,6 +351,7 @@ const Chat = ({ chatId }: { chatId: string }) => {
isClosable: true,
duration: 5000
});
router.push('/model/list');
},
onSettled() {
setLoading(false);

View File

@@ -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: [
{

View File

@@ -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

View File

@@ -93,7 +93,6 @@ export interface ChatSchema {
expiredTime: number;
loadAmount: number;
updateTime: Date;
isShare: boolean;
content: ChatItemType[];
}
export interface ChatPopulate extends ChatSchema {