Feat: Serve bad.webp instead of an AI image when free.* is given a src

A specific ?src= asks for that source's images only, so a search that finds nothing
there now serves bad.webp (remembered for 24h) rather than the AI fallback.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-14 08:39:20 +00:00
co-authored by Claude Opus 5.5
parent 8995b5e0c3
commit 4701637dd9
3 changed files with 10 additions and 9 deletions
+3 -3
View File
@@ -189,10 +189,10 @@ COMMIT TRANSACTION;`;
};
// Nothing found: serve an AI image of the query instead, cached like any other image. bad.webp (remembered for 24h)
// is only left for when that fails too.
// is only left for when that fails too, or for free.* with a ?src=, which asked for that source's images only.
const fail = async (t, m, tag, p) => {
const fallback = await aiImage(DEFAULT_AI_SOURCE, query, i, env);
note({ title: fallback.success ? `${t}, Served AI Image` : t, message: fallback.success ? m : `${m}\nAI fallback failed: ${fallback.reason}`, tags: tag, priority: p });
const fallback = (!free || src === "auto") && await aiImage(DEFAULT_AI_SOURCE, query, i, env);
note({ title: fallback.success ? `${t}, Served AI Image` : t, message: fallback.success ? m : `${m}\n${fallback ? `AI fallback failed: ${fallback.reason}` : `No AI fallback with src=${src}`}`, tags: tag, priority: p });
if (fallback.success) return await store(fallback);
await env.DIRECT_IMG_CACHE.put(cacheKey, JSON.stringify({ t: Math.floor(Date.now() / 1000), err: true }), { expirationTtl: 86400 });
release();