refactor: 提取 validation.ts 和 amap.ts,统一 API 路由校验逻辑

新增 validation.ts(用户名/密码/邮箱/内容/房间名/必填字段校验)
和 amap.ts(AMAP API key 校验),消除 7 个路由中的重复验证代码。
This commit is contained in:
2026-02-26 19:22:17 +08:00
parent 455b9e04d8
commit 1229bb849b
9 changed files with 80 additions and 41 deletions
+2 -4
View File
@@ -3,6 +3,7 @@ import { createRoom } from "@/lib/store";
import { Restaurant, SceneType } from "@/types";
import { getSceneConfig } from "@/lib/sceneConfig";
import { apiHandler, ApiError } from "@/lib/api";
import { requireAmapApiKey } from "@/lib/amap";
interface AmapPoiV5 {
id: string;
@@ -120,10 +121,7 @@ export const POST = apiHandler(async (req) => {
throw new ApiError("无法获取位置信息,请允许定位权限后重试");
}
const apiKey = process.env.AMAP_API_KEY;
if (!apiKey) {
throw new ApiError("服务配置异常,请稍后重试", 500);
}
const apiKey = requireAmapApiKey();
const url = new URL("https://restapi.amap.com/v5/place/around");
url.searchParams.set("key", apiKey);