diff --git a/src/app/api/room/[id]/join/route.ts b/src/app/api/room/[id]/join/route.ts index 230357e..7f7c96b 100644 --- a/src/app/api/room/[id]/join/route.ts +++ b/src/app/api/room/[id]/join/route.ts @@ -22,12 +22,7 @@ export const POST = apiHandler(async (req, { params }) => { return data; }); - if (!updated) { - return NextResponse.json( - { error: "房间不存在或已过期" }, - { status: 404 }, - ); - } + if (!updated) throw new ApiError("房间不存在或已过期", 404); notify(id); diff --git a/src/app/api/room/[id]/manage/route.ts b/src/app/api/room/[id]/manage/route.ts index b2b76b3..a806676 100644 --- a/src/app/api/room/[id]/manage/route.ts +++ b/src/app/api/room/[id]/manage/route.ts @@ -59,12 +59,7 @@ export const POST = apiHandler(async (req, { params }) => { return data; }); - if (!updated) { - return NextResponse.json( - { error: "房间不存在或已过期" }, - { status: 404 }, - ); - } + if (!updated) throw new ApiError("房间不存在或已过期", 404); notify(id); diff --git a/src/app/api/room/[id]/reset/route.ts b/src/app/api/room/[id]/reset/route.ts index e02a9d2..1570906 100644 --- a/src/app/api/room/[id]/reset/route.ts +++ b/src/app/api/room/[id]/reset/route.ts @@ -1,7 +1,7 @@ import { NextResponse } from "next/server"; import { atomicUpdateRoom } from "@/lib/store"; import { notify } from "@/lib/roomEvents"; -import { apiHandler } from "@/lib/api"; +import { apiHandler, ApiError } from "@/lib/api"; export const POST = apiHandler(async (req, { params }) => { const { id } = await params; @@ -27,12 +27,7 @@ export const POST = apiHandler(async (req, { params }) => { return data; }); - if (!updated) { - return NextResponse.json( - { error: "房间不存在或已过期" }, - { status: 404 }, - ); - } + if (!updated) throw new ApiError("房间不存在或已过期", 404); notify(id); diff --git a/src/app/api/room/[id]/route.ts b/src/app/api/room/[id]/route.ts index c7a309d..cda1d39 100644 --- a/src/app/api/room/[id]/route.ts +++ b/src/app/api/room/[id]/route.ts @@ -1,18 +1,12 @@ import { NextResponse } from "next/server"; import { buildRoomStatus } from "@/lib/buildRoomStatus"; -import { apiHandler } from "@/lib/api"; +import { apiHandler, ApiError } from "@/lib/api"; export const GET = apiHandler(async (_req, { params }) => { const { id } = await params; const status = await buildRoomStatus(id); - - if (!status) { - return NextResponse.json( - { error: "房间不存在或已过期" }, - { status: 404 }, - ); - } + if (!status) throw new ApiError("房间不存在或已过期", 404); return NextResponse.json(status); }); diff --git a/src/app/api/room/[id]/swipe/route.ts b/src/app/api/room/[id]/swipe/route.ts index 835368e..bc5325c 100644 --- a/src/app/api/room/[id]/swipe/route.ts +++ b/src/app/api/room/[id]/swipe/route.ts @@ -40,12 +40,7 @@ export const POST = apiHandler(async (req, { params }) => { return data; }); - if (!updated) { - return NextResponse.json( - { error: "房间不存在或已过期" }, - { status: 404 }, - ); - } + if (!updated) throw new ApiError("房间不存在或已过期", 404); notify(id); diff --git a/src/app/api/room/[id]/undo/route.ts b/src/app/api/room/[id]/undo/route.ts index f493849..92273a4 100644 --- a/src/app/api/room/[id]/undo/route.ts +++ b/src/app/api/room/[id]/undo/route.ts @@ -32,12 +32,7 @@ export const POST = apiHandler(async (req, { params }) => { return data; }); - if (!updated) { - return NextResponse.json( - { error: "房间不存在或已过期" }, - { status: 404 }, - ); - } + if (!updated) throw new ApiError("房间不存在或已过期", 404); notify(id); diff --git a/src/app/api/room/create/route.ts b/src/app/api/room/create/route.ts index 37d12f3..e0cfe35 100644 --- a/src/app/api/room/create/route.ts +++ b/src/app/api/room/create/route.ts @@ -150,12 +150,7 @@ export const POST = apiHandler(async (req) => { restaurants = results.slice(0, 15); } - if (restaurants.length === 0) { - return NextResponse.json( - { error: sceneConfig.emptyError }, - { status: 404 }, - ); - } + if (restaurants.length === 0) throw new ApiError(sceneConfig.emptyError, 404); const roomId = await createRoom(restaurants, userId, sceneConfig.key); return NextResponse.json({ roomId, restaurants }); diff --git a/src/app/profile/page.tsx b/src/app/profile/page.tsx index d8a0500..f9d0b7d 100644 --- a/src/app/profile/page.tsx +++ b/src/app/profile/page.tsx @@ -29,6 +29,7 @@ import RestaurantImage from "@/components/RestaurantImage"; import { ProfileCardSkeleton, RecordItemSkeleton } from "@/components/Skeleton"; import { getUserId, getCachedProfile, setCachedProfile, setCachedPreferences, logout } from "@/lib/userId"; import { getAvatarBg, AVATARS } from "@/lib/avatars"; +import { buildNavUrl } from "@/lib/navigation"; import type { UserProfile, UserPreferences, DecisionRecord, FavoriteRecord, Restaurant } from "@/types"; function firstImage(r: Restaurant): string { @@ -279,10 +280,6 @@ export default function ProfilePage() { if (!profile) return null; - const amapNavUrl = (r: Restaurant) => - r.location - ? `https://uri.amap.com/marker?position=${r.location}&name=${encodeURIComponent(r.name)}&callnative=1` - : `https://www.google.com/maps/search/?api=1&query=${encodeURIComponent(r.name)}`; return (
@@ -567,7 +564,7 @@ export default function ProfilePage() { {history.map((d) => (