diff --git a/app/api/logs/[...path]/route.ts b/app/api/logs/[...path]/route.ts index 2e1f1fc77..9fccab3d7 100644 --- a/app/api/logs/[...path]/route.ts +++ b/app/api/logs/[...path]/route.ts @@ -2,15 +2,16 @@ import { NextRequest, NextResponse } from "next/server"; import prisma from "@/lib/prisma"; import { insertUser } from "@/lib/auth"; -function cleanObjectKeys(input: { [key: string]: string }): { - [key: string]: string; -} { - const cleanedObj: { [key: string]: string } = {}; - Object.keys(input).forEach((key) => { - cleanedObj[key] = input[key].trim(); - }); - return cleanedObj; -} +// function cleanObjectKeys(input: { [key: string]: string }): { +// [key: string]: string; +// } { +// const cleanedObj: { [key: string]: string } = {}; +// Object.keys(input).forEach((key) => { +// cleanedObj[key] = input[key].trim(); +// }); +// console.log('========', input, cleanedObj) +// return cleanedObj; +// } async function handle( req: NextRequest, @@ -23,7 +24,7 @@ async function handle( } // console.log("===========4", request_data); await prisma.logEntry.create({ - data: cleanObjectKeys(request_data), + data: request_data, }); } catch (e) { return NextResponse.json({ status: 0 }); diff --git a/app/app/(admin)/admin/usage-analysis.tsx b/app/app/(admin)/admin/usage-analysis.tsx index e43c3ccfd..345d49652 100644 --- a/app/app/(admin)/admin/usage-analysis.tsx +++ b/app/app/(admin)/admin/usage-analysis.tsx @@ -1,6 +1,38 @@ // "use client"; import { BarList, Bold, Card, Flex, Text, Title } from "@tremor/react"; import prisma from "@/lib/prisma"; +import { estimateTokenLength } from "@/app/utils/token"; + +function HandleLogData(todayLog: [{ userName: string; logEntry: string }]) { + const data1 = todayLog.map((log) => { + return { + name: log.userName ?? "unknown", + value: estimateTokenLength(log.logEntry ?? ""), + }; + }); + + type Accumulator = { + [key: string]: number; + }; + const data2 = data1.reduce((acc, item) => { + if (acc[item.name]) { + acc[item.name] += item.value; + } else { + acc[item.name] = item.value; + } + return acc; + }, {}); + const data3 = Object.entries(data2) + .map(([name, value]) => ({ + name, + value, + })) + .sort((a, b) => { + return b.value - a.value; + }); + return data3; +} + export default async function UsageAnalysis() { // 今天日期的开始和结束 const startDate = new Date(); @@ -8,7 +40,6 @@ export default async function UsageAnalysis() { const endDate = new Date(); endDate.setHours(23, 59, 59, 999); - const todayLog = await prisma.logEntry.findMany({ where: { createdAt: { @@ -16,106 +47,113 @@ export default async function UsageAnalysis() { lte: endDate, // lte 表示 '小于等于' }, }, + include: { + user: true, + }, }); - console.log("======", todayLog); - const data = [ - { - name: "Twitter", - value: 456, - href: "https://twitter.com/tremorlabs", - icon: function TwitterIcon() { - return ( - - - - - ); - }, - }, - { - name: "Google", - value: 351, - href: "https://google.com", - icon: function GoogleIcon() { - return ( - - - - - ); - }, - }, - { - name: "GitHub", - value: 271, - href: "https://github.com/tremorlabs/tremor", - icon: function GitHubIcon() { - return ( - - - - - ); - }, - }, - { - name: "Reddit", - value: 191, - href: "https://reddit.com", - icon: function RedditIcon() { - return ( - - - - - ); - }, - }, - { - name: "Youtube", - value: 91, - href: "https://www.youtube.com/@tremorlabs3079", - icon: function YouTubeIcon() { - return ( - - - - - ); - }, - }, - ]; + // @ts-ignore + const log_data = HandleLogData(todayLog); + // console.log("======", log_data); + + // const data = [ + // { + // name: "Twitter", + // value: 456, + // href: "https://twitter.com/tremorlabs", + // icon: function TwitterIcon() { + // return ( + // + // + // + // + // ); + // }, + // }, + // { + // name: "Google", + // value: 351, + // href: "https://google.com", + // icon: function GoogleIcon() { + // return ( + // + // + // + // + // ); + // }, + // }, + // { + // name: "GitHub", + // value: 271, + // href: "https://github.com/tremorlabs/tremor", + // icon: function GitHubIcon() { + // return ( + // + // + // + // + // ); + // }, + // }, + // { + // name: "Reddit", + // value: 191, + // href: "https://reddit.com", + // icon: function RedditIcon() { + // return ( + // + // + // + // + // ); + // }, + // }, + // { + // name: "Youtube", + // value: 91, + // href: "https://www.youtube.com/@tremorlabs3079", + // icon: function YouTubeIcon() { + // return ( + // + // + // + // + // ); + // }, + // }, + // ]; + // @ts-ignore return ( Website Analytics @@ -127,7 +165,7 @@ export default async function UsageAnalysis() { Visits - + ); } diff --git a/app/constant.ts b/app/constant.ts index 083474014..ae3dae370 100644 --- a/app/constant.ts +++ b/app/constant.ts @@ -92,7 +92,7 @@ Latex inline: $x^2$ Latex block: $$e=mc^2$$ `; -export const SUMMARIZE_MODEL = "gpt-3.5-turbo-16k"; +export const SUMMARIZE_MODEL = "gpt-3.5-turbo-1106"; export const KnowledgeCutOffDate: Record = { default: "2021-09", @@ -133,7 +133,7 @@ export const DEFAULT_MODELS = [ { name: "gpt-4-all", describe: "GPT-4全能版,联网绘图多模态,又慢又贵", - available: true, + available: false, }, // { // name: "gpt-4v", diff --git a/lib/auth.ts b/lib/auth.ts index 234dfa75c..de93680dc 100644 --- a/lib/auth.ts +++ b/lib/auth.ts @@ -251,6 +251,12 @@ function isPinYin(input: string): boolean { export function isName(input: string): boolean { + const denyList = [ + "suibian", + ] + if (denyList.includes(input)) { + return false; + } return isEmail(input) || isHanZi(input) || isPinYin(input); } diff --git a/package.json b/package.json index fabc42e25..2773f3ea2 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,7 @@ "private": false, "license": "mit", "scripts": { - "dev": "npx prisma generate && npx prisma db push && next dev", + "dev": "npx prisma generate && npx prisma db push && next dev", "build": "npx next telemetry disable && npx prisma generate && cross-env BUILD_MODE=standalone next build", "start": "next start", "lint": "next lint", diff --git a/prisma/schema.prisma b/prisma/schema.prisma index 6e388a800..8778db45b 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -65,10 +65,10 @@ model Session { model LogEntry { id Int @id @default(autoincrement()) - ip String? @db.Char(25) + ip String? @db.VarChar(25) path String? @db.Text - model String? @db.Char(25) - userName String? @db.Char(50) + model String? @db.VarChar(25) + userName String? @db.VarChar(50) createdAt DateTime @default(now()) logEntry String? @db.Text user User? @relation(fields: [userName], references: [name], onDelete: NoAction)