diff --git a/assets/bad.webp b/assets/bad.webp new file mode 100644 index 0000000..b7de317 Binary files /dev/null and b/assets/bad.webp differ diff --git a/assets/favicon.ico b/assets/favicon.ico new file mode 100644 index 0000000..137a56f Binary files /dev/null and b/assets/favicon.ico differ diff --git a/limit.webp b/assets/limit.webp similarity index 100% rename from limit.webp rename to assets/limit.webp diff --git a/assets/logo.jpg b/assets/logo.jpg new file mode 100644 index 0000000..44124ab Binary files /dev/null and b/assets/logo.jpg differ diff --git a/assets/logo.svg b/assets/logo.svg new file mode 100644 index 0000000..ac33802 --- /dev/null +++ b/assets/logo.svg @@ -0,0 +1,12 @@ + diff --git a/functions/[[path]].js b/functions/[[path]].js index 31afc9e..a3432bb 100644 --- a/functions/[[path]].js +++ b/functions/[[path]].js @@ -7,17 +7,17 @@ export async function onRequest(context) { const { request, env, params } = context; const url = new URL(request.url); const path = params.path?.join("/") || ""; + const asset = f => env.ASSETS.fetch(new Request(new URL(`/assets/${f}`, url.origin))); - if (!path || path === "index.html" || path === "favicon.ico" || path === "robots.txt" || path === "limit.webp" || path === "bad.webp") { + if (!path || path === "index.html" || path === "robots.txt" || path.startsWith("assets/")) { return env.ASSETS.fetch(request); } + if (path === "favicon.ico") return asset("favicon.ico"); if (path === "_setup") return setupSurreal(env); const rawQueryPart = url.pathname.slice(1).replace(/\/+$/, ""); - if (rawQueryPart.includes(".") || rawQueryPart.includes("/")) { - return env.ASSETS.fetch(new Request(new URL("/bad.webp", url.origin))); - } + if (rawQueryPart.includes(".") || rawQueryPart.includes("/")) return asset("bad.webp"); const query = normalizeQuery(path); if (!query) return jsonResponse(400, { error: "Empty query" }); @@ -28,7 +28,7 @@ export async function onRequest(context) { const cached = await env.DIRECT_IMG_CACHE.get(cacheKey, "json"); if (cached) { - if (cached.err) return env.ASSETS.fetch(new Request(new URL("/bad.webp", url.origin))); + if (cached.err) return asset("bad.webp"); const obj = await env.R2_IMAGES.get(r2Key); if (obj) { const nowSec = Math.floor(Date.now() / 1000); @@ -120,7 +120,7 @@ export async function onRequest(context) { if (count > 20) { context.waitUntil(notify(env, { title: "Rate Limit Hit", message: `IP ${ip} hit limit for: ${query}`, tags: "warning,no_entry", priority: 2 })); - return env.ASSETS.fetch(new Request(new URL("/limit.webp", url.origin))); + return asset("limit.webp"); } context.waitUntil(notify(env, { title: "New Search", message: `Query: ${query} (Search #${count} for ${ip})\n${url.origin}/${path}`, tags: "mag", priority: 2 })); @@ -128,7 +128,7 @@ export async function onRequest(context) { const fail = async (t, m, tag, p) => { context.waitUntil(notify(env, { title: t, message: m, tags: tag, priority: p })); await env.DIRECT_IMG_CACHE.put(cacheKey, JSON.stringify({ t: Math.floor(Date.now() / 1000), err: true }), { expirationTtl: 86400 }); - return env.ASSETS.fetch(new Request(new URL("/bad.webp", url.origin))); + return asset("bad.webp"); }; let imageUrls = await braveImageSearch(query, env.BRAVE_API_KEY); diff --git a/index.html b/index.html index f931b38..5b3b568 100644 --- a/index.html +++ b/index.html @@ -4,6 +4,7 @@