|
|
import { getServerSideConfig } from "@/app/config/server";
|
|
|
import { NextRequest, NextResponse } from "next/server";
|
|
|
|
|
|
import md5 from "spark-md5";
|
|
|
// 处理每日使用限制逻辑
|
|
|
function parseDailyUsage(allowNum: string, configMax: number): number {
|
|
|
function parseDailyUsage(
|
|
|
allowNum: string,
|
|
|
accessCode: string,
|
|
|
maxDailyUse: string,
|
|
|
): number {
|
|
|
let configMax = 0;
|
|
|
if (maxDailyUse) {
|
|
|
configMax = JSON.parse(maxDailyUse)[accessCode];
|
|
|
}
|
|
|
if (allowNum === "first") return configMax;
|
|
|
const parsed = parseInt(allowNum, 10);
|
|
|
return Number.isNaN(parsed) ? configMax : parsed;
|
...
|
...
|
@@ -26,9 +34,9 @@ export async function handle( |
|
|
// 提取 accessCode 和 max_use 参数
|
|
|
const uid = parsedBody.accessCode;
|
|
|
let maxUse = parsedBody.max_use;
|
|
|
if (!uid) {
|
|
|
if (!uid || !config.codes.has(md5.hash(uid))) {
|
|
|
return NextResponse.json({
|
|
|
data: "请前往设置页面输入登录密码",
|
|
|
data: "请检查登录密码",
|
|
|
status: 400,
|
|
|
});
|
|
|
}
|
...
|
...
|
@@ -38,7 +46,7 @@ export async function handle( |
|
|
status: 400,
|
|
|
});
|
|
|
}
|
|
|
maxUse = parseDailyUsage(maxUse, config.docmeeMaxDailyUses);
|
|
|
maxUse = parseDailyUsage(maxUse, uid, config.docmeeMaxDailyUses);
|
|
|
|
|
|
const headers = new Headers({
|
|
|
"Api-Key": config.docmeeApiKey,
|
...
|
...
|
|