feat(fuel): CPC Taiwan fuel prices (stage C item 3) - #76
Merged
Conversation
政府 API 生活工具第一發:中油今日牌價+加油試算。第三支 serverless function。 - 資料源:中油官網 GetOilPriceJson.aspx?type=TodayOilPriceString (免金鑰 JSON;sPrice1~6 對應抄自中油首頁 widget JS: 92/95/98 無鉛、酒精汽油、超級柴油、車用液化石油氣)。 - src/lib/fuelPrice.ts:回應正規化(TDD 4 tests)——價格轉數字、 UpOrDown_Html 一律拆成純文字(前端不做 innerHTML,不透傳外部 HTML)、 中油更新中回空字串時整包判 null。 - api/fuel-price.ts:固定網址、無使用者輸入(無 SSRF 面), CDN 快取 s-maxage=1800 + SWR 一天(牌價每週一調)。 - src/tools/FuelPrice.tsx:六格牌價卡、本週調價訊息、生效日, 加油試算(油品×公升⇄金額雙向);中英頁面、tools.ts 註冊(⛽)。 - e2e:stub API,涵蓋牌價顯示、試算雙向與換油品重算、掛掉重試(+2)。 - OG 卡 72 張(守門測試同步),新卡已目測。 測試:typecheck:api ✓ / 541 unit ✓(+4)/ 62 e2e ✓(+2) 合併後需立即驗 production /api/fuel-price(preview 在 SSO 後面)。 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
TTigger
added a commit
that referenced
this pull request
Jul 13, 2026
First of the government-data everyday tools: today's CPC list prices plus a fill-up calculator. Third serverless function. - Source: CPC's own GetOilPriceJson.aspx?type=TodayOilPriceString (key-free JSON). The sPrice1~6 field mapping is copied from the CPC homepage widget JS — 92/95/98 unleaded, alcohol gasoline, premium diesel, automotive LPG — not guessed. - src/lib/fuelPrice.ts: response normalization (TDD 4 tests) — prices to numbers, UpOrDown_Html flattened to plain text on the server side (the frontend never innerHTMLs upstream markup; a test pins that the output contains no '<'), and the whole payload rejected as null when CPC returns empty strings mid-update (their own JS guards the same way). - api/fuel-price.ts: fixed URL, no user input (no SSRF surface), CDN cache s-maxage=1800 + one-day SWR (prices adjust weekly on Monday). - src/tools/FuelPrice.tsx: six price cards, weekly-adjustment banner, effective date, and a fuel x liters <-> amount two-way calculator; zh/en pages and tools.ts entry (⛽). - e2e: stub API — price display, two-way calculation and fuel-switch recalculation, failure + retry (+2). - OG cards regenerated (72 total) and eyeballed. Tests: typecheck:api / 541 unit (+4) / 62 e2e (+2). api/ changed: production /api/fuel-price verified right after the merge (preview deployments sit behind Vercel SSO). Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
摘要
階段 C 第 3 項(政府 API 生活工具第一發):中油油價 —— 今日牌價、本週調價與加油試算。第三支 serverless function。
資料源
中油官網
GetOilPriceJson.aspx?type=TodayOilPriceString(免金鑰 JSON)。sPrice1~6欄位對應直接抄自中油首頁 widget 的 JS(92/95/98 無鉛、酒精汽油、超級柴油、車用液化石油氣),不是猜的。固定網址、無使用者輸入 → 無 SSRF 面。牌價每週一調,CDN 快取 30 分鐘。安全細節
中油回應裡的
UpOrDown_Html是一段 HTML。不透傳、不 innerHTML ——src/lib/fuelPrice.ts在伺服器端就拆成純文字(單元測試釘住輸出不含<)。功能
驗證
api/,合併後立即實打 production/api/fuel-price驗證🤖 Generated with Claude Code