@searchos/bot-proxy 1.0.3 → 1.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1 @@
1
+ import{b as O,c as f}from"./chunk-62QI7OUQ.js";var P=/^\/(?:robots\.txt|llms\.txt|sitemap[^\/]*\.(?:xml|xsl))$/i,S=/mobile|android|iphone|phone|tablet|webos|ipad/i;async function E(s,r){let{projectId:t,cloudfrontDomain:p,prerenderDomain:n,botLogEndpoint:a,aiRender:x=!0,ocr:y=!0,aiPathPrefixes:$=[]}=r,o=r.siteDomain.replace(/^https?:\/\//,"").replace(/\/+$/,""),b=p.replace(/\/$/,""),l=new URL(s.url),e=l.pathname;if(s.headers.get("x-prerender-host")){if(P.test(e)||e===`/${t}.txt`){let{NextResponse:i}=await import("next/server");return i.next()}return null}if(e===`/${t}.txt`)try{let i=await fetch(`${n}${e}`,{redirect:"manual"});return new Response(i.body,{status:i.status,headers:{"Content-Type":"text/plain","Cache-Control":"public, max-age=3600"}})}catch{return null}if(P.test(e))try{let i=await fetch(`${n}/static${e}`,{headers:{"X-Signature":t,"X-Original-Host":o}});return new Response(i.body,{status:i.status,headers:{"Content-Type":i.headers.get("Content-Type")||"text/plain","Cache-Control":"public, max-age=3600"}})}catch{return null}let c=s.headers.get("user-agent")||"",u=O(c);if(!u)return null;let k=S.test(c)?"mobile":"desktop",d=`https://${o}${e}`;try{if(u.isAi&&x){let m=await f(e,"ai"),_=await fetch(`${b}/v2/${o}/${m}.html`,{headers:{Accept:"text/html"}});if(_.ok){let h=await _.text();if(h&&h.length>100)return g(a,t,o,e,l.search,c,"hit_ai"),R(n,t,d,y,$),w(h,"HIT-AI",u.name)}let I=await f(e,"desktop"),j=await fetch(`${b}/v2/${o}/${I}.html`,{headers:{Accept:"text/html"}});if(j.ok){let h=await j.text();if(h&&h.length>100)return g(a,t,o,e,l.search,c,"hit_desktop_fallback"),R(n,t,d,y,$),w(h,"HIT-DESKTOP",u.name)}return g(a,t,o,e,l.search,c,"miss_ai"),R(n,t,d,y,$),T(n,t,d),null}let i=await f(e,k),C=await fetch(`${b}/v2/${o}/${i}.html`,{headers:{Accept:"text/html"}});if(C.ok){let m=await C.text();if(m&&m.length>100)return g(a,t,o,e,l.search,c,"hit"),T(n,t,d),w(m,"HIT",u.name)}}catch{}return g(a,t,o,e,l.search,c,"miss"),T(n,t,d),null}function w(s,r,t){return new Response(s,{headers:{"Content-Type":"text/html; charset=utf-8","X-Cache":r,"X-Bot":t}})}function g(s,r,t,p,n,a,x){fetch(s,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({project_id:r,url:`https://${t}${p}${n}`,domain:t,path:p,user_agent:a,phase:x})}).catch(()=>{})}function T(s,r,t){fetch(`${s}/v2/cache`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({items:[{url:t,project_id:r}]})}).catch(()=>{})}function R(s,r,t,p,n){let a={items:[{url:t,project_id:r}],ocr:p};n.length>0&&(a.path_prefixes=n),fetch(`${s}/v2/cache/ai`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(a)}).catch(()=>{})}export{E as a};
@@ -0,0 +1 @@
1
+ import{a as E,b as R,c as w}from"./chunk-62QI7OUQ.js";var S=/^\/(?:robots\.txt|llms\.txt|sitemap[^\/]*\.(?:xml|xsl))$/i,I=/mobile|android|iphone|phone|tablet|webos|ipad/i;async function V(s,n,r,p){let{projectId:t,siteDomain:u,prerenderDomain:i,botLogEndpoint:h,aiRender:k=!0,ocr:$=!0,aiPathPrefixes:C=[]}=p,e=new URL(s.url).pathname,c=u.replace(/^https?:\/\//,"").replace(/\/+$/,"");if(s.headers.get("x-prerender-host"))return null;if(e===`/${t}.txt`)try{let o=await fetch(`${i}${e}`,{redirect:"manual"});return new Response(o.body,{status:o.status,headers:{"Content-Type":"text/plain","Cache-Control":"public, max-age=3600"}})}catch{return new Response("",{status:404})}if(S.test(e))try{let o=await fetch(`${i}/static${e}`,{redirect:"manual",headers:{"X-Signature":t,"X-Original-Host":c}});return new Response(o.body,{status:o.status,headers:{"Content-Type":o.headers.get("Content-Type")||"text/plain","Cache-Control":"public, max-age=3600"}})}catch{return null}let l=s.headers.get("user-agent")||"",a=R(l);if(!a||!n.V2_CACHE)return null;let P=I.test(l)?"mobile":"desktop",d=`https://${c}${e}`,g=E.has(a.name)?"ai-user":a.isAi?"ai-crawl":"standard",m=o=>r.waitUntil(o().catch(f=>console.error("[bot-proxy]",f)));try{if(a.isAi&&k){let A=await w(e,"ai"),x=await n.V2_CACHE.get(A);if(x)return m(async()=>{console.log(`[BOT] ${a.name} | ${g} | hit_ai | ${e}`),await y(h,t,c,e,l,"hit_ai"),await _(i,t,d,$,C)}),b(x,"HIT-AI",a.name);let H=await w(e,"desktop"),O=await n.V2_CACHE.get(H);return O?(m(async()=>{console.log(`[BOT] ${a.name} | ${g} | hit_desktop_fallback | ${e}`),await y(h,t,c,e,l,"hit_desktop_fallback"),await _(i,t,d,$,C)}),b(O,"HIT-DESKTOP",a.name)):(m(async()=>{console.log(`[BOT] ${a.name} | ${g} | miss_ai | ${e}`),await y(h,t,c,e,l,"miss_ai"),await Promise.all([_(i,t,d,$,C),T(i,t,d)])}),null)}let o=await w(e,P),f=await n.V2_CACHE.get(o);return f?(m(async()=>{console.log(`[BOT] ${a.name} | ${g} | hit | ${e}`),await y(h,t,c,e,l,"hit"),await T(i,t,d)}),b(f,"HIT",a.name)):(m(async()=>{console.log(`[BOT] ${a.name} | ${g} | miss | ${e}`),await y(h,t,c,e,l,"miss"),await T(i,t,d)}),null)}catch(o){return console.error("[bot-proxy]",o),null}}function b(s,n,r){return new Response(s,{headers:{"Content-Type":"text/html; charset=utf-8","X-Cache":n,"X-Bot":r}})}async function y(s,n,r,p,t,u){await fetch(s,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({project_id:n,url:`https://${r}${p}`,domain:r,path:p,user_agent:t,phase:u})})}async function T(s,n,r){await fetch(`${s}/v2/cache/kv`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({items:[{url:r,project_id:n}]})})}async function _(s,n,r,p,t){let u={items:[{url:r,project_id:n}],ocr:p};t.length>0&&(u.path_prefixes=t),await fetch(`${s}/v2/cache/kv/ai`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(u)})}export{V as a};
@@ -1 +1 @@
1
- "use strict";var _=Object.defineProperty;var V=Object.getOwnPropertyDescriptor;var D=Object.getOwnPropertyNames;var M=Object.prototype.hasOwnProperty;var W=(t,o)=>{for(var e in o)_(t,e,{get:o[e],enumerable:!0})},X=(t,o,e,r)=>{if(o&&typeof o=="object"||typeof o=="function")for(let n of D(o))!M.call(t,n)&&n!==e&&_(t,n,{get:()=>o[n],enumerable:!(r=V(o,n))||r.enumerable});return t};var z=t=>X(_({},"__esModule",{value:!0}),t);var Z={};W(Z,{cloudflareProxy:()=>H});module.exports=z(Z);var T=["chatgpt-user","claude-user","perplexity-user","gemini-user","gemini-deep-research","mistralai-user","grok-user"],R=["gptbot","oai-searchbot","claudebot","claude-searchbot","google-extended","google-cloudvertexbot","perplexitybot","meta-externalagent","applebot-extended","amazonbot","cohere-ai","bytespider","deepseekbot","grokbot","ccbot","diffbot","ai2bot","petalbot"],k=["googlebot","googlebot-image","googlebot-video","googlebot-news","googleother","mediapartners-google","adsbot-google","google-inspectiontool","bingbot","bingpreview","naverbot","yeti","daumoa","baiduspider","yandexbot","duckduckbot","applebot"],B=["facebookexternalhit","linkedinbot","twitterbot","slackbot","discordbot","telegrambot","whatsapp","pinterestbot","redditbot"],P=["ahrefsbot","semrushbot","mj12bot","dotbot","dataforseobot"],J=["uptimerobot","lighthouse","chrome-lighthouse"],I=new Set([...T,...R]),C=new Set(T),G=[...T,...R,...k,...B,...P,...J];function N(t){let o=t.toLowerCase();for(let e of G)if(o.includes(e)){let r;return C.has(e)?r="ai-user":I.has(e)?r="ai-crawl":k.includes(e)?r="search":B.includes(e)?r="sns":P.includes(e)?r="seo":r="monitoring",{name:e,isAi:I.has(e),category:r}}return null}async function q(t){if(typeof process<"u"&&process.versions?.node){let{createHash:r}=require("crypto");return r("md5").update(t,"utf8").digest("hex")}let o=new TextEncoder().encode(t),e=await crypto.subtle.digest("MD5",o);return Array.from(new Uint8Array(e),r=>r.toString(16).padStart(2,"0")).join("")}function F(t){if(!t)return"/";if(t.startsWith("http://")||t.startsWith("https://"))try{t=new URL(t).pathname}catch{}let o=t.indexOf("?");return o!==-1&&(t=t.substring(0,o)),t?t.split("/").map(e=>{if(!e)return e;try{return encodeURIComponent(decodeURIComponent(e))}catch{return encodeURIComponent(e)}}).join("/"):"/"}async function x(t,o){let e=F(t);return`${await q(e)}_${o}`}var Q=/^\/(?:robots\.txt|llms\.txt|sitemap[^\/]*\.(?:xml|xsl))$/i,Y=/mobile|android|iphone|phone|tablet|webos|ipad/i;async function H(t,o,e,r){let{projectId:n,siteDomain:d,prerenderDomain:c,botLogEndpoint:g,aiRender:K=!0,ocr:w=!0,aiPathPrefixes:h=[]}=r,s=new URL(t.url).pathname,l=d.replace(/^https?:\/\//,"").replace(/\/+$/,"");if(t.headers.get("x-prerender-host"))return null;if(s===`/${n}.txt`)try{let a=await fetch(`${c}${s}`,{redirect:"manual"});return new Response(a.body,{status:a.status,headers:{"Content-Type":"text/plain","Cache-Control":"public, max-age=3600"}})}catch{return new Response("",{status:404})}if(Q.test(s))try{let a=await fetch(`${c}/static${s}`,{redirect:"manual",headers:{"X-Signature":n,"X-Original-Host":l}});return new Response(a.body,{status:a.status,headers:{"Content-Type":a.headers.get("Content-Type")||"text/plain","Cache-Control":"public, max-age=3600"}})}catch{return null}let p=t.headers.get("user-agent")||"",i=N(p);if(!i||!o.V2_CACHE)return null;let j=Y.test(p)?"mobile":"desktop",u=`https://${l}${s}`,m=C.has(i.name)?"ai-user":i.isAi?"ai-crawl":"standard",f=a=>e.waitUntil(a().catch(y=>console.error("[bot-proxy]",y))),L=h.length===0||h.some(a=>s.startsWith(a));try{if(i.isAi&&K&&L){let U=await x(s,"ai"),$=await o.V2_CACHE.get(U);if($)return f(async()=>{console.log(`[BOT] ${i.name} | ${m} | hit_ai | ${s}`),await b(g,n,l,s,p,"hit_ai"),await S(c,n,u,w,h)}),O($,"HIT-AI",i.name);let v=await x(s,"desktop"),A=await o.V2_CACHE.get(v);return A?(f(async()=>{console.log(`[BOT] ${i.name} | ${m} | hit_desktop_fallback | ${s}`),await b(g,n,l,s,p,"hit_desktop_fallback"),await S(c,n,u,w,h)}),O(A,"HIT-DESKTOP",i.name)):(f(async()=>{console.log(`[BOT] ${i.name} | ${m} | miss_ai | ${s}`),await b(g,n,l,s,p,"miss_ai"),await Promise.all([S(c,n,u,w,h),E(c,n,u)])}),null)}let a=await x(s,j),y=await o.V2_CACHE.get(a);return y?(f(async()=>{console.log(`[BOT] ${i.name} | ${m} | hit | ${s}`),await b(g,n,l,s,p,"hit"),await E(c,n,u)}),O(y,"HIT",i.name)):(f(async()=>{console.log(`[BOT] ${i.name} | ${m} | miss | ${s}`),await b(g,n,l,s,p,"miss"),await E(c,n,u)}),null)}catch(a){return console.error("[bot-proxy]",a),null}}function O(t,o,e){return new Response(t,{headers:{"Content-Type":"text/html; charset=utf-8","X-Cache":o,"X-Bot":e}})}async function b(t,o,e,r,n,d){await fetch(t,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({project_id:o,url:`https://${e}${r}`,domain:e,path:r,user_agent:n,phase:d})})}async function E(t,o,e){await fetch(`${t}/v2/cache/kv`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({items:[{url:e,project_id:o}]})})}async function S(t,o,e,r,n){let d={items:[{url:e,project_id:o}],ocr:r};n.length>0&&(d.path_prefixes=n),await fetch(`${t}/v2/cache/kv/ai`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(d)})}0&&(module.exports={cloudflareProxy});
1
+ "use strict";var _=Object.defineProperty;var v=Object.getOwnPropertyDescriptor;var V=Object.getOwnPropertyNames;var D=Object.prototype.hasOwnProperty;var M=(t,o)=>{for(var e in o)_(t,e,{get:o[e],enumerable:!0})},X=(t,o,e,r)=>{if(o&&typeof o=="object"||typeof o=="function")for(let n of V(o))!D.call(t,n)&&n!==e&&_(t,n,{get:()=>o[n],enumerable:!(r=v(o,n))||r.enumerable});return t};var z=t=>X(_({},"__esModule",{value:!0}),t);var Y={};M(Y,{cloudflareProxy:()=>H});module.exports=z(Y);var T=["chatgpt-user","claude-user","perplexity-user","gemini-user","gemini-deep-research","mistralai-user","grok-user"],k=["gptbot","oai-searchbot","claudebot","claude-searchbot","google-extended","google-cloudvertexbot","perplexitybot","meta-externalagent","applebot-extended","amazonbot","cohere-ai","bytespider","deepseekbot","grokbot","ccbot","diffbot","ai2bot","petalbot"],A=["googlebot","googlebot-image","googlebot-video","googlebot-news","googleother","mediapartners-google","adsbot-google","google-inspectiontool","bingbot","bingpreview","naverbot","yeti","daumoa","baiduspider","yandexbot","duckduckbot","applebot"],B=["facebookexternalhit","linkedinbot","twitterbot","slackbot","discordbot","telegrambot","whatsapp","pinterestbot","redditbot"],P=["ahrefsbot","semrushbot","mj12bot","dotbot","dataforseobot"],J=["uptimerobot","lighthouse","chrome-lighthouse"],R=new Set([...T,...k]),C=new Set(T),W=[...T,...k,...A,...B,...P,...J];function N(t){let o=t.toLowerCase();for(let e of W)if(o.includes(e)){let r;return C.has(e)?r="ai-user":R.has(e)?r="ai-crawl":A.includes(e)?r="search":B.includes(e)?r="sns":P.includes(e)?r="seo":r="monitoring",{name:e,isAi:R.has(e),category:r}}return null}async function G(t){if(typeof process<"u"&&process.versions?.node){let{createHash:r}=require("crypto");return r("md5").update(t,"utf8").digest("hex")}let o=new TextEncoder().encode(t),e=await crypto.subtle.digest("MD5",o);return Array.from(new Uint8Array(e),r=>r.toString(16).padStart(2,"0")).join("")}function q(t){if(!t)return"/";if(t.startsWith("http://")||t.startsWith("https://"))try{t=new URL(t).pathname}catch{}let o=t.indexOf("?");return o!==-1&&(t=t.substring(0,o)),t?t.split("/").map(e=>{if(!e)return e;try{return encodeURIComponent(decodeURIComponent(e))}catch{return encodeURIComponent(e)}}).join("/"):"/"}async function y(t,o){let e=q(t);return`${await G(e)}_${o}`}var F=/^\/(?:robots\.txt|llms\.txt|sitemap[^\/]*\.(?:xml|xsl))$/i,Q=/mobile|android|iphone|phone|tablet|webos|ipad/i;async function H(t,o,e,r){let{projectId:n,siteDomain:d,prerenderDomain:c,botLogEndpoint:g,aiRender:K=!0,ocr:x=!0,aiPathPrefixes:w=[]}=r,s=new URL(t.url).pathname,l=d.replace(/^https?:\/\//,"").replace(/\/+$/,"");if(t.headers.get("x-prerender-host"))return null;if(s===`/${n}.txt`)try{let i=await fetch(`${c}${s}`,{redirect:"manual"});return new Response(i.body,{status:i.status,headers:{"Content-Type":"text/plain","Cache-Control":"public, max-age=3600"}})}catch{return new Response("",{status:404})}if(F.test(s))try{let i=await fetch(`${c}/static${s}`,{redirect:"manual",headers:{"X-Signature":n,"X-Original-Host":l}});return new Response(i.body,{status:i.status,headers:{"Content-Type":i.headers.get("Content-Type")||"text/plain","Cache-Control":"public, max-age=3600"}})}catch{return null}let p=t.headers.get("user-agent")||"",a=N(p);if(!a||!o.V2_CACHE)return null;let j=Q.test(p)?"mobile":"desktop",u=`https://${l}${s}`,h=C.has(a.name)?"ai-user":a.isAi?"ai-crawl":"standard",m=i=>e.waitUntil(i().catch(b=>console.error("[bot-proxy]",b)));try{if(a.isAi&&K){let L=await y(s,"ai"),$=await o.V2_CACHE.get(L);if($)return m(async()=>{console.log(`[BOT] ${a.name} | ${h} | hit_ai | ${s}`),await f(g,n,l,s,p,"hit_ai"),await S(c,n,u,x,w)}),O($,"HIT-AI",a.name);let U=await y(s,"desktop"),I=await o.V2_CACHE.get(U);return I?(m(async()=>{console.log(`[BOT] ${a.name} | ${h} | hit_desktop_fallback | ${s}`),await f(g,n,l,s,p,"hit_desktop_fallback"),await S(c,n,u,x,w)}),O(I,"HIT-DESKTOP",a.name)):(m(async()=>{console.log(`[BOT] ${a.name} | ${h} | miss_ai | ${s}`),await f(g,n,l,s,p,"miss_ai"),await Promise.all([S(c,n,u,x,w),E(c,n,u)])}),null)}let i=await y(s,j),b=await o.V2_CACHE.get(i);return b?(m(async()=>{console.log(`[BOT] ${a.name} | ${h} | hit | ${s}`),await f(g,n,l,s,p,"hit"),await E(c,n,u)}),O(b,"HIT",a.name)):(m(async()=>{console.log(`[BOT] ${a.name} | ${h} | miss | ${s}`),await f(g,n,l,s,p,"miss"),await E(c,n,u)}),null)}catch(i){return console.error("[bot-proxy]",i),null}}function O(t,o,e){return new Response(t,{headers:{"Content-Type":"text/html; charset=utf-8","X-Cache":o,"X-Bot":e}})}async function f(t,o,e,r,n,d){await fetch(t,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({project_id:o,url:`https://${e}${r}`,domain:e,path:r,user_agent:n,phase:d})})}async function E(t,o,e){await fetch(`${t}/v2/cache/kv`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({items:[{url:e,project_id:o}]})})}async function S(t,o,e,r,n){let d={items:[{url:e,project_id:o}],ocr:r};n.length>0&&(d.path_prefixes=n),await fetch(`${t}/v2/cache/kv/ai`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(d)})}0&&(module.exports={cloudflareProxy});
@@ -1 +1 @@
1
- import{a as o}from"./chunk-UELFMNQN.js";import"./chunk-62QI7OUQ.js";export{o as cloudflareProxy};
1
+ import{a as o}from"./chunk-HLBLRAGQ.js";import"./chunk-62QI7OUQ.js";export{o as cloudflareProxy};
package/dist/index.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";var G=Object.create;var R=Object.defineProperty;var q=Object.getOwnPropertyDescriptor;var Q=Object.getOwnPropertyNames;var Y=Object.getPrototypeOf,Z=Object.prototype.hasOwnProperty;var tt=(e,o)=>{for(var t in o)R(e,t,{get:o[t],enumerable:!0})},v=(e,o,t,s)=>{if(o&&typeof o=="object"||typeof o=="function")for(let n of Q(o))!Z.call(e,n)&&n!==t&&R(e,n,{get:()=>o[n],enumerable:!(s=q(o,n))||s.enumerable});return e};var et=(e,o,t)=>(t=e!=null?G(Y(e)):{},v(o||!e||!e.__esModule?R(t,"default",{value:e,enumerable:!0}):t,e)),ot=e=>v(R({},"__esModule",{value:!0}),e);var pt={};tt(pt,{cloudflareProxy:()=>z,nextjsProxy:()=>W});module.exports=ot(pt);var k=["chatgpt-user","claude-user","perplexity-user","gemini-user","gemini-deep-research","mistralai-user","grok-user"],U=["gptbot","oai-searchbot","claudebot","claude-searchbot","google-extended","google-cloudvertexbot","perplexitybot","meta-externalagent","applebot-extended","amazonbot","cohere-ai","bytespider","deepseekbot","grokbot","ccbot","diffbot","ai2bot","petalbot"],X=["googlebot","googlebot-image","googlebot-video","googlebot-news","googleother","mediapartners-google","adsbot-google","google-inspectiontool","bingbot","bingpreview","naverbot","yeti","daumoa","baiduspider","yandexbot","duckduckbot","applebot"],V=["facebookexternalhit","linkedinbot","twitterbot","slackbot","discordbot","telegrambot","whatsapp","pinterestbot","redditbot"],J=["ahrefsbot","semrushbot","mj12bot","dotbot","dataforseobot"],nt=["uptimerobot","lighthouse","chrome-lighthouse"],D=new Set([...k,...U]),A=new Set(k),rt=[...k,...U,...X,...V,...J,...nt];function I(e){let o=e.toLowerCase();for(let t of rt)if(o.includes(t)){let s;return A.has(t)?s="ai-user":D.has(t)?s="ai-crawl":X.includes(t)?s="search":V.includes(t)?s="sns":J.includes(t)?s="seo":s="monitoring",{name:t,isAi:D.has(t),category:s}}return null}async function st(e){if(typeof process<"u"&&process.versions?.node){let{createHash:s}=require("crypto");return s("md5").update(e,"utf8").digest("hex")}let o=new TextEncoder().encode(e),t=await crypto.subtle.digest("MD5",o);return Array.from(new Uint8Array(t),s=>s.toString(16).padStart(2,"0")).join("")}function at(e){if(!e)return"/";if(e.startsWith("http://")||e.startsWith("https://"))try{e=new URL(e).pathname}catch{}let o=e.indexOf("?");return o!==-1&&(e=e.substring(0,o)),e?e.split("/").map(t=>{if(!t)return t;try{return encodeURIComponent(decodeURIComponent(t))}catch{return encodeURIComponent(t)}}).join("/"):"/"}async function w(e,o){let t=at(e);return`${await st(t)}_${o}`}var M=/^\/(?:robots\.txt|llms\.txt|sitemap[^\/]*\.(?:xml|xsl))$/i,it=/mobile|android|iphone|phone|tablet|webos|ipad/i;async function W(e,o){let{projectId:t,cloudfrontDomain:s,prerenderDomain:n,botLogEndpoint:i,aiRender:u=!0,ocr:m=!0,aiPathPrefixes:T=[]}=o,p=o.siteDomain.replace(/^https?:\/\//,"").replace(/\/+$/,""),f=s.replace(/\/$/,""),_=new URL(e.url),r=_.pathname;if(e.headers.get("x-prerender-host")){if(M.test(r)||r===`/${t}.txt`){let{NextResponse:a}=await import("next/server");return a.next()}return null}if(r===`/${t}.txt`)try{let a=await fetch(`${n}${r}`,{redirect:"manual"});return new Response(a.body,{status:a.status,headers:{"Content-Type":"text/plain","Cache-Control":"public, max-age=3600"}})}catch{return null}if(M.test(r))try{let a=await fetch(`${n}/static${r}`,{headers:{"X-Signature":t,"X-Original-Host":p}});return new Response(a.body,{status:a.status,headers:{"Content-Type":a.headers.get("Content-Type")||"text/plain","Cache-Control":"public, max-age=3600"}})}catch{return null}let l=e.headers.get("user-agent")||"",h=I(l);if(!h)return null;let d=it.test(l)?"mobile":"desktop",y=`https://${p}${r}`,x=T.length===0||T.some(a=>r.startsWith(a));try{if(h.isAi&&u&&x){let $=await w(r,"ai"),c=await fetch(`${f}/v2/${p}/${$}.html`,{headers:{Accept:"text/html"}});if(c.ok){let g=await c.text();if(g&&g.length>100)return O(i,t,p,r,_.search,l,"hit_ai"),B(n,t,y,m,T),P(g,"HIT-AI",h.name)}let C=await w(r,"desktop"),E=await fetch(`${f}/v2/${p}/${C}.html`,{headers:{Accept:"text/html"}});if(E.ok){let g=await E.text();if(g&&g.length>100)return O(i,t,p,r,_.search,l,"hit_desktop_fallback"),B(n,t,y,m,T),P(g,"HIT-DESKTOP",h.name)}return O(i,t,p,r,_.search,l,"miss_ai"),B(n,t,y,m,T),j(n,t,y),null}let a=await w(r,d),b=await fetch(`${f}/v2/${p}/${a}.html`,{headers:{Accept:"text/html"}});if(b.ok){let $=await b.text();if($&&$.length>100)return O(i,t,p,r,_.search,l,"hit"),j(n,t,y),P($,"HIT",h.name)}}catch{}return O(i,t,p,r,_.search,l,"miss"),j(n,t,y),null}function P(e,o,t){return new Response(e,{headers:{"Content-Type":"text/html; charset=utf-8","X-Cache":o,"X-Bot":t}})}function O(e,o,t,s,n,i,u){fetch(e,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({project_id:o,url:`https://${t}${s}${n}`,domain:t,path:s,user_agent:i,phase:u})}).catch(()=>{})}function j(e,o,t){fetch(`${e}/v2/cache`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({items:[{url:t,project_id:o}]})}).catch(()=>{})}function B(e,o,t,s,n){let i={items:[{url:t,project_id:o}],ocr:s};n.length>0&&(i.path_prefixes=n),fetch(`${e}/v2/cache/ai`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(i)}).catch(()=>{})}var ct=/^\/(?:robots\.txt|llms\.txt|sitemap[^\/]*\.(?:xml|xsl))$/i,lt=/mobile|android|iphone|phone|tablet|webos|ipad/i;async function z(e,o,t,s){let{projectId:n,siteDomain:i,prerenderDomain:u,botLogEndpoint:m,aiRender:T=!0,ocr:p=!0,aiPathPrefixes:f=[]}=s,r=new URL(e.url).pathname,l=i.replace(/^https?:\/\//,"").replace(/\/+$/,"");if(e.headers.get("x-prerender-host"))return null;if(r===`/${n}.txt`)try{let c=await fetch(`${u}${r}`,{redirect:"manual"});return new Response(c.body,{status:c.status,headers:{"Content-Type":"text/plain","Cache-Control":"public, max-age=3600"}})}catch{return new Response("",{status:404})}if(ct.test(r))try{let c=await fetch(`${u}/static${r}`,{redirect:"manual",headers:{"X-Signature":n,"X-Original-Host":l}});return new Response(c.body,{status:c.status,headers:{"Content-Type":c.headers.get("Content-Type")||"text/plain","Cache-Control":"public, max-age=3600"}})}catch{return null}let h=e.headers.get("user-agent")||"",d=I(h);if(!d||!o.V2_CACHE)return null;let y=lt.test(h)?"mobile":"desktop",x=`https://${l}${r}`,a=A.has(d.name)?"ai-user":d.isAi?"ai-crawl":"standard",b=c=>t.waitUntil(c().catch(C=>console.error("[bot-proxy]",C))),$=f.length===0||f.some(c=>r.startsWith(c));try{if(d.isAi&&T&&$){let E=await w(r,"ai"),g=await o.V2_CACHE.get(E);if(g)return b(async()=>{console.log(`[BOT] ${d.name} | ${a} | hit_ai | ${r}`),await S(m,n,l,r,h,"hit_ai"),await K(u,n,x,p,f)}),N(g,"HIT-AI",d.name);let F=await w(r,"desktop"),H=await o.V2_CACHE.get(F);return H?(b(async()=>{console.log(`[BOT] ${d.name} | ${a} | hit_desktop_fallback | ${r}`),await S(m,n,l,r,h,"hit_desktop_fallback"),await K(u,n,x,p,f)}),N(H,"HIT-DESKTOP",d.name)):(b(async()=>{console.log(`[BOT] ${d.name} | ${a} | miss_ai | ${r}`),await S(m,n,l,r,h,"miss_ai"),await Promise.all([K(u,n,x,p,f),L(u,n,x)])}),null)}let c=await w(r,y),C=await o.V2_CACHE.get(c);return C?(b(async()=>{console.log(`[BOT] ${d.name} | ${a} | hit | ${r}`),await S(m,n,l,r,h,"hit"),await L(u,n,x)}),N(C,"HIT",d.name)):(b(async()=>{console.log(`[BOT] ${d.name} | ${a} | miss | ${r}`),await S(m,n,l,r,h,"miss"),await L(u,n,x)}),null)}catch(c){return console.error("[bot-proxy]",c),null}}function N(e,o,t){return new Response(e,{headers:{"Content-Type":"text/html; charset=utf-8","X-Cache":o,"X-Bot":t}})}async function S(e,o,t,s,n,i){await fetch(e,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({project_id:o,url:`https://${t}${s}`,domain:t,path:s,user_agent:n,phase:i})})}async function L(e,o,t){await fetch(`${e}/v2/cache/kv`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({items:[{url:t,project_id:o}]})})}async function K(e,o,t,s,n){let i={items:[{url:t,project_id:o}],ocr:s};n.length>0&&(i.path_prefixes=n),await fetch(`${e}/v2/cache/kv/ai`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(i)})}0&&(module.exports={cloudflareProxy,nextjsProxy});
1
+ "use strict";var F=Object.create;var E=Object.defineProperty;var G=Object.getOwnPropertyDescriptor;var q=Object.getOwnPropertyNames;var Q=Object.getPrototypeOf,Y=Object.prototype.hasOwnProperty;var Z=(e,o)=>{for(var t in o)E(e,t,{get:o[t],enumerable:!0})},H=(e,o,t,s)=>{if(o&&typeof o=="object"||typeof o=="function")for(let n of q(o))!Y.call(e,n)&&n!==t&&E(e,n,{get:()=>o[n],enumerable:!(s=G(o,n))||s.enumerable});return e};var tt=(e,o,t)=>(t=e!=null?F(Q(e)):{},H(o||!e||!e.__esModule?E(t,"default",{value:e,enumerable:!0}):t,e)),et=e=>H(E({},"__esModule",{value:!0}),e);var lt={};Z(lt,{cloudflareProxy:()=>z,nextjsProxy:()=>M});module.exports=et(lt);var I=["chatgpt-user","claude-user","perplexity-user","gemini-user","gemini-deep-research","mistralai-user","grok-user"],D=["gptbot","oai-searchbot","claudebot","claude-searchbot","google-extended","google-cloudvertexbot","perplexitybot","meta-externalagent","applebot-extended","amazonbot","cohere-ai","bytespider","deepseekbot","grokbot","ccbot","diffbot","ai2bot","petalbot"],U=["googlebot","googlebot-image","googlebot-video","googlebot-news","googleother","mediapartners-google","adsbot-google","google-inspectiontool","bingbot","bingpreview","naverbot","yeti","daumoa","baiduspider","yandexbot","duckduckbot","applebot"],X=["facebookexternalhit","linkedinbot","twitterbot","slackbot","discordbot","telegrambot","whatsapp","pinterestbot","redditbot"],V=["ahrefsbot","semrushbot","mj12bot","dotbot","dataforseobot"],ot=["uptimerobot","lighthouse","chrome-lighthouse"],v=new Set([...I,...D]),k=new Set(I),nt=[...I,...D,...U,...X,...V,...ot];function R(e){let o=e.toLowerCase();for(let t of nt)if(o.includes(t)){let s;return k.has(t)?s="ai-user":v.has(t)?s="ai-crawl":U.includes(t)?s="search":X.includes(t)?s="sns":V.includes(t)?s="seo":s="monitoring",{name:t,isAi:v.has(t),category:s}}return null}async function rt(e){if(typeof process<"u"&&process.versions?.node){let{createHash:s}=require("crypto");return s("md5").update(e,"utf8").digest("hex")}let o=new TextEncoder().encode(e),t=await crypto.subtle.digest("MD5",o);return Array.from(new Uint8Array(t),s=>s.toString(16).padStart(2,"0")).join("")}function st(e){if(!e)return"/";if(e.startsWith("http://")||e.startsWith("https://"))try{e=new URL(e).pathname}catch{}let o=e.indexOf("?");return o!==-1&&(e=e.substring(0,o)),e?e.split("/").map(t=>{if(!t)return t;try{return encodeURIComponent(decodeURIComponent(t))}catch{return encodeURIComponent(t)}}).join("/"):"/"}async function b(e,o){let t=st(e);return`${await rt(t)}_${o}`}var J=/^\/(?:robots\.txt|llms\.txt|sitemap[^\/]*\.(?:xml|xsl))$/i,at=/mobile|android|iphone|phone|tablet|webos|ipad/i;async function M(e,o){let{projectId:t,cloudfrontDomain:s,prerenderDomain:n,botLogEndpoint:a,aiRender:h=!0,ocr:f=!0,aiPathPrefixes:$=[]}=o,p=o.siteDomain.replace(/^https?:\/\//,"").replace(/\/+$/,""),w=s.replace(/\/$/,""),T=new URL(e.url),r=T.pathname;if(e.headers.get("x-prerender-host")){if(J.test(r)||r===`/${t}.txt`){let{NextResponse:i}=await import("next/server");return i.next()}return null}if(r===`/${t}.txt`)try{let i=await fetch(`${n}${r}`,{redirect:"manual"});return new Response(i.body,{status:i.status,headers:{"Content-Type":"text/plain","Cache-Control":"public, max-age=3600"}})}catch{return null}if(J.test(r))try{let i=await fetch(`${n}/static${r}`,{headers:{"X-Signature":t,"X-Original-Host":p}});return new Response(i.body,{status:i.status,headers:{"Content-Type":i.headers.get("Content-Type")||"text/plain","Cache-Control":"public, max-age=3600"}})}catch{return null}let c=e.headers.get("user-agent")||"",u=R(c);if(!u)return null;let d=at.test(c)?"mobile":"desktop",y=`https://${p}${r}`;try{if(u.isAi&&h){let g=await b(r,"ai"),l=await fetch(`${w}/v2/${p}/${g}.html`,{headers:{Accept:"text/html"}});if(l.ok){let m=await l.text();if(m&&m.length>100)return C(a,t,p,r,T.search,c,"hit_ai"),j(n,t,y,f,$),A(m,"HIT-AI",u.name)}let _=await b(r,"desktop"),S=await fetch(`${w}/v2/${p}/${_}.html`,{headers:{Accept:"text/html"}});if(S.ok){let m=await S.text();if(m&&m.length>100)return C(a,t,p,r,T.search,c,"hit_desktop_fallback"),j(n,t,y,f,$),A(m,"HIT-DESKTOP",u.name)}return C(a,t,p,r,T.search,c,"miss_ai"),j(n,t,y,f,$),P(n,t,y),null}let i=await b(r,d),x=await fetch(`${w}/v2/${p}/${i}.html`,{headers:{Accept:"text/html"}});if(x.ok){let g=await x.text();if(g&&g.length>100)return C(a,t,p,r,T.search,c,"hit"),P(n,t,y),A(g,"HIT",u.name)}}catch{}return C(a,t,p,r,T.search,c,"miss"),P(n,t,y),null}function A(e,o,t){return new Response(e,{headers:{"Content-Type":"text/html; charset=utf-8","X-Cache":o,"X-Bot":t}})}function C(e,o,t,s,n,a,h){fetch(e,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({project_id:o,url:`https://${t}${s}${n}`,domain:t,path:s,user_agent:a,phase:h})}).catch(()=>{})}function P(e,o,t){fetch(`${e}/v2/cache`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({items:[{url:t,project_id:o}]})}).catch(()=>{})}function j(e,o,t,s,n){let a={items:[{url:t,project_id:o}],ocr:s};n.length>0&&(a.path_prefixes=n),fetch(`${e}/v2/cache/ai`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(a)}).catch(()=>{})}var it=/^\/(?:robots\.txt|llms\.txt|sitemap[^\/]*\.(?:xml|xsl))$/i,ct=/mobile|android|iphone|phone|tablet|webos|ipad/i;async function z(e,o,t,s){let{projectId:n,siteDomain:a,prerenderDomain:h,botLogEndpoint:f,aiRender:$=!0,ocr:p=!0,aiPathPrefixes:w=[]}=s,r=new URL(e.url).pathname,c=a.replace(/^https?:\/\//,"").replace(/\/+$/,"");if(e.headers.get("x-prerender-host"))return null;if(r===`/${n}.txt`)try{let l=await fetch(`${h}${r}`,{redirect:"manual"});return new Response(l.body,{status:l.status,headers:{"Content-Type":"text/plain","Cache-Control":"public, max-age=3600"}})}catch{return new Response("",{status:404})}if(it.test(r))try{let l=await fetch(`${h}/static${r}`,{redirect:"manual",headers:{"X-Signature":n,"X-Original-Host":c}});return new Response(l.body,{status:l.status,headers:{"Content-Type":l.headers.get("Content-Type")||"text/plain","Cache-Control":"public, max-age=3600"}})}catch{return null}let u=e.headers.get("user-agent")||"",d=R(u);if(!d||!o.V2_CACHE)return null;let y=ct.test(u)?"mobile":"desktop",i=`https://${c}${r}`,x=k.has(d.name)?"ai-user":d.isAi?"ai-crawl":"standard",g=l=>t.waitUntil(l().catch(_=>console.error("[bot-proxy]",_)));try{if(d.isAi&&$){let S=await b(r,"ai"),m=await o.V2_CACHE.get(S);if(m)return g(async()=>{console.log(`[BOT] ${d.name} | ${x} | hit_ai | ${r}`),await O(f,n,c,r,u,"hit_ai"),await L(h,n,i,p,w)}),B(m,"HIT-AI",d.name);let W=await b(r,"desktop"),K=await o.V2_CACHE.get(W);return K?(g(async()=>{console.log(`[BOT] ${d.name} | ${x} | hit_desktop_fallback | ${r}`),await O(f,n,c,r,u,"hit_desktop_fallback"),await L(h,n,i,p,w)}),B(K,"HIT-DESKTOP",d.name)):(g(async()=>{console.log(`[BOT] ${d.name} | ${x} | miss_ai | ${r}`),await O(f,n,c,r,u,"miss_ai"),await Promise.all([L(h,n,i,p,w),N(h,n,i)])}),null)}let l=await b(r,y),_=await o.V2_CACHE.get(l);return _?(g(async()=>{console.log(`[BOT] ${d.name} | ${x} | hit | ${r}`),await O(f,n,c,r,u,"hit"),await N(h,n,i)}),B(_,"HIT",d.name)):(g(async()=>{console.log(`[BOT] ${d.name} | ${x} | miss | ${r}`),await O(f,n,c,r,u,"miss"),await N(h,n,i)}),null)}catch(l){return console.error("[bot-proxy]",l),null}}function B(e,o,t){return new Response(e,{headers:{"Content-Type":"text/html; charset=utf-8","X-Cache":o,"X-Bot":t}})}async function O(e,o,t,s,n,a){await fetch(e,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({project_id:o,url:`https://${t}${s}`,domain:t,path:s,user_agent:n,phase:a})})}async function N(e,o,t){await fetch(`${e}/v2/cache/kv`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({items:[{url:t,project_id:o}]})})}async function L(e,o,t,s,n){let a={items:[{url:t,project_id:o}],ocr:s};n.length>0&&(a.path_prefixes=n),await fetch(`${e}/v2/cache/kv/ai`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(a)})}0&&(module.exports={cloudflareProxy,nextjsProxy});
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- import{a as o}from"./chunk-UELFMNQN.js";import{a as r}from"./chunk-T6IK43SM.js";import"./chunk-62QI7OUQ.js";export{o as cloudflareProxy,r as nextjsProxy};
1
+ import{a as o}from"./chunk-HLBLRAGQ.js";import{a as r}from"./chunk-3GWBNF6R.js";import"./chunk-62QI7OUQ.js";export{o as cloudflareProxy,r as nextjsProxy};
package/dist/nextjs.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";var H=Object.create;var b=Object.defineProperty;var M=Object.getOwnPropertyDescriptor;var W=Object.getOwnPropertyNames;var X=Object.getPrototypeOf,z=Object.prototype.hasOwnProperty;var J=(e,o)=>{for(var t in o)b(e,t,{get:o[t],enumerable:!0})},I=(e,o,t,n)=>{if(o&&typeof o=="object"||typeof o=="function")for(let r of W(o))!z.call(e,r)&&r!==t&&b(e,r,{get:()=>o[r],enumerable:!(n=M(o,r))||n.enumerable});return e};var G=(e,o,t)=>(t=e!=null?H(X(e)):{},I(o||!e||!e.__esModule?b(t,"default",{value:e,enumerable:!0}):t,e)),q=e=>I(b({},"__esModule",{value:!0}),e);var et={};J(et,{nextjsProxy:()=>L});module.exports=q(et);var _=["chatgpt-user","claude-user","perplexity-user","gemini-user","gemini-deep-research","mistralai-user","grok-user"],N=["gptbot","oai-searchbot","claudebot","claude-searchbot","google-extended","google-cloudvertexbot","perplexitybot","meta-externalagent","applebot-extended","amazonbot","cohere-ai","bytespider","deepseekbot","grokbot","ccbot","diffbot","ai2bot","petalbot"],j=["googlebot","googlebot-image","googlebot-video","googlebot-news","googleother","mediapartners-google","adsbot-google","google-inspectiontool","bingbot","bingpreview","naverbot","yeti","daumoa","baiduspider","yandexbot","duckduckbot","applebot"],k=["facebookexternalhit","linkedinbot","twitterbot","slackbot","discordbot","telegrambot","whatsapp","pinterestbot","redditbot"],B=["ahrefsbot","semrushbot","mj12bot","dotbot","dataforseobot"],F=["uptimerobot","lighthouse","chrome-lighthouse"],A=new Set([..._,...N]),V=new Set(_),Q=[..._,...N,...j,...k,...B,...F];function P(e){let o=e.toLowerCase();for(let t of Q)if(o.includes(t)){let n;return V.has(t)?n="ai-user":A.has(t)?n="ai-crawl":j.includes(t)?n="search":k.includes(t)?n="sns":B.includes(t)?n="seo":n="monitoring",{name:t,isAi:A.has(t),category:n}}return null}async function Y(e){if(typeof process<"u"&&process.versions?.node){let{createHash:n}=require("crypto");return n("md5").update(e,"utf8").digest("hex")}let o=new TextEncoder().encode(e),t=await crypto.subtle.digest("MD5",o);return Array.from(new Uint8Array(t),n=>n.toString(16).padStart(2,"0")).join("")}function Z(e){if(!e)return"/";if(e.startsWith("http://")||e.startsWith("https://"))try{e=new URL(e).pathname}catch{}let o=e.indexOf("?");return o!==-1&&(e=e.substring(0,o)),e?e.split("/").map(t=>{if(!t)return t;try{return encodeURIComponent(decodeURIComponent(t))}catch{return encodeURIComponent(t)}}).join("/"):"/"}async function x(e,o){let t=Z(e);return`${await Y(t)}_${o}`}var K=/^\/(?:robots\.txt|llms\.txt|sitemap[^\/]*\.(?:xml|xsl))$/i,tt=/mobile|android|iphone|phone|tablet|webos|ipad/i;async function L(e,o){let{projectId:t,cloudfrontDomain:n,prerenderDomain:r,botLogEndpoint:a,aiRender:y=!0,ocr:T=!0,aiPathPrefixes:g=[]}=o,c=o.siteDomain.replace(/^https?:\/\//,"").replace(/\/+$/,""),w=n.replace(/\/$/,""),d=new URL(e.url),s=d.pathname;if(e.headers.get("x-prerender-host")){if(K.test(s)||s===`/${t}.txt`){let{NextResponse:i}=await import("next/server");return i.next()}return null}if(s===`/${t}.txt`)try{let i=await fetch(`${r}${s}`,{redirect:"manual"});return new Response(i.body,{status:i.status,headers:{"Content-Type":"text/plain","Cache-Control":"public, max-age=3600"}})}catch{return null}if(K.test(s))try{let i=await fetch(`${r}/static${s}`,{headers:{"X-Signature":t,"X-Original-Host":c}});return new Response(i.body,{status:i.status,headers:{"Content-Type":i.headers.get("Content-Type")||"text/plain","Cache-Control":"public, max-age=3600"}})}catch{return null}let l=e.headers.get("user-agent")||"",u=P(l);if(!u)return null;let v=tt.test(l)?"mobile":"desktop",h=`https://${c}${s}`,U=g.length===0||g.some(i=>s.startsWith(i));try{if(u.isAi&&y&&U){let m=await x(s,"ai"),R=await fetch(`${w}/v2/${c}/${m}.html`,{headers:{Accept:"text/html"}});if(R.ok){let p=await R.text();if(p&&p.length>100)return f(a,t,c,s,d.search,l,"hit_ai"),$(r,t,h,T,g),O(p,"HIT-AI",u.name)}let D=await x(s,"desktop"),E=await fetch(`${w}/v2/${c}/${D}.html`,{headers:{Accept:"text/html"}});if(E.ok){let p=await E.text();if(p&&p.length>100)return f(a,t,c,s,d.search,l,"hit_desktop_fallback"),$(r,t,h,T,g),O(p,"HIT-DESKTOP",u.name)}return f(a,t,c,s,d.search,l,"miss_ai"),$(r,t,h,T,g),S(r,t,h),null}let i=await x(s,v),C=await fetch(`${w}/v2/${c}/${i}.html`,{headers:{Accept:"text/html"}});if(C.ok){let m=await C.text();if(m&&m.length>100)return f(a,t,c,s,d.search,l,"hit"),S(r,t,h),O(m,"HIT",u.name)}}catch{}return f(a,t,c,s,d.search,l,"miss"),S(r,t,h),null}function O(e,o,t){return new Response(e,{headers:{"Content-Type":"text/html; charset=utf-8","X-Cache":o,"X-Bot":t}})}function f(e,o,t,n,r,a,y){fetch(e,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({project_id:o,url:`https://${t}${n}${r}`,domain:t,path:n,user_agent:a,phase:y})}).catch(()=>{})}function S(e,o,t){fetch(`${e}/v2/cache`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({items:[{url:t,project_id:o}]})}).catch(()=>{})}function $(e,o,t,n,r){let a={items:[{url:t,project_id:o}],ocr:n};r.length>0&&(a.path_prefixes=r),fetch(`${e}/v2/cache/ai`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(a)}).catch(()=>{})}0&&(module.exports={nextjsProxy});
1
+ "use strict";var D=Object.create;var f=Object.defineProperty;var H=Object.getOwnPropertyDescriptor;var M=Object.getOwnPropertyNames;var X=Object.getPrototypeOf,z=Object.prototype.hasOwnProperty;var J=(e,o)=>{for(var t in o)f(e,t,{get:o[t],enumerable:!0})},I=(e,o,t,n)=>{if(o&&typeof o=="object"||typeof o=="function")for(let r of M(o))!z.call(e,r)&&r!==t&&f(e,r,{get:()=>o[r],enumerable:!(n=H(o,r))||n.enumerable});return e};var W=(e,o,t)=>(t=e!=null?D(X(e)):{},I(o||!e||!e.__esModule?f(t,"default",{value:e,enumerable:!0}):t,e)),G=e=>I(f({},"__esModule",{value:!0}),e);var tt={};J(tt,{nextjsProxy:()=>L});module.exports=G(tt);var _=["chatgpt-user","claude-user","perplexity-user","gemini-user","gemini-deep-research","mistralai-user","grok-user"],j=["gptbot","oai-searchbot","claudebot","claude-searchbot","google-extended","google-cloudvertexbot","perplexitybot","meta-externalagent","applebot-extended","amazonbot","cohere-ai","bytespider","deepseekbot","grokbot","ccbot","diffbot","ai2bot","petalbot"],k=["googlebot","googlebot-image","googlebot-video","googlebot-news","googleother","mediapartners-google","adsbot-google","google-inspectiontool","bingbot","bingpreview","naverbot","yeti","daumoa","baiduspider","yandexbot","duckduckbot","applebot"],A=["facebookexternalhit","linkedinbot","twitterbot","slackbot","discordbot","telegrambot","whatsapp","pinterestbot","redditbot"],B=["ahrefsbot","semrushbot","mj12bot","dotbot","dataforseobot"],q=["uptimerobot","lighthouse","chrome-lighthouse"],N=new Set([..._,...j]),F=new Set(_),V=[..._,...j,...k,...A,...B,...q];function P(e){let o=e.toLowerCase();for(let t of V)if(o.includes(t)){let n;return F.has(t)?n="ai-user":N.has(t)?n="ai-crawl":k.includes(t)?n="search":A.includes(t)?n="sns":B.includes(t)?n="seo":n="monitoring",{name:t,isAi:N.has(t),category:n}}return null}async function Q(e){if(typeof process<"u"&&process.versions?.node){let{createHash:n}=require("crypto");return n("md5").update(e,"utf8").digest("hex")}let o=new TextEncoder().encode(e),t=await crypto.subtle.digest("MD5",o);return Array.from(new Uint8Array(t),n=>n.toString(16).padStart(2,"0")).join("")}function Y(e){if(!e)return"/";if(e.startsWith("http://")||e.startsWith("https://"))try{e=new URL(e).pathname}catch{}let o=e.indexOf("?");return o!==-1&&(e=e.substring(0,o)),e?e.split("/").map(t=>{if(!t)return t;try{return encodeURIComponent(decodeURIComponent(t))}catch{return encodeURIComponent(t)}}).join("/"):"/"}async function b(e,o){let t=Y(e);return`${await Q(t)}_${o}`}var K=/^\/(?:robots\.txt|llms\.txt|sitemap[^\/]*\.(?:xml|xsl))$/i,Z=/mobile|android|iphone|phone|tablet|webos|ipad/i;async function L(e,o){let{projectId:t,cloudfrontDomain:n,prerenderDomain:r,botLogEndpoint:i,aiRender:x=!0,ocr:y=!0,aiPathPrefixes:T=[]}=o,a=o.siteDomain.replace(/^https?:\/\//,"").replace(/\/+$/,""),w=n.replace(/\/$/,""),d=new URL(e.url),s=d.pathname;if(e.headers.get("x-prerender-host")){if(K.test(s)||s===`/${t}.txt`){let{NextResponse:c}=await import("next/server");return c.next()}return null}if(s===`/${t}.txt`)try{let c=await fetch(`${r}${s}`,{redirect:"manual"});return new Response(c.body,{status:c.status,headers:{"Content-Type":"text/plain","Cache-Control":"public, max-age=3600"}})}catch{return null}if(K.test(s))try{let c=await fetch(`${r}/static${s}`,{headers:{"X-Signature":t,"X-Original-Host":a}});return new Response(c.body,{status:c.status,headers:{"Content-Type":c.headers.get("Content-Type")||"text/plain","Cache-Control":"public, max-age=3600"}})}catch{return null}let p=e.headers.get("user-agent")||"",g=P(p);if(!g)return null;let v=Z.test(p)?"mobile":"desktop",h=`https://${a}${s}`;try{if(g.isAi&&x){let u=await b(s,"ai"),R=await fetch(`${w}/v2/${a}/${u}.html`,{headers:{Accept:"text/html"}});if(R.ok){let l=await R.text();if(l&&l.length>100)return m(i,t,a,s,d.search,p,"hit_ai"),$(r,t,h,y,T),O(l,"HIT-AI",g.name)}let U=await b(s,"desktop"),E=await fetch(`${w}/v2/${a}/${U}.html`,{headers:{Accept:"text/html"}});if(E.ok){let l=await E.text();if(l&&l.length>100)return m(i,t,a,s,d.search,p,"hit_desktop_fallback"),$(r,t,h,y,T),O(l,"HIT-DESKTOP",g.name)}return m(i,t,a,s,d.search,p,"miss_ai"),$(r,t,h,y,T),S(r,t,h),null}let c=await b(s,v),C=await fetch(`${w}/v2/${a}/${c}.html`,{headers:{Accept:"text/html"}});if(C.ok){let u=await C.text();if(u&&u.length>100)return m(i,t,a,s,d.search,p,"hit"),S(r,t,h),O(u,"HIT",g.name)}}catch{}return m(i,t,a,s,d.search,p,"miss"),S(r,t,h),null}function O(e,o,t){return new Response(e,{headers:{"Content-Type":"text/html; charset=utf-8","X-Cache":o,"X-Bot":t}})}function m(e,o,t,n,r,i,x){fetch(e,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({project_id:o,url:`https://${t}${n}${r}`,domain:t,path:n,user_agent:i,phase:x})}).catch(()=>{})}function S(e,o,t){fetch(`${e}/v2/cache`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({items:[{url:t,project_id:o}]})}).catch(()=>{})}function $(e,o,t,n,r){let i={items:[{url:t,project_id:o}],ocr:n};r.length>0&&(i.path_prefixes=r),fetch(`${e}/v2/cache/ai`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(i)}).catch(()=>{})}0&&(module.exports={nextjsProxy});
package/dist/nextjs.js CHANGED
@@ -1 +1 @@
1
- import{a as o}from"./chunk-T6IK43SM.js";import"./chunk-62QI7OUQ.js";export{o as nextjsProxy};
1
+ import{a as o}from"./chunk-3GWBNF6R.js";import"./chunk-62QI7OUQ.js";export{o as nextjsProxy};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@searchos/bot-proxy",
3
- "version": "1.0.3",
3
+ "version": "1.0.4",
4
4
  "description": "SearchOS 봇 프록시 — Next.js, Cloudflare Worker용 봇 감지 + 캐시 프록시",
5
5
  "type": "module",
6
6
  "exports": {
@@ -1 +0,0 @@
1
- import{b as O,c as x}from"./chunk-62QI7OUQ.js";var P=/^\/(?:robots\.txt|llms\.txt|sitemap[^\/]*\.(?:xml|xsl))$/i,A=/mobile|android|iphone|phone|tablet|webos|ipad/i;async function L(r,a){let{projectId:t,cloudfrontDomain:p,prerenderDomain:n,botLogEndpoint:o,aiRender:y=!0,ocr:$=!0,aiPathPrefixes:u=[]}=a,i=a.siteDomain.replace(/^https?:\/\//,"").replace(/\/+$/,""),b=p.replace(/\/$/,""),l=new URL(r.url),e=l.pathname;if(r.headers.get("x-prerender-host")){if(P.test(e)||e===`/${t}.txt`){let{NextResponse:s}=await import("next/server");return s.next()}return null}if(e===`/${t}.txt`)try{let s=await fetch(`${n}${e}`,{redirect:"manual"});return new Response(s.body,{status:s.status,headers:{"Content-Type":"text/plain","Cache-Control":"public, max-age=3600"}})}catch{return null}if(P.test(e))try{let s=await fetch(`${n}/static${e}`,{headers:{"X-Signature":t,"X-Original-Host":i}});return new Response(s.body,{status:s.status,headers:{"Content-Type":s.headers.get("Content-Type")||"text/plain","Cache-Control":"public, max-age=3600"}})}catch{return null}let c=r.headers.get("user-agent")||"",m=O(c);if(!m)return null;let k=A.test(c)?"mobile":"desktop",d=`https://${i}${e}`,I=u.length===0||u.some(s=>e.startsWith(s));try{if(m.isAi&&y&&I){let g=await x(e,"ai"),_=await fetch(`${b}/v2/${i}/${g}.html`,{headers:{Accept:"text/html"}});if(_.ok){let h=await _.text();if(h&&h.length>100)return f(o,t,i,e,l.search,c,"hit_ai"),R(n,t,d,$,u),w(h,"HIT-AI",m.name)}let S=await x(e,"desktop"),j=await fetch(`${b}/v2/${i}/${S}.html`,{headers:{Accept:"text/html"}});if(j.ok){let h=await j.text();if(h&&h.length>100)return f(o,t,i,e,l.search,c,"hit_desktop_fallback"),R(n,t,d,$,u),w(h,"HIT-DESKTOP",m.name)}return f(o,t,i,e,l.search,c,"miss_ai"),R(n,t,d,$,u),T(n,t,d),null}let s=await x(e,k),C=await fetch(`${b}/v2/${i}/${s}.html`,{headers:{Accept:"text/html"}});if(C.ok){let g=await C.text();if(g&&g.length>100)return f(o,t,i,e,l.search,c,"hit"),T(n,t,d),w(g,"HIT",m.name)}}catch{}return f(o,t,i,e,l.search,c,"miss"),T(n,t,d),null}function w(r,a,t){return new Response(r,{headers:{"Content-Type":"text/html; charset=utf-8","X-Cache":a,"X-Bot":t}})}function f(r,a,t,p,n,o,y){fetch(r,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({project_id:a,url:`https://${t}${p}${n}`,domain:t,path:p,user_agent:o,phase:y})}).catch(()=>{})}function T(r,a,t){fetch(`${r}/v2/cache`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({items:[{url:t,project_id:a}]})}).catch(()=>{})}function R(r,a,t,p,n){let o={items:[{url:t,project_id:a}],ocr:p};n.length>0&&(o.path_prefixes=n),fetch(`${r}/v2/cache/ai`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(o)}).catch(()=>{})}export{L as a};
@@ -1 +0,0 @@
1
- import{a as E,b as R,c as $}from"./chunk-62QI7OUQ.js";var I=/^\/(?:robots\.txt|llms\.txt|sitemap[^\/]*\.(?:xml|xsl))$/i,j=/mobile|android|iphone|phone|tablet|webos|ipad/i;async function D(o,a,i,p){let{projectId:e,siteDomain:u,prerenderDomain:r,botLogEndpoint:d,aiRender:k=!0,ocr:C=!0,aiPathPrefixes:g=[]}=p,t=new URL(o.url).pathname,c=u.replace(/^https?:\/\//,"").replace(/\/+$/,"");if(o.headers.get("x-prerender-host"))return null;if(t===`/${e}.txt`)try{let n=await fetch(`${r}${t}`,{redirect:"manual"});return new Response(n.body,{status:n.status,headers:{"Content-Type":"text/plain","Cache-Control":"public, max-age=3600"}})}catch{return new Response("",{status:404})}if(I.test(t))try{let n=await fetch(`${r}/static${t}`,{redirect:"manual",headers:{"X-Signature":e,"X-Original-Host":c}});return new Response(n.body,{status:n.status,headers:{"Content-Type":n.headers.get("Content-Type")||"text/plain","Cache-Control":"public, max-age=3600"}})}catch{return null}let l=o.headers.get("user-agent")||"",s=R(l);if(!s||!a.V2_CACHE)return null;let P=j.test(l)?"mobile":"desktop",h=`https://${c}${t}`,m=E.has(s.name)?"ai-user":s.isAi?"ai-crawl":"standard",y=n=>i.waitUntil(n().catch(w=>console.error("[bot-proxy]",w))),A=g.length===0||g.some(n=>t.startsWith(n));try{if(s.isAi&&k&&A){let H=await $(t,"ai"),x=await a.V2_CACHE.get(H);if(x)return y(async()=>{console.log(`[BOT] ${s.name} | ${m} | hit_ai | ${t}`),await f(d,e,c,t,l,"hit_ai"),await _(r,e,h,C,g)}),b(x,"HIT-AI",s.name);let S=await $(t,"desktop"),O=await a.V2_CACHE.get(S);return O?(y(async()=>{console.log(`[BOT] ${s.name} | ${m} | hit_desktop_fallback | ${t}`),await f(d,e,c,t,l,"hit_desktop_fallback"),await _(r,e,h,C,g)}),b(O,"HIT-DESKTOP",s.name)):(y(async()=>{console.log(`[BOT] ${s.name} | ${m} | miss_ai | ${t}`),await f(d,e,c,t,l,"miss_ai"),await Promise.all([_(r,e,h,C,g),T(r,e,h)])}),null)}let n=await $(t,P),w=await a.V2_CACHE.get(n);return w?(y(async()=>{console.log(`[BOT] ${s.name} | ${m} | hit | ${t}`),await f(d,e,c,t,l,"hit"),await T(r,e,h)}),b(w,"HIT",s.name)):(y(async()=>{console.log(`[BOT] ${s.name} | ${m} | miss | ${t}`),await f(d,e,c,t,l,"miss"),await T(r,e,h)}),null)}catch(n){return console.error("[bot-proxy]",n),null}}function b(o,a,i){return new Response(o,{headers:{"Content-Type":"text/html; charset=utf-8","X-Cache":a,"X-Bot":i}})}async function f(o,a,i,p,e,u){await fetch(o,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({project_id:a,url:`https://${i}${p}`,domain:i,path:p,user_agent:e,phase:u})})}async function T(o,a,i){await fetch(`${o}/v2/cache/kv`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({items:[{url:i,project_id:a}]})})}async function _(o,a,i,p,e){let u={items:[{url:i,project_id:a}],ocr:p};e.length>0&&(u.path_prefixes=e),await fetch(`${o}/v2/cache/kv/ai`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(u)})}export{D as a};