fix: prevent browser caching of config and models APIs
| | |
| | | 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 |
| | |
| | | |
| | | |
| | | @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), |
| | |
| | | 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 ( |
| | |
| | | |
| | | @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): |
| | |
| | | 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 || {}); |
| | |
| | | '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'; |
| | |
| | | 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 || {}; |
| | |
| | | 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 || []; |