diff --git a/Dockerfile b/Dockerfile index f1ef956..19b298d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -35,7 +35,7 @@ RUN find ./src -type f -name "route.ts" -print0 \ ENV DOCKER_ENV=true # 海报走站内 /api/image-proxy(浏览器直连豆瓣图被拦导致全裂) ENV NEXT_PUBLIC_IMAGE_PROXY=/api/image-proxy -ENV NEXT_PUBLIC_SITE_VERSION=fixed119 +ENV NEXT_PUBLIC_SITE_VERSION=fixed120 ENV NEXT_PUBLIC_ENABLE_REGISTER=true # For Docker builds, force dynamic rendering to read runtime environment variables. @@ -56,7 +56,7 @@ ENV HOSTNAME=0.0.0.0 ENV PORT=3000 ENV DOCKER_ENV=true ENV NEXT_PUBLIC_IMAGE_PROXY=/api/image-proxy -ENV NEXT_PUBLIC_SITE_VERSION=fixed119 +ENV NEXT_PUBLIC_SITE_VERSION=fixed120 ENV NEXT_PUBLIC_ENABLE_REGISTER=true # 从构建器中复制 standalone 输出 diff --git a/src/components/HkDramaRow.tsx b/src/components/HkDramaRow.tsx index 1af93ee..19fb41e 100644 --- a/src/components/HkDramaRow.tsx +++ b/src/components/HkDramaRow.tsx @@ -23,7 +23,22 @@ export default function HkDramaRow() { const [loading, setLoading] = useState(true); useEffect(() => { - fetch('/api/tvbox/all?ac=videolist&t=902&pg=1&by=time') + const CACHE_KEY = 'hkDramaRow:v1'; + const TTL = 5 * 60 * 1000; + try { + const raw = sessionStorage.getItem(CACHE_KEY); + if (raw) { + const { ts, data } = JSON.parse(raw); + if (Date.now() - ts < TTL && Array.isArray(data)) { + setItems(data); + setLoading(false); + return; + } + } + } catch {} + const ctrl = new AbortController(); + const timer = setTimeout(() => ctrl.abort(), 12000); + fetch('/api/tvbox/all?ac=videolist&t=902&pg=1&by=time', { signal: ctrl.signal }) .then((r) => r.json()) .then((j) => { const arr = (((j && j.list) as VodItem[]) || []).slice(); @@ -35,10 +50,22 @@ export default function HkDramaRow() { String(a.vod_time || '') ); }); - setItems(arr.slice(0, SHOW_COUNT)); + const out = arr.slice(0, SHOW_COUNT); + setItems(out); + try { sessionStorage.setItem(CACHE_KEY, JSON.stringify({ ts: Date.now(), data: out })); } catch {} }) - .catch(() => {}) - .finally(() => setLoading(false)); + .catch(() => { + // 失败兜底:尝试用过期缓存 + try { + const raw = sessionStorage.getItem(CACHE_KEY); + if (raw) { + const { data } = JSON.parse(raw); + if (Array.isArray(data)) setItems(data); + } + } catch {} + }) + .finally(() => { clearTimeout(timer); setLoading(false); }); + return () => { clearTimeout(timer); ctrl.abort(); }; }, []); // 加载失败且无数据时不占位;加载中显示骨架占位,与其它栏目同时出现