From 4f1b7c341c04d5196e69a9cdbbe4f37611878f93 Mon Sep 17 00:00:00 2001 From: hz4th_coder Date: Fri, 11 Sep 2026 23:00:03 +0800 Subject: [PATCH] =?UTF-8?q?v1.9.1=20=E7=BC=93=E5=AD=98=E6=97=B6=E6=95=88?= =?UTF-8?q?=E8=AE=BE=E7=BD=AE=E5=85=A5=E5=8F=A3=E6=98=BE=E7=9C=BC=E5=8C=96?= =?UTF-8?q?=20+=20API=E6=94=AF=E6=8C=81per-request=E7=BC=93=E5=AD=98?= =?UTF-8?q?=E5=8F=82=E6=95=B0=20+=20=E9=A1=B5=E9=9D=A2API=E8=AF=B4?= =?UTF-8?q?=E6=98=8E=E5=90=8C=E6=AD=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1) 页面可见性: 高级选项区缓存状态行改为可点击「⚙️ 设置时效与开关」按钮(直接打开设置弹窗), 明确设置入口 2) API per-request 缓存参数: - cache_ttl_seconds: 本次请求缓存时效(秒), 覆盖全局有效期, 命中判定也用它 - cache: false / no_cache: true: 本次请求禁用缓存 (refresh=true 强制刷新已有) 3) 页面API调用说明段完整同步: refresh/cache/cache_ttl_seconds 参数注释 + POST /api/capture/settings 请求示例 + 缓存命中响应字段说明 验证: cache_ttl_seconds=3600命中历史并回显TTL / =1超期走实时 / cache:false禁用缓存走实时 --- app.py | 12 ++++++++++-- templates/index.html | 24 ++++++++++++++++++++---- 2 files changed, 30 insertions(+), 6 deletions(-) diff --git a/app.py b/app.py index 7a1f560..7f9c38f 100644 --- a/app.py +++ b/app.py @@ -1584,6 +1584,8 @@ def capture(): "url": "https://example.com", "action": "screenshot" | "html" | "text" | "smart", "refresh": false, // 可选:true=强制实时提取(绕过网址缓存) + "cache": true, // 可选:false=本次请求禁用缓存 + "cache_ttl_seconds": 3600, // 可选:本次请求的缓存时效(秒),覆盖全局设置;命中判定也用它 "scroll_times": 0, "scroll_delay": 1000, "full_page": false, @@ -1637,9 +1639,15 @@ def capture(): cache_cfg = settings.get("cache", DEFAULT_CACHE_CONFIG) retry_cfg = settings.get("retry", DEFAULT_RETRY_CONFIG) force_refresh = bool(data.get("refresh") or data.get("force")) + # per-request 缓存参数:cache_ttl_seconds=本次缓存时效(覆盖全局),cache=false / no_cache=true=本次禁用缓存 + no_cache = data.get("cache") is False or str(data.get("no_cache")).lower() in ("true", "1", "yes") + try: + cache_ttl_override = max(1, int(data.get("cache_ttl_seconds"))) if data.get("cache_ttl_seconds") is not None else None + except Exception: + cache_ttl_override = None - if cache_cfg.get("enabled") and not force_refresh: - ttl = int(cache_cfg.get("ttl_seconds", 3600)) + if cache_cfg.get("enabled") and not force_refresh and not no_cache: + ttl = cache_ttl_override or int(cache_cfg.get("ttl_seconds", 3600)) hit = find_cache_hit(url, action, ttl) if hit: hit["from_cache"] = True diff --git a/templates/index.html b/templates/index.html index c71e7fb..baad52a 100644 --- a/templates/index.html +++ b/templates/index.html @@ -627,8 +627,10 @@ 🔄 强制刷新(绕过网址缓存,重新提取) - - 📦 网址缓存已(有效期 ),同网址命中缓存直接返回历史结果,不会重复提取。 + + 📦 网址缓存: | 有效期 +
+ 同网址命中缓存直接返回历史结果,不重复提取;勾选上方「强制刷新」可绕过。
@@ -761,7 +763,6 @@ { "url": "https://example.com", "action": "smart", // "screenshot" | "html" | "text" | "smart" - "refresh": false, // 可选:true=强制实时提取(绕过网址缓存) "wait_time": 15000, // 重要!验证网站需设置较长等待 "scroll_times": 3, // 可选:加载动态内容 "scroll_delay": 1000, // 可选:滚动间隔 @@ -770,6 +771,10 @@ "caller": "news-tracker", // 可选:调用者标识(历史记录里显示,默认游客) "call_method": "api", // 可选:调用方式 web/api(缺省自动判定) "viewport": {"width":1280,"height":700}, + // ---- 📦 网址缓存(默认开启,全局配置在 /api/capture/settings)---- + "refresh": false, // 可选:true=强制实时提取(绕过缓存) + "cache": true, // 可选:false=本次请求禁用缓存 + "cache_ttl_seconds": 3600, // 可选:本次缓存时效(秒),覆盖全局有效期,命中判定也用它 "smart_config": { // 可选:临时覆盖按需截图配置(接口列表按顺序=优先级,失败自动降级) "endpoints": [ {"name":"本地Qwen", "base_url":"http://121.40.164.32:18008/v1", "api_key":"xxxx", "model":"unsloth/Qwen3.8-27B-NVFP4", "enabled":true}, @@ -779,11 +784,22 @@ "scroll_ratio": 0.85 } } +// 缓存命中响应(text/html/smart 为 JSON;screenshot 直接返回历史图片文件): +// {success:true, from_cache:true, history_id:123, cached_at:"2026-09-11 22:49:41", cache_ttl_seconds:3600, ...} + +📦 缓存/🔁 重试全局配置(页面「⚙️ 缓存/重试」按钮或以下接口): +GET /api/capture/settings +POST /api/capture/settings +{ + "settings": { + "cache": {"enabled": true, "ttl_seconds": 3600}, // enabled=缓存开关, ttl_seconds=有效期(秒) + "retry": {"max_retries": 2, "delay_seconds": 2} // max_retries=失败重试次数(默认2), delay_seconds=重试间隔(秒) + } +} GET /api/smart/config // 获取智能截图配置(含 endpoints 多接口列表) POST /api/smart/config // 保存配置(body: {config:{endpoints:[...], prompt, max_scrolls,...}}) POST /api/smart/test // 测试指定接口(body: {endpoint_id} 或 {endpoint:{...}} 或旧版 {config:{...}}) -GET /api/capture/settings // 网址缓存+失败重试 配置({cache:{enabled,ttl_seconds}, retry:{max_retries,delay_seconds}}) GET /api/history?page=1&page_size=15&action=all&search=关键词 // 历史分页 GET /api/history/stats?dimension=day&days=30 // 历史统计(dimension: day/action/backend/status/caller/method) GET /api/history/<id> // 历史详情