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 EXPOSE 3000
ENV PORT 3000 ENV PORT 3000
ENV MAX_USER ''
ENV AXIOS_PROXY_HOST '' ENV AXIOS_PROXY_HOST ''
ENV AXIOS_PROXY_PORT '' ENV AXIOS_PROXY_PORT ''
ENV MONGODB_URI '' ENV MONGODB_URI ''

View File

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

View File

@@ -1,15 +1,13 @@
import type { NextApiRequest, NextApiResponse } from 'next'; import type { NextApiRequest, NextApiResponse } from 'next';
import { jsonRes } from '@/service/response'; 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 { authToken } from '@/service/utils/tools';
import type { ModelSchema } from '@/types/mongoSchema';
/* 获取我的模型 */ /* 获取我的模型 */
export default async function handler(req: NextApiRequest, res: NextApiResponse<any>) { export default async function handler(req: NextApiRequest, res: NextApiResponse<any>) {
try { try {
const { modelId, isShare = 'false' } = req.query as { const { modelId } = req.query as {
modelId: string; modelId: string;
isShare?: 'true' | 'false';
}; };
const { authorization } = req.headers; const { authorization } = req.headers;
@@ -26,23 +24,10 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse<
await connectToDatabase(); await connectToDatabase();
// 获取模型配置
const model = await Model.findOne<ModelSchema>({
_id: modelId,
userId
});
if (!model) {
throw new Error('模型不存在');
}
// 创建 chat 数据 // 创建 chat 数据
const response = await Chat.create({ const response = await Chat.create({
userId, userId,
modelId, modelId,
expiredTime: Date.now() + model.security.expiredTime,
loadAmount: model.security.maxLoadAmount,
isShare: isShare === 'true',
content: [] content: []
}); });

View File

@@ -16,15 +16,6 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
await connectToDatabase(); 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 = ''; let code = '';
for (let i = 0; i < 6; i++) { for (let i = 0; i < 6; i++) {
code += Math.floor(Math.random() * 10); code += Math.floor(Math.random() * 10);

View File

@@ -281,7 +281,7 @@ const SlideBar = ({
mr={3} mr={3}
onClick={async () => { onClick={async () => {
copyData( copyData(
`${location.origin}/chat?chatId=${await getChatSiteId(modelId, true)}`, `${location.origin}/chat?chatId=${await getChatSiteId(modelId)}`,
'已复制分享链接' '已复制分享链接'
); );
onCloseShare(); onCloseShare();

View File

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

View File

@@ -15,21 +15,17 @@ const ChatSchema = new Schema({
expiredTime: { expiredTime: {
// 过期时间 // 过期时间
type: Number, type: Number,
required: true default: Date.now()
}, },
loadAmount: { loadAmount: {
// 剩余加载次数 // 剩余加载次数
type: Number, type: Number,
required: true default: -1
}, },
updateTime: { updateTime: {
type: Date, type: Date,
default: () => new Date() default: () => new Date()
}, },
isShare: {
type: Boolean,
default: false
},
content: { content: {
type: [ type: [
{ {

View File

@@ -26,13 +26,9 @@ export const authChat = async (chatId: string, authorization?: string) => {
} }
// 凭证校验 // 凭证校验
if (!chat.isShare) { const userId = await authToken(authorization);
const userId = await authToken(authorization); if (userId !== String(chat.userId._id)) {
if (userId !== String(chat.userId._id)) { return Promise.reject('无权使用该对话');
return Promise.reject('无权使用该对话');
}
} else if (chat.loadAmount === 0 || chat.expiredTime <= Date.now()) {
return Promise.reject('聊天框已过期');
} }
// 获取 user 的 apiKey // 获取 user 的 apiKey

View File

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