mirror of
https://github.com/ChatGPTNextWeb/ChatGPT-Next-Web.git
synced 2025-10-01 15:46:39 +08:00
temp user token
This commit is contained in:
parent
15f29d448d
commit
48cf006f83
@ -63,6 +63,7 @@ async function handle(
|
||||
image: item.image,
|
||||
email: item.email,
|
||||
emailVerified: item.emailVerified,
|
||||
everyLimitToken: item.everyLimitToken,
|
||||
createdAt: item.createdAt,
|
||||
updatedAt: item.updatedAt,
|
||||
allowToLogin: item.allowToLogin,
|
||||
|
@ -19,7 +19,19 @@ async function handle(
|
||||
const user_id = session?.user.id;
|
||||
const { startOfTheDayInTimeZone, endOfTheDayInTimeZone } =
|
||||
getCurStartEnd();
|
||||
const current_token = await prisma.logEntry
|
||||
let current_day_limit_token = 0;
|
||||
const current_user = await prisma.user.findUnique({
|
||||
where: {
|
||||
id: user_id,
|
||||
},
|
||||
});
|
||||
if (current_user && current_user.everyLimitToken !== 0) {
|
||||
current_day_limit_token = current_user.everyLimitToken * 1000;
|
||||
} else {
|
||||
current_day_limit_token = 0;
|
||||
}
|
||||
|
||||
const current_day_token = await prisma.logEntry
|
||||
.findMany({
|
||||
where: {
|
||||
userID: user_id,
|
||||
@ -39,7 +51,12 @@ async function handle(
|
||||
);
|
||||
});
|
||||
// console.log('-----------', user_id, current_token)
|
||||
return NextResponse.json({ result: { current_token: current_token } });
|
||||
return NextResponse.json({
|
||||
result: {
|
||||
current_day_token: current_day_token,
|
||||
current_day_limit_token: current_day_limit_token,
|
||||
},
|
||||
});
|
||||
} catch {}
|
||||
return NextResponse.json({ error: "未知错误" }, { status: 500 });
|
||||
}
|
||||
|
@ -1420,7 +1420,11 @@ function _Chat() {
|
||||
// console.log("请求成功,", result);
|
||||
localStorage.setItem(
|
||||
"current_day_token",
|
||||
result["result"]["current_token"],
|
||||
result["result"]["current_day_token"],
|
||||
);
|
||||
localStorage.setItem(
|
||||
"current_day_limit_token",
|
||||
result["result"]["current_day_limit_token"],
|
||||
);
|
||||
});
|
||||
} catch {}
|
||||
@ -1484,7 +1488,7 @@ function _Chat() {
|
||||
<Progress
|
||||
percent={
|
||||
(parseInt(localStorage.getItem("current_day_token") ?? "0") /
|
||||
200000) *
|
||||
parseInt(localStorage.getItem("limit_token") ?? "200000")) *
|
||||
100
|
||||
}
|
||||
size="small"
|
||||
|
@ -543,8 +543,11 @@ export const useChatStore = createPersistStore(
|
||||
const current_day_token = parseInt(
|
||||
localStorage.getItem("current_day_token") ?? "0",
|
||||
);
|
||||
const current_day_limit_token = parseInt(
|
||||
localStorage.getItem("current_day_limit_token") ?? "200000",
|
||||
);
|
||||
// console.log('---------', current_day_token)
|
||||
if (current_day_token >= 200000) {
|
||||
if (current_day_token >= current_day_limit_token) {
|
||||
botMessage.content +=
|
||||
"\n\n" +
|
||||
prettyObject({
|
||||
|
@ -27,6 +27,8 @@ model User {
|
||||
emailVerified DateTime?
|
||||
image String?
|
||||
password String?
|
||||
// 默认每人每天限额20k,但数据库存储0
|
||||
everyLimitToken Int? @default(0)
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
allowToLogin Boolean @default(true)
|
||||
|
Loading…
Reference in New Issue
Block a user