更新 CLAUDE.md,清理死 import,图表与 API 细节调整

This commit is contained in:
2569718930@qq.com
2026-05-25 07:52:31 +08:00
parent e6d24c308f
commit 7273891794
5 changed files with 615 additions and 238 deletions
+55 -9
View File
@@ -1,9 +1,35 @@
import { NextRequest, NextResponse } from "next/server";
import { proxyBackendJsonGet } from "@/lib/api-proxy";
import {
applyAuthResponseCookies,
buildBackendRequestHeaders,
} from "@/lib/backend-auth";
import {
buildProxyExceptionResponse,
buildUpstreamErrorResponse,
} from "@/lib/api-proxy";
import { buildCachedJsonResponse } from "@/lib/http-cache";
import { buildCityDetailProxyCachePolicy } from "@/lib/proxy-cache-policy";
const API_BASE = process.env.POLYWEATHER_API_BASE_URL;
function normalizeCityDetailPayload(data: unknown) {
if (!data || typeof data !== "object") return data;
const payload = data as Record<string, any>;
// Backend v2 nests hourly under timeseries; chart expects it at top level.
if (!payload.hourly && payload.timeseries?.hourly) {
payload.hourly = payload.timeseries.hourly;
}
if (!payload.market_scan && payload.market_scan_payload) {
return {
...payload,
market_scan: payload.market_scan_payload,
};
}
return payload;
}
export async function GET(
req: NextRequest,
context: { params: Promise<{ name: string }> },
@@ -36,12 +62,32 @@ export async function GET(
}
const url = `${API_BASE}/api/city/${encodeURIComponent(name)}/detail?${searchParams.toString()}`;
return proxyBackendJsonGet(req, {
cacheControl: cachePolicy.responseCacheControl,
fetchCache:
cachePolicy.fetchMode === "no-store" ? "no-store" : undefined,
publicMessage: "Failed to fetch city detail aggregate",
revalidateSeconds: cachePolicy.revalidateSeconds,
url,
});
try {
const auth = await buildBackendRequestHeaders(req, {
includeSupabaseIdentity: false,
});
const res = await fetch(url, {
headers: auth.headers,
...(cachePolicy.fetchMode === "no-store"
? { cache: "no-store" as const }
: { next: { revalidate: cachePolicy.revalidateSeconds ?? 15 } }),
});
if (!res.ok) {
const raw = await res.text();
const response = buildUpstreamErrorResponse(res.status, raw);
return applyAuthResponseCookies(response, auth.response);
}
const data = normalizeCityDetailPayload(await res.json());
const response = buildCachedJsonResponse(
req,
data,
cachePolicy.responseCacheControl,
);
return applyAuthResponseCookies(response, auth.response);
} catch (error) {
const response = buildProxyExceptionResponse(error, {
publicMessage: "Failed to fetch city detail aggregate",
});
return response;
}
}