diff --git a/README.md b/README.md index b8c1c74..bb17cca 100644 --- a/README.md +++ b/README.md @@ -133,7 +133,7 @@ Use images to complement your responses, powered by Brave. ### New Searches (Cache Misses) -- **35 new searches per day per IP** (resets at midnight UTC), then `limit.webp` is served — shared between `direct-img.link` and `free.direct-img.link` +- **35 new searches per day per IP** on `direct-img.link` and **100** on `free.direct-img.link` (separate counters, reset at midnight UTC), then `limit.webp` is served - **Cache hits are unlimited** (within WAF limits above) - Failed searches count toward the limit and are remembered for 24h (`bad.webp`) - WAF counters are approximate (not shared perfectly across Cloudflare servers), so bursts may slip slightly past 10 diff --git a/functions/[[path]].js b/functions/[[path]].js index 6abfe6d..451299c 100644 --- a/functions/[[path]].js +++ b/functions/[[path]].js @@ -54,7 +54,9 @@ export async function onRequest(context) { const ip = request.headers.get("cf-connecting-ip") || "unknown"; const today = new Date().toISOString().slice(0, 10); - const rateId = await sha256(`${ip}:${today}`); + // free.* gets its own counter (prefixed so main-site ids stay unchanged) since it never spends Brave credits + const rateId = await sha256(`${free ? "free:" : ""}${ip}:${today}`); + const limit = free ? 100 : 35; let count = 1; if (env.SURREAL_URL && env.SURREAL_USER && env.SURREAL_PASS) { @@ -133,8 +135,8 @@ export async function onRequest(context) { })); } - if (count > 35) { - context.waitUntil(notify(env, { title: "Rate Limit Hit", message: `IP ${ip} hit limit for: ${query}`, tags: "warning,no_entry", priority: 2 })); + if (count > limit) { + context.waitUntil(notify(env, { title: free ? "Free Rate Limit Hit" : "Rate Limit Hit", message: `IP ${ip} hit limit for: ${query}`, tags: "warning,no_entry", priority: 2 })); return asset("limit.webp"); } diff --git a/index.html b/index.html index 3e0a50e..270a785 100644 --- a/index.html +++ b/index.html @@ -100,9 +100,10 @@ Use images to complement your responses, powered by Brave. Burst~10 req/10s per IPHTTP 429 (~10s) New Searches35 per day per IPLimit image served + New Free Searches100 per day per IPLimit image served -

* The daily limit is shared with free.direct-img.link. Cached images don't count toward it and keep loading after you hit it. The burst limit applies to all image requests and is enforced approximately. The daily limit resets at 00:00 UTC.

+

* free.direct-img.link has its own daily limit, separate from the main site's. Cached images don't count toward it and keep loading after you hit it. The burst limit applies to all image requests and is enforced approximately. The daily limit resets at 00:00 UTC.