fix(widgets): fetch Steam icons from the community-assets hosts (#102)
#101 asked three Steam CDNs in turn, but all three refuse Workers (403) for any icon their edge has not cached, so production still mirrored no icons. Probed from Cloudflare's network, the shared.fastly and shared.akamai community-assets hosts served every icon, cdn.fastly served cached ones, and cdn.cloudflare, cdn.akamai and media.steampowered.com refused all of them. The worker now asks those three in that order; a remote run against preview KV mirrored all three current icons. Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
c32b0b0586
commit
f18264a859
4 files changed
+29
-22
No files matched your search
+7
-4
@@ -69,10 +69,13 @@ A platform upgrade, a security pass, a new palette and a rebuilt admin
|
||||
trap, lightbox focus handling, labelled report dialog, a correct "copied" message, Esc no longer
|
||||
dismisses the legal notice from elsewhere, landmark and link labels translated.
|
||||
- Gallery albums work without JavaScript; contact lines on /qa and the 403 page are real links.
|
||||
- Widgets: Steam's CDNs answer Workers with 403 for any icon they have not cached, so the worker
|
||||
now asks each of Steam's three hosts in turn and keeps the copy an earlier run stored (games
|
||||
without an icon show their name only). An optional read-only `GITHUB_TOKEN` keeps the GitHub feed
|
||||
from going stale under the per-IP rate limit Workers share.
|
||||
- Widgets: Steam game icons never appeared. The CDN hosts the worker used answer Workers with 403
|
||||
for any icon their edge has not cached; the worker now fetches icons from Steam's
|
||||
community-assets hosts, which serve Workers, falls back to another CDN, and keeps the copy an
|
||||
earlier run stored (games without an icon show their name only)
|
||||
([#101](https://github.com/poli0981/poli0981-dev/pull/101),
|
||||
[#102](https://github.com/poli0981/poli0981-dev/pull/102)). An optional read-only `GITHUB_TOKEN`
|
||||
keeps the GitHub feed from going stale under the per-IP rate limit Workers share.
|
||||
- Dozens of smaller issues found by SonarCloud and the new tests (error pages served with the
|
||||
wrong status under `astro dev`, regex backtracking, scripts that passed without checking).
|
||||
|
||||
|
||||
@@ -33,7 +33,7 @@ Khách **không bao giờ** gọi thẳng bên thứ ba — kể cả ảnh: nha
|
||||
| `widgets:steam` | `{updated, items:[{appid,name,playtime2w,icon}]}` | — |
|
||||
| `widgets:gh` | `{updated, items:[{type,repo,ts,detail}]}` | — |
|
||||
| `widgets:status` | `{yt:"ok"|"stale"|"na", steam:…, gh:…, lastRun}` | — (dashboard admin hiển thị) |
|
||||
| `widgets:img:yt:<id>` · `widgets:img:steam:<appid>:<hash>` | bytes ảnh, metadata `{type}` (jpeg/png/webp) | 14 ngày; ảnh > 2 MB hoặc sai kiểu bị bỏ qua; lượt tải mới lỗi thì giữ bản cũ. Icon Steam: cả ba CDN của Steam (`cdn.cloudflare.steamstatic.com`, `cdn.akamai.steamstatic.com`, `media.steampowered.com`) trả 403 cho Workers khi ảnh chưa nằm trong cache của chúng — worker hỏi lần lượt từng host; game chưa có icon thì widget chỉ hiện tên |
|
||||
| `widgets:img:yt:<id>` · `widgets:img:steam:<appid>:<hash>` | bytes ảnh, metadata `{type}` (jpeg/png/webp) | 14 ngày; ảnh > 2 MB hoặc sai kiểu bị bỏ qua; lượt tải mới lỗi thì giữ bản cũ. Icon Steam: worker hỏi lần lượt `shared.fastly.steamstatic.com` → `shared.akamai.steamstatic.com` (đường dẫn `/community_assets/images/apps/<appid>/<hash>.jpg`, luôn trả ảnh cho Workers) → `cdn.fastly.steamstatic.com` (`/steamcommunity/public/images/apps/…`). Không dùng `cdn.cloudflare`/`cdn.akamai.steamstatic.com` hay `media.steampowered.com`: chúng trả 403 cho Workers với mọi ảnh chưa nằm trong cache của chúng (đo từ mạng Cloudflare ngày 24/10/2026). Game chưa có icon thì widget chỉ hiện tên |
|
||||
|
||||
## 5. Quy tắc bền vững (kế thừa convention tracker của bạn)
|
||||
|
||||
|
||||
@@ -74,9 +74,9 @@ function upstream(
|
||||
);
|
||||
if (
|
||||
url.startsWith("https://i.ytimg.com/") ||
|
||||
url.startsWith("https://cdn.cloudflare.steamstatic.com/") ||
|
||||
url.startsWith("https://cdn.akamai.steamstatic.com/") ||
|
||||
url.startsWith("https://media.steampowered.com/")
|
||||
url.startsWith("https://shared.fastly.steamstatic.com/") ||
|
||||
url.startsWith("https://shared.akamai.steamstatic.com/") ||
|
||||
url.startsWith("https://cdn.fastly.steamstatic.com/")
|
||||
)
|
||||
return overrides.img?.(call) ?? image();
|
||||
if (url.startsWith("https://discord.example/"))
|
||||
@@ -167,18 +167,22 @@ describe("widget sources", () => {
|
||||
|
||||
it("asks each Steam CDN in turn for an icon", async () => {
|
||||
const kv = new FakeKV();
|
||||
// Every Steam host refuses Workers on a cache miss; here only the Akamai one has it.
|
||||
// Here only the last source has the icon; the others refuse, as a cold edge does.
|
||||
const { calls } = upstream({
|
||||
img: (call) =>
|
||||
call.url.startsWith("https://cdn.akamai.steamstatic.com/")
|
||||
call.url.startsWith("https://cdn.fastly.steamstatic.com/")
|
||||
? image()
|
||||
: new Response("<html>", { status: 403, headers: { "content-type": "text/html" } }),
|
||||
});
|
||||
const games = await fetchSteam(env(kv));
|
||||
assert.equal(games[0].icon, `/ext-img/steam/570/${HASH}`);
|
||||
assert.deepEqual(
|
||||
calls.filter((c) => c.url.includes(`/${HASH}.jpg`)).map((c) => new URL(c.url).host),
|
||||
["cdn.cloudflare.steamstatic.com", "cdn.akamai.steamstatic.com"],
|
||||
calls.filter((c) => c.url.includes(`/${HASH}.jpg`)).map((c) => c.url),
|
||||
[
|
||||
`https://shared.fastly.steamstatic.com/community_assets/images/apps/570/${HASH}.jpg`,
|
||||
`https://shared.akamai.steamstatic.com/community_assets/images/apps/570/${HASH}.jpg`,
|
||||
`https://cdn.fastly.steamstatic.com/steamcommunity/public/images/apps/570/${HASH}.jpg`,
|
||||
],
|
||||
);
|
||||
});
|
||||
|
||||
|
||||
@@ -153,14 +153,16 @@ export async function mirrorImage(
|
||||
}
|
||||
|
||||
/**
|
||||
* Steam serves each game icon from several CDNs, and every one of them refuses requests from
|
||||
* Workers (403) for files it has not cached yet — only an edge cache hit gets through
|
||||
* (probed 2026-10-24). Asking each in turn mirrors whatever one of them holds.
|
||||
* Steam serves each game icon from several CDNs. The community-assets path on the `shared.*`
|
||||
* hosts answers Workers every time; the classic `/steamcommunity/public/` hosts refuse them
|
||||
* (403) for any file their edge has not cached — `cdn.cloudflare`, `cdn.akamai` and
|
||||
* `media.steampowered.com` refused every icon, `cdn.fastly` served cached ones (probed from
|
||||
* Cloudflare's network 2026-10-24). Asking each in turn mirrors whatever one of them holds.
|
||||
*/
|
||||
const STEAM_ICON_HOSTS = [
|
||||
"https://cdn.cloudflare.steamstatic.com",
|
||||
"https://cdn.akamai.steamstatic.com",
|
||||
"https://media.steampowered.com",
|
||||
const STEAM_ICON_SOURCES = [
|
||||
"https://shared.fastly.steamstatic.com/community_assets/images/apps",
|
||||
"https://shared.akamai.steamstatic.com/community_assets/images/apps",
|
||||
"https://cdn.fastly.steamstatic.com/steamcommunity/public/images/apps",
|
||||
];
|
||||
|
||||
export async function fetchYouTube(env: WidgetsEnv): Promise<VideoItem[]> {
|
||||
@@ -187,9 +189,7 @@ export async function fetchSteam(env: WidgetsEnv): Promise<GameItem[]> {
|
||||
return Promise.all(
|
||||
games.map(async ({ iconHash, ...game }) => {
|
||||
if (!iconHash) return game;
|
||||
const sources = STEAM_ICON_HOSTS.map(
|
||||
(host) => `${host}/steamcommunity/public/images/apps/${game.appid}/${iconHash}.jpg`,
|
||||
);
|
||||
const sources = STEAM_ICON_SOURCES.map((base) => `${base}/${game.appid}/${iconHash}.jpg`);
|
||||
const ok = await mirrorImage(env.KV, `steam:${game.appid}:${iconHash}`, sources);
|
||||
return { ...game, icon: ok ? `/ext-img/steam/${game.appid}/${iconHash}` : "" };
|
||||
}),
|
||||
|
||||
Reference in new issue
Block a user