feat: implement scan terminal dashboard with AI-driven city analysis and state management

This commit is contained in:
2569718930@qq.com
2026-04-26 03:42:13 +08:00
parent d71d5979e1
commit ce0f7629a2
7 changed files with 133 additions and 152 deletions
+17 -13
View File
@@ -62,7 +62,7 @@ export type AssistantChatResponse = {
};
const CACHE_KEY = "polyWeather_v1";
const CACHE_TTL_MS = 5 * 60 * 1000;
const CACHE_TTL_MS = 30 * 60 * 1000;
const SCAN_TERMINAL_CLIENT_TIMEOUT_MS = 35_000;
const pendingCityDetailRequests = new Map<string, Promise<CityDetail>>();
const pendingHistoryRequests = new Map<string, Promise<HistoryPayload>>();
@@ -244,16 +244,18 @@ function readLegacyCache(raw: string): CityCacheBundle {
};
const details = parsed.data || {};
const cachedAt = parsed.timestamp || 0;
const meta = Object.fromEntries(
Object.entries(details).map(([cityName, detail]) => [
cityName,
{
cachedAt,
revision: getCityRevision(detail),
},
]),
);
return { details, meta };
const freshDetails: Record<string, CityDetail> = {};
const meta: Record<string, CityCacheMeta> = {};
Object.entries(details).forEach(([cityName, detail]) => {
const nextMeta = {
cachedAt,
revision: getCityRevision(detail),
};
if (!isFresh(nextMeta)) return;
freshDetails[cityName] = detail;
meta[cityName] = nextMeta;
});
return { details: freshDetails, meta };
}
export const dashboardClient = {
@@ -606,11 +608,13 @@ export const dashboardClient = {
const meta: Record<string, CityCacheMeta> = {};
Object.entries(parsed.entries).forEach(([cityName, entry]) => {
if (!entry?.detail) return;
details[cityName] = entry.detail;
meta[cityName] = {
const nextMeta = {
cachedAt: entry.cachedAt || 0,
revision: entry.revision || getCityRevision(entry.detail),
};
if (!isFresh(nextMeta)) return;
details[cityName] = entry.detail;
meta[cityName] = nextMeta;
});
return { details, meta };
}