feat: 添加 2D/3D 地图切换与坐标偏移功能

- 新增 WorldMap 组件,支持 2D 世界地图视图
- 主页添加 2D/3D 视图切换按钮
- 实现确定性坐标偏移算法,分散同城用户位置
- 更新 heatmap 和 register API 使用坐标偏移
This commit is contained in:
richarjiang
2026-03-15 14:19:36 +08:00
parent 7db59c9290
commit 8d094ad5cc
5 changed files with 513 additions and 102 deletions

View File

@@ -11,6 +11,7 @@ import {
} from "@/lib/redis";
import { generateApiKey } from "@/lib/auth/api-key";
import { getGeoLocation } from "@/lib/geo/ip-location";
import { applyDeterministicOffset } from "@/lib/geo/offset";
import { registerSchema } from "@/lib/validators/schemas";
function getClientIp(req: NextRequest): string {
@@ -39,6 +40,15 @@ export async function POST(req: NextRequest) {
const geo = await getGeoLocation(clientIp);
const now = new Date();
// Apply deterministic offset to spread out users in the same city
let finalLat: number | null = null;
let finalLng: number | null = null;
if (geo) {
const offset = applyDeterministicOffset(geo.latitude, geo.longitude, clawId);
finalLat = offset.lat;
finalLng = offset.lng;
}
await db.insert(claws).values({
id: clawId,
apiKey,
@@ -46,8 +56,8 @@ export async function POST(req: NextRequest) {
model: model ?? null,
platform: platform ?? null,
ip: clientIp,
latitude: geo ? String(geo.latitude) : null,
longitude: geo ? String(geo.longitude) : null,
latitude: finalLat !== null ? String(finalLat) : null,
longitude: finalLng !== null ? String(finalLng) : null,
city: geo?.city ?? null,
country: geo?.country ?? null,
countryCode: geo?.countryCode ?? null,