docs: 更新 README 與 INFRA.md 記錄 generated_at、SWR 重試、updated badge
- README: /scan response 示例補 generated_at 欄位與說明 - INFRA.md: - 演進紀錄新增 3.12(前端空資料 auto-retry)、3.13(UI 顯示資料更新時間、後端加 generated_at) - 3.12 記錄 webhook pipeline 第一次真實使用(由前端 auto-retry 的 push 觸發) - follow-up 追加 pokemon-radar-api 後端自動部署的想法 Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -92,12 +92,15 @@ Secrets 放 `.env`(gitignore)。本機與生產共用同一份格式、只
|
||||
"ttl": 281,
|
||||
"count_raw": 79,
|
||||
"count_filtered": 24,
|
||||
"generated_at": "2026-04-20T11:14:32+08:00",
|
||||
"items": [ /* id, name, gender, iv_pct, cp, level, latitude, longitude,
|
||||
remaining, expire_at, fast_move, charge_move, is_perfect, ... */ ],
|
||||
"debug": { "notes": [...], "redis_ttl": 281 }
|
||||
}
|
||||
```
|
||||
|
||||
`generated_at` 是 fetcher 寫入 Redis 那份資料時的時間戳(ISO 8601,台北時區)。空資料分支會是 `null`。
|
||||
|
||||
### Redis schema
|
||||
Key `pokemon:radar:latest`,String(JSON),TTL 由 `REDIS_TTL` 控制。Value 結構:
|
||||
```json
|
||||
|
||||
@@ -217,6 +217,32 @@ ALLOWED_HOST_LIST = external,192.168.42.0/24,loopback
|
||||
|
||||
舊 global secret 從 `.env` 遷到 `hooks/pokemon/secret`(沿用原值保持 Gitea 端不用改)。
|
||||
|
||||
### 3.12 前端 SWR 冷啟動 UX:空資料自動重試
|
||||
|
||||
問題:Redis 快取過期時,第一次 `/scan` 回 `source: "redis (empty)"`,要等 ~30-60 秒 fetcher 完成才有資料。使用者第一次開頁就撞上,看到紅框誤以為壞了。
|
||||
|
||||
前端 `loadScan()` 改成:
|
||||
- 空資料不走紅框錯誤分支,改顯示中性灰框 banner「正在更新資料,請稍候…(N/10)」
|
||||
- 每 8 秒 `setTimeout` 遞迴重試,上限 10 次(80 秒)
|
||||
- 拿到資料自動清 timer + 隱藏 banner
|
||||
- 超時顯示中性警告「後端仍無資料,請稍後重新整理」
|
||||
- 真正網路 / HTTP / JSON 錯誤 → 維持原本紅框
|
||||
|
||||
這次的 push 也是 **webhook pipeline 第一次真實使用**:push → Gitea 觸發 webhook → 42.104 自動 rsync → caddy 下次 request 即新版。之前都是用 Gitea API 的 test endpoint 模擬。
|
||||
|
||||
### 3.13 UI 顯示資料更新時間
|
||||
|
||||
使用者想看到「這份資料什麼時候抓的」:
|
||||
|
||||
- 後端 `/scan` response 新增 `generated_at` 欄位(ISO 8601,台北時區),從 Redis 存的 fetcher payload 頂層讀出
|
||||
- `ScanResponse` model 補 `Optional[str]` 對應
|
||||
- 前端右下角 `<div id="updated-badge">` 半透明深色 banner,文字格式「資料更新於 HH:MM:SS(N 分鐘前)」
|
||||
- 相對時間:<30s 剛剛 / <60m 分鐘前 / <24h 小時前 / 否則日期
|
||||
- `setInterval` 每 10 秒重算顯示(不重 fetch)
|
||||
- 只在成功拿到有 items 的 response 時更新,空/錯誤分支保留上次值
|
||||
|
||||
後端變更需手動部署到 42.108:`git pull && uv sync && supervisorctl restart`。前端透過 webhook 自動部署。
|
||||
|
||||
---
|
||||
|
||||
## 4. 日常操作 Cookbook
|
||||
@@ -330,3 +356,4 @@ curl -sS -X POST http://192.168.42.124:81/api/nginx/proxy-hosts \
|
||||
- 監控:webhook deploy 失敗時沒通知、API 500 時沒通知;可考慮 ntfy / Discord webhook 串起來
|
||||
- Redis 在 42.108 Docker 裡,**沒設 persistence volume**;restart container 資料丟掉但 SWR 會自動重建,實務上無感。若以後需要 persist:加 `-v redis-data:/data`
|
||||
- `add-deploy.sh` 需要 Gitea token 當 arg,使用上每次要貼。可在 42.104 寫個 `/opt/git-webhook/.env` 放 `GITEA_TOKEN`,helper 自動 source
|
||||
- `pokemon-radar-api` 後端還是手動 `git pull + restart`。仿 `add-deploy.sh` 做一個帶 `supervisorctl restart` 的 deploy.sh 即可(需要 webhook container 能 ssh 進 host 執行 supervisorctl,或改用 host-level daemon)
|
||||
|
||||
Reference in New Issue
Block a user