bug修复

This commit is contained in:
xuzhenjun 2023-04-15 00:48:51 +08:00
parent d0abf899b5
commit c617071746
5 changed files with 16 additions and 11 deletions

View File

@ -58,11 +58,18 @@ export async function POST(req: NextRequest) {
const usersCollection = db.collection("users"); const usersCollection = db.collection("users");
// 查询用户数据 // 查询用户数据
const user = await usersCollection.findOne({ key: accessCode }); const user = await usersCollection.findOne({ key: accessCode });
console.log(user, accessCode);
const tips = const tips =
"您的链接授权已过期,为了避免恶意盗刷,\n 关注微信公众号【coder思维】\n回复关键词`ai` 获取授权链接 \n ![](/wx.png)"; "您的链接授权已过期,为了避免恶意盗刷,\n 关注微信公众号【coder思维】\n回复关键词`ai` 获取授权链接 \n ![](/wx.png)";
if (!user) { if (!user) {
return new Response(tips); return new Response(tips);
} }
console.log("compare: ");
console.log(
user["expire"] < new Date().getTime(),
user["expire"],
new Date().getTime(),
);
if (user["expire"] < new Date().getTime()) { if (user["expire"] < new Date().getTime()) {
// 判断用户是否过期 // 判断用户是否过期
return new Response(tips); return new Response(tips);
@ -95,7 +102,7 @@ export async function POST(req: NextRequest) {
content: req.body, content: req.body,
}; };
collection.insertOne(chatLog).then(() => { collection.insertOne(chatLog).then(() => {
client.close(); //client.close();
}); });
const stream = await createStream(req); const stream = await createStream(req);

View File

@ -35,7 +35,7 @@ export const getServerSideConfig = () => {
apiKey: process.env.OPENAI_API_KEY, apiKey: process.env.OPENAI_API_KEY,
code: process.env.CODE, code: process.env.CODE,
codes: ACCESS_CODES, codes: ACCESS_CODES,
needCode: true, needCode: false,
proxyUrl: process.env.PROXY_URL, proxyUrl: process.env.PROXY_URL,
isVercel: !!process.env.VERCEL, isVercel: !!process.env.VERCEL,
}; };

View File

@ -4,7 +4,7 @@ const cn = {
WIP: "该功能仍在开发中……", WIP: "该功能仍在开发中……",
Error: { Error: {
Unauthorized: Unauthorized:
"现在是未授权状态,为了避免恶意盗刷:\n 关注微信公众号【coder思维】\n回复关键词`ai` 获取授权链接 \n ![](/wx.png)", "现在是未授权状态,为了避免恶意盗刷:\n 关注微信公众号【coder思维】\n回复关键词`ai` 获取授权链接 \n ![](/wx.png)",
}, },
ChatItem: { ChatItem: {
ChatItemCount: (count: number) => `${count} 条对话`, ChatItemCount: (count: number) => `${count} 条对话`,
@ -151,7 +151,7 @@ const cn = {
}, },
Store: { Store: {
DefaultTopic: "新的聊天", DefaultTopic: "新的聊天",
BotHello: "有什么可以帮你的吗", BotHello: "有什么可以帮你的吗,我是智商超越人类的 AI大师",
Error: "出错了,稍后重试吧", Error: "出错了,稍后重试吧",
Prompt: { Prompt: {
History: (content: string) => History: (content: string) =>

View File

@ -37,11 +37,9 @@ function getHeaders() {
const accessStore = useAccessStore.getState(); const accessStore = useAccessStore.getState();
let headers: Record<string, string> = {}; let headers: Record<string, string> = {};
if (accessStore.enabledAccessControl()) { const hash = window.location.hash.substr(1); // 获取 hash 值,去掉 #
const hash = window.location.hash.substr(1); // 获取 hash 值,去掉 # const params = new URLSearchParams(hash); // 创建 URLSearchParams 对象
const params = new URLSearchParams(hash); // 创建 URLSearchParams 对象 headers["access-code"] = params.get("key") + "";
headers["access-code"] = params.get("key") + "";
}
if (accessStore.token && accessStore.token.length > 0) { if (accessStore.token && accessStore.token.length > 0) {
headers["token"] = accessStore.token; headers["token"] = accessStore.token;

View File

@ -9,7 +9,7 @@ export const config = {
const serverConfig = getServerSideConfig(); const serverConfig = getServerSideConfig();
export function middleware(req: NextRequest) { export function middleware(req: NextRequest) {
console.log("req:",req) //console.log("req:",req)
const accessCode = req.headers.get("access-code"); const accessCode = req.headers.get("access-code");
const token = req.headers.get("token"); const token = req.headers.get("token");
const hashedCode = md5.hash(accessCode ?? "").trim(); const hashedCode = md5.hash(accessCode ?? "").trim();