Short banner links remember a missing file for one minute, not ten (Road Agent's banners were uploaded 2026-11-03 right after Michael asked for them and stayed 404 on the short link)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -2205,7 +2205,7 @@ const SHARE_HOSTS = String(process.env.SHARE_HOSTS || 'ctbgo.com,mylinehq.com').
|
|||||||
// by exchange and safelist image fields, so the banners never show). /b/<slug>/<file> serves the same file from
|
// by exchange and safelist image fields, so the banners never show). /b/<slug>/<file> serves the same file from
|
||||||
// game-banners/<slug>/ on the Spaces CDN, bytes in place (no redirect: some sites only HEAD the URL), on the share hosts as
|
// game-banners/<slug>/ on the Spaces CDN, bytes in place (no redirect: some sites only HEAD the URL), on the share hosts as
|
||||||
// well as here: https://ctbgo.com/b/turkeydrop/728x90.png. A bare <size>.<ext> expands to <slug>-<size>.<ext>. Small
|
// well as here: https://ctbgo.com/b/turkeydrop/728x90.png. A bare <size>.<ext> expands to <slug>-<size>.<ext>. Small
|
||||||
// in-memory cache, 300 files, six hours, misses remembered ten minutes.
|
// in-memory cache, 300 files, six hours, misses remembered one minute (a banner uploaded after someone asked for it shows up fast).
|
||||||
const BANNER_CDN = 'https://coolify-saasytop.nyc3.cdn.digitaloceanspaces.com/game-banners/';
|
const BANNER_CDN = 'https://coolify-saasytop.nyc3.cdn.digitaloceanspaces.com/game-banners/';
|
||||||
const BANNER_TYPES = { png: 'image/png', jpg: 'image/jpeg', jpeg: 'image/jpeg', webp: 'image/webp', gif: 'image/gif' };
|
const BANNER_TYPES = { png: 'image/png', jpg: 'image/jpeg', jpeg: 'image/jpeg', webp: 'image/webp', gif: 'image/gif' };
|
||||||
const bannerCache = new Map(); // cdn url -> { buf, type, at, miss }
|
const bannerCache = new Map(); // cdn url -> { buf, type, at, miss }
|
||||||
@@ -2216,7 +2216,7 @@ async function serveBanner(req, res, p) {
|
|||||||
let name = m[2].toLowerCase(); if (/^\d{2,4}x\d{2,4}$/.test(name)) name = slug + '-' + name;
|
let name = m[2].toLowerCase(); if (/^\d{2,4}x\d{2,4}$/.test(name)) name = slug + '-' + name;
|
||||||
const url = BANNER_CDN + slug + '/' + name + '.' + ext;
|
const url = BANNER_CDN + slug + '/' + name + '.' + ext;
|
||||||
let hit = bannerCache.get(url);
|
let hit = bannerCache.get(url);
|
||||||
if (!hit || Date.now() - hit.at > (hit.miss ? 600e3 : 6 * 3600e3)) {
|
if (!hit || Date.now() - hit.at > (hit.miss ? 60e3 : 6 * 3600e3)) {
|
||||||
try {
|
try {
|
||||||
const r = await fetch(url, { signal: AbortSignal.timeout(10000) });
|
const r = await fetch(url, { signal: AbortSignal.timeout(10000) });
|
||||||
if (r.ok) {
|
if (r.ok) {
|
||||||
|
|||||||
Reference in New Issue
Block a user