作者 202304001

修改密码次数限制

... ... @@ -20,7 +20,6 @@ import { handle as zuotangHandler } from "../../zuotang";
//20250328新增PPT API
import { handle as docmeeHandler } from "../../docmee";
import { handle as generateImgHandler } from "../../generateImg";
import { handle as tencentCosHandler } from "../../tencentCos";
async function handle(
req: NextRequest,
... ... @@ -64,8 +63,6 @@ async function handle(
return docmeeHandler(req, { params });
case ApiPath.OpenAiImg:
return generateImgHandler(req, { params });
case ApiPath.TencentCos:
return tencentCosHandler(req, { params });
default:
return proxyHandler(req, { params });
}
... ...
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,
... ...
import { NextRequest, NextResponse } from "next/server";
export async function handle(
req: NextRequest,
{ params }: { params: { path: string[] } },
) {
return NextResponse.json(
{
success: true,
data: {
msg: "success",
},
},
{ status: 200 },
);
}
... ... @@ -31,8 +31,15 @@ function createErrorResponse(
});
}
// 处理每日使用限制逻辑
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;
... ... @@ -67,7 +74,8 @@ export async function handle(
}
const maxDailyUses = parseDailyUsage(
localDataObj.maxDailyUses,
config.maxDailyUses,
accessCode,
config.bgRemoveMaxDailyUses,
);
if (maxDailyUses <= 0) {
... ...
... ... @@ -13,7 +13,6 @@ import { useChatStore } from "@/app/store";
import { getBgPrompt } from "@/app/utils/prompt";
import { cosUploadImage } from "@/app/utils/tencentCos";
import { getFileByUrl } from "@/app/utils/fileUtil";
import { getServerSideConfig } from "@/app/config/server";
// 错误消息映射函数
const getErrorMessage = (state: number): string => {
const errorMap: { [key: number]: string } = {
... ... @@ -519,17 +518,6 @@ export function BgPanel(props: PanelProps) {
onClick={() => handleProcessImage("visual/r-background")}
disabled={isLoading}
/>
<IconButton
text="测试"
type="primary"
shadow
onClick={() => {
const config = getServerSideConfig();
console.log("**********************************", bgremovalModel);
}}
disabled={isLoading}
/>
</div>
</ControlParamItem>
</>
... ...
... ... @@ -96,12 +96,12 @@ declare global {
//佐糖抠图API URL
BACKGROUND_REMOVAL_URL: string;
BACKGROUND_REMOVAL_API_KEY: string;
MAX_DAILY_USES: number;
BGREMOVE_MAX_DAILY_USES: string;
//AI PPT
DOCMEE_URL: string;
DOCMEE_API_KEY: string;
DOCMEE_MAX_DAILY_USES: number;
DOCMEE_MAX_DAILY_USES: string;
//腾讯云
TENCENT_COS_SECRETKEY: string;
... ... @@ -285,7 +285,7 @@ export const getServerSideConfig = () => {
//20250320新增 佐糖抠图API URL
bgRemovalUrl: process.env.BACKGROUND_REMOVAL_URL ?? "",
bgRemovalApiKey: process.env.BACKGROUND_REMOVAL_API_KEY ?? "",
maxDailyUses: process.env.MAX_DAILY_USES,
bgRemoveMaxDailyUses: process.env.BGREMOVE_MAX_DAILY_USES,
//20250328新增 ppt api
docmeeUrl: process.env.DOCMEE_URL,
docmeeApiKey: process.env.DOCMEE_API_KEY ?? "",
... ...
... ... @@ -81,7 +81,6 @@ export enum ApiPath {
ZuoTang = "/api/tasks",
Docmee = "/api/ppt",
OpenAiImg = "/api/v1",
TencentCos = "/api/cos",
}
///api/tasks/visual/segmentation
//api/tasks/visual/segmentation/{task_id}
... ...