Skip to content

feat(fuel): CPC Taiwan fuel prices (stage C item 3) - #76

Merged
TTigger merged 1 commit into
masterfrom
feat/fuel-price
Jul 13, 2026
Merged

feat(fuel): CPC Taiwan fuel prices (stage C item 3)#76
TTigger merged 1 commit into
masterfrom
feat/fuel-price

Conversation

@TTigger

@TTigger TTigger commented Jul 13, 2026

Copy link
Copy Markdown
Owner

摘要

階段 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 在伺服器端就拆成純文字(單元測試釘住輸出不含 <)。

功能

  • 六格牌價卡+本週調價訊息+價格生效日
  • 加油試算:油品 × 公升 ⇄ 金額雙向換算,換油品即重算
  • 中油更新中(回空字串)→ 502,前端顯示錯誤與重試

驗證

  • typecheck:api ✓ / 541 unit ✓(+4)/ 62 e2e ✓(+2)
  • OG 卡 72 張重生成、新卡已目測;工具頁已截圖目測
  • ⚠️ 依 HANDOFF 規則:動到 api/合併後立即實打 production /api/fuel-price 驗證

🤖 Generated with Claude Code

政府 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>
@vercel

vercel Bot commented Jul 13, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
tiglet Ready Ready Preview, Comment Jul 13, 2026 2:09pm

@TTigger
TTigger merged commit 4f0a54f into master Jul 13, 2026
3 checks passed
@TTigger
TTigger deleted the feat/fuel-price branch July 13, 2026 14:11
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>
@TTigger TTigger changed the title feat(fuel): 中油油價 (stage C item 3) feat(fuel): CPC Taiwan fuel prices (stage C item 3) Jul 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant