From b0e56e17c7f3cd99dac5d9598aa19015d1fe256c Mon Sep 17 00:00:00 2001 From: sijinhui Date: Thu, 28 Dec 2023 13:22:09 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=B0=8F=E7=BB=86=E8=8A=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Dockerfile | 1 + app/api/logs/[...path]/route.ts | 16 ++++++++++------ app/api/openai/[...path]/route.ts | 3 ++- app/app/(admin)/admin/usage-by-model.tsx | 18 ++++++++++-------- 4 files changed, 23 insertions(+), 15 deletions(-) diff --git a/Dockerfile b/Dockerfile index 16c0e3bb8..957063c46 100644 --- a/Dockerfile +++ b/Dockerfile @@ -52,6 +52,7 @@ RUN rm -f .env EXPOSE 3000 ENV KEEP_ALIVE_TIMEOUT=30 +ENV HOSTNAME="" CMD if [ -n "$PROXY_URL" ]; then \ export HOSTNAME="127.0.0.1"; \ diff --git a/app/api/logs/[...path]/route.ts b/app/api/logs/[...path]/route.ts index accf77036..b2cc5b584 100644 --- a/app/api/logs/[...path]/route.ts +++ b/app/api/logs/[...path]/route.ts @@ -13,13 +13,17 @@ async function handle( await insertUser({ name: request_data?.userName }); } // console.log("===========4", request_data); - if (request_data?.logEntry) { - const regex = /\[(.*)]/g; - const matchResponse = request_data.logEntry.match(regex); - if (matchResponse.length > 0) { - request_data.logToken = getTokenLength(matchResponse[0]); + try { + if (request_data?.logEntry) { + const regex = /\[(.*)]/g; + const matchResponse = request_data.logEntry.match(regex); + if (matchResponse.length > 0) { + request_data.logToken = getTokenLength(matchResponse[0]); + } } - // console.log('=======', request_data.logEntry, '=====', matchResponse); + } catch (e) { + console.log("[LOG]", "logToken", e); + request_data.logToken = 0; } await prisma.logEntry.create({ diff --git a/app/api/openai/[...path]/route.ts b/app/api/openai/[...path]/route.ts index e153138aa..8885baf97 100644 --- a/app/api/openai/[...path]/route.ts +++ b/app/api/openai/[...path]/route.ts @@ -77,7 +77,8 @@ async function handle( try { const protocol = req.headers.get("x-forwarded-proto") || "http"; - const baseUrl = process.env.NEXTAUTH_URL ?? "http://localhost:3000"; + //const baseUrl = process.env.NEXTAUTH_URL ?? "http://localhost:3000"; + const baseUrl = "http://localhost:3000"; const ip = getIP(req); // 对其进行 Base64 解码 let h_userName = req.headers.get("x-request-name"); diff --git a/app/app/(admin)/admin/usage-by-model.tsx b/app/app/(admin)/admin/usage-by-model.tsx index dfcbd8d54..a3495eec0 100644 --- a/app/app/(admin)/admin/usage-by-model.tsx +++ b/app/app/(admin)/admin/usage-by-model.tsx @@ -65,14 +65,16 @@ export default async function UsageByModel() { 0, 0, ); - const endOfTheDayInTimeZone = new Date( - today.getFullYear(), - today.getMonth(), - today.getDate(), - 23, - 59, - 59, - ); // 当天的结束时间 + // const endOfTheDayInTimeZone = new Date( + // today.getFullYear(), + // today.getMonth(), + // today.getDate(), + // 23, + // 59, + // 59, + // ); // 当天的结束时间 + const endOfTheDayInTimeZone = addHours(startOfTheDayInTimeZone, +24); // 当天的结束时间 + // const startDate = addHours(startOfTheDayInTimeZone, -8); // const endDate = addHours(endOfTheDayInTimeZone, -8); console.log("===", today, startOfTheDayInTimeZone, endOfTheDayInTimeZone);