重构:将 "lobster" 重命名为 "claw" 并添加国际化支持 (i18n)
This commit is contained in:
@@ -1,10 +1,10 @@
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
import { eq } from "drizzle-orm";
|
||||
import { db } from "@/lib/db";
|
||||
import { lobsters, heartbeats } from "@/lib/db/schema";
|
||||
import { claws, heartbeats } from "@/lib/db/schema";
|
||||
import {
|
||||
setLobsterOnline,
|
||||
updateActiveLobsters,
|
||||
setClawOnline,
|
||||
updateActiveClaws,
|
||||
incrementHourlyActivity,
|
||||
publishEvent,
|
||||
} from "@/lib/redis";
|
||||
@@ -31,8 +31,8 @@ export async function POST(req: NextRequest) {
|
||||
}
|
||||
|
||||
const apiKey = authHeader.slice(7);
|
||||
const lobster = await validateApiKey(apiKey);
|
||||
if (!lobster) {
|
||||
const claw = await validateApiKey(apiKey);
|
||||
if (!claw) {
|
||||
return NextResponse.json({ error: "Invalid API key" }, { status: 401 });
|
||||
}
|
||||
|
||||
@@ -61,7 +61,7 @@ export async function POST(req: NextRequest) {
|
||||
updatedAt: now,
|
||||
};
|
||||
|
||||
if (clientIp !== lobster.ip) {
|
||||
if (clientIp !== claw.ip) {
|
||||
const geo = await getGeoLocation(clientIp);
|
||||
if (geo) {
|
||||
updateFields.latitude = String(geo.latitude);
|
||||
@@ -77,27 +77,27 @@ export async function POST(req: NextRequest) {
|
||||
if (parsed.data.model) updateFields.model = parsed.data.model;
|
||||
if (parsed.data.platform) updateFields.platform = parsed.data.platform;
|
||||
|
||||
await setLobsterOnline(lobster.id, clientIp);
|
||||
await updateActiveLobsters(lobster.id);
|
||||
await setClawOnline(claw.id, clientIp);
|
||||
await updateActiveClaws(claw.id);
|
||||
await incrementHourlyActivity();
|
||||
|
||||
await db
|
||||
.update(lobsters)
|
||||
.update(claws)
|
||||
.set(updateFields)
|
||||
.where(eq(lobsters.id, lobster.id));
|
||||
.where(eq(claws.id, claw.id));
|
||||
|
||||
// Insert heartbeat record asynchronously
|
||||
db.insert(heartbeats)
|
||||
.values({ lobsterId: lobster.id, ip: clientIp, timestamp: now })
|
||||
.values({ clawId: claw.id, ip: clientIp, timestamp: now })
|
||||
.then(() => {})
|
||||
.catch((err: unknown) => console.error("Failed to insert heartbeat:", err));
|
||||
|
||||
await publishEvent({
|
||||
type: "heartbeat",
|
||||
lobsterId: lobster.id,
|
||||
lobsterName: (updateFields.name as string) ?? lobster.name,
|
||||
city: (updateFields.city as string) ?? lobster.city,
|
||||
country: (updateFields.country as string) ?? lobster.country,
|
||||
clawId: claw.id,
|
||||
clawName: (updateFields.name as string) ?? claw.name,
|
||||
city: (updateFields.city as string) ?? claw.city,
|
||||
country: (updateFields.country as string) ?? claw.country,
|
||||
});
|
||||
|
||||
return NextResponse.json({ ok: true, nextIn: 180 });
|
||||
|
||||
Reference in New Issue
Block a user