mirror of
https://github.com/ChatGPTNextWeb/ChatGPT-Next-Web.git
synced 2025-10-01 23:56:39 +08:00
39 lines
999 B
TypeScript
39 lines
999 B
TypeScript
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;
|
|
}
|
|
|
|
async function handle(
|
|
req: NextRequest,
|
|
{ params }: { params: { path: string[] } },
|
|
) {
|
|
try {
|
|
const request_data = await req.json();
|
|
if (request_data?.userName) {
|
|
await insertUser({ name: request_data?.userName });
|
|
}
|
|
// console.log("===========4", request_data);
|
|
await prisma.logEntry.create({
|
|
data: cleanObjectKeys(request_data),
|
|
});
|
|
} catch (e) {
|
|
return NextResponse.json({ status: 0 });
|
|
// console.log("[LOG]", e);
|
|
}
|
|
|
|
return NextResponse.json({ status: 1 });
|
|
}
|
|
export const GET = handle;
|
|
export const POST = handle;
|
|
|
|
// export const runtime = "edge";
|