重构:将 "lobster" 重命名为 "claw" 并添加国际化支持 (i18n)
This commit is contained in:
@@ -1,10 +1,10 @@
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
import { nanoid } from "nanoid";
|
||||
import { db } from "@/lib/db";
|
||||
import { lobsters } from "@/lib/db/schema";
|
||||
import { claws } from "@/lib/db/schema";
|
||||
import {
|
||||
setLobsterOnline,
|
||||
updateActiveLobsters,
|
||||
setClawOnline,
|
||||
updateActiveClaws,
|
||||
incrementGlobalStat,
|
||||
incrementRegionCount,
|
||||
publishEvent,
|
||||
@@ -33,14 +33,14 @@ export async function POST(req: NextRequest) {
|
||||
}
|
||||
|
||||
const { name, model, platform } = parsed.data;
|
||||
const lobsterId = nanoid(21);
|
||||
const clawId = nanoid(21);
|
||||
const apiKey = generateApiKey();
|
||||
const clientIp = getClientIp(req);
|
||||
const geo = await getGeoLocation(clientIp);
|
||||
const now = new Date();
|
||||
|
||||
await db.insert(lobsters).values({
|
||||
id: lobsterId,
|
||||
await db.insert(claws).values({
|
||||
id: clawId,
|
||||
apiKey,
|
||||
name,
|
||||
model: model ?? null,
|
||||
@@ -58,9 +58,9 @@ export async function POST(req: NextRequest) {
|
||||
updatedAt: now,
|
||||
});
|
||||
|
||||
await setLobsterOnline(lobsterId, clientIp);
|
||||
await updateActiveLobsters(lobsterId);
|
||||
await incrementGlobalStat("total_lobsters");
|
||||
await setClawOnline(clawId, clientIp);
|
||||
await updateActiveClaws(clawId);
|
||||
await incrementGlobalStat("total_claws");
|
||||
|
||||
if (geo?.region) {
|
||||
await incrementRegionCount(geo.region);
|
||||
@@ -68,14 +68,14 @@ export async function POST(req: NextRequest) {
|
||||
|
||||
await publishEvent({
|
||||
type: "online",
|
||||
lobsterId,
|
||||
lobsterName: name,
|
||||
clawId,
|
||||
clawName: name,
|
||||
city: geo?.city ?? null,
|
||||
country: geo?.country ?? null,
|
||||
});
|
||||
|
||||
return NextResponse.json({
|
||||
lobsterId,
|
||||
clawId,
|
||||
apiKey,
|
||||
endpoint: `${process.env.NEXT_PUBLIC_APP_URL}/api/v1`,
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user