From f7a532137a3d98e2c0d6fde376387325455f5444 Mon Sep 17 00:00:00 2001
From: log
Date: Tue, 23 Jun 2026 21:10:10 +0800
Subject: [PATCH] fix: prevent browser caching of config and models APIs
---
video-claw/video-claw/backend/api/routers/configuration.py | 5 +++--
video-claw/video-claw/frontend/lib/workflowApi.ts | 2 +-
video-claw/video-claw/frontend/components/HomePage.tsx | 4 ++--
video-claw/video-claw/backend/api/routers/pipelines.py | 4 +++-
video-claw/video-claw/frontend/app/settings/page.tsx | 2 +-
5 files changed, 10 insertions(+), 7 deletions(-)
diff --git a/video-claw/video-claw/backend/api/routers/configuration.py b/video-claw/video-claw/backend/api/routers/configuration.py
index 156d789..0f96c1b 100644
--- a/video-claw/video-claw/backend/api/routers/configuration.py
+++ b/video-claw/video-claw/backend/api/routers/configuration.py
@@ -1,6 +1,6 @@
from typing import Any, Dict
-from fastapi import APIRouter
+from fastapi import APIRouter, Response
from pydantic import BaseModel, Field
from api.logging_config import apply_access_log_setting, apply_log_level_setting
@@ -14,7 +14,8 @@
@router.get("/api/config")
-async def get_config():
+async def get_config(response: Response):
+ response.headers["Cache-Control"] = "no-cache, no-store, must-revalidate"
return {
"config": Config.as_dict(),
"path": str(CONFIG_PATH),
diff --git a/video-claw/video-claw/backend/api/routers/pipelines.py b/video-claw/video-claw/backend/api/routers/pipelines.py
index eb75e0e..77851b6 100644
--- a/video-claw/video-claw/backend/api/routers/pipelines.py
+++ b/video-claw/video-claw/backend/api/routers/pipelines.py
@@ -5,7 +5,7 @@
from urllib.parse import quote
from typing import Optional
-from fastapi import APIRouter, BackgroundTasks, HTTPException, Query
+from fastapi import APIRouter, BackgroundTasks, HTTPException, Query, Response
from fastapi.responses import HTMLResponse, StreamingResponse
from api.schemas.pipelines import (
@@ -149,11 +149,13 @@
@router.get("/api/models")
async def get_api_models(
+ response: Response,
media_type: Optional[str] = Query(None, pattern="^(image|video)$"),
model_type: Optional[str] = Query(None, pattern="^(llm|vlm|t2i|i2i|video)$"),
ability: Optional[str] = Query(None),
verified_only: bool = False,
):
+ response.headers["Cache-Control"] = "no-cache, no-store, must-revalidate"
if model_type:
models = []
for model in get_models_by_type(model_type):
diff --git a/video-claw/video-claw/frontend/app/settings/page.tsx b/video-claw/video-claw/frontend/app/settings/page.tsx
index 084f5a2..6a55f9e 100644
--- a/video-claw/video-claw/frontend/app/settings/page.tsx
+++ b/video-claw/video-claw/frontend/app/settings/page.tsx
@@ -202,7 +202,7 @@
setLoading(true);
setError('');
try {
- const resp = await fetch('/api/config');
+ const resp = await fetch('/api/config', { cache: 'no-store' });
if (!resp.ok) throw new Error('读取配置失败');
const data = await resp.json();
setConfig(data.config || {});
diff --git a/video-claw/video-claw/frontend/components/HomePage.tsx b/video-claw/video-claw/frontend/components/HomePage.tsx
index 1cadbaf..577e452 100644
--- a/video-claw/video-claw/frontend/components/HomePage.tsx
+++ b/video-claw/video-claw/frontend/components/HomePage.tsx
@@ -1,4 +1,4 @@
-'use client';
+'use client';
import React, { useState, useRef, useEffect } from 'react';
import { Sparkles, Play, Settings2, Clock, ArrowRight, Zap, CheckCircle, Trash2, X, Lock, Globe, ListOrdered, Upload, Loader2 } from 'lucide-react';
@@ -145,7 +145,7 @@
setConfigLoading(true);
setConfigError('');
try {
- const resp = await fetch('/api/config');
+ const resp = await fetch('/api/config', { cache: 'no-store' });
if (!resp.ok) throw new Error('读取默认模型配置失败');
const data = await resp.json();
const models = data.config?.models || {};
diff --git a/video-claw/video-claw/frontend/lib/workflowApi.ts b/video-claw/video-claw/frontend/lib/workflowApi.ts
index 86219d3..65290d1 100644
--- a/video-claw/video-claw/frontend/lib/workflowApi.ts
+++ b/video-claw/video-claw/frontend/lib/workflowApi.ts
@@ -195,7 +195,7 @@
if (params.modelType) search.set('model_type', params.modelType);
if (params.ability) search.set('ability', params.ability);
if (params.verifiedOnly) search.set('verified_only', 'true');
- const resp = await fetch(`/api/models${search.toString() ? `?${search.toString()}` : ''}`);
+ const resp = await fetch(`/api/models${search.toString() ? `?${search.toString()}` : ''}`, { cache: 'no-store' });
if (!resp.ok) throw new Error('获取模型列表失败');
const data = await resp.json();
return data.models || [];
--
Gitblit v1.8.0