@searchos/bot-proxy 1.0.3 → 1.0.5

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 x,b as V,c as g}from"./chunk-62QI7OUQ.js";var S=/^\/(?:robots\.txt|llms\.txt|sitemap[^\/]*\.(?:xml|xsl))$/i,L=/mobile|android|iphone|phone|tablet|webos|ipad/i,U=604800;async function D(s,t,e,a){let{projectId:n,siteDomain:i,prerenderDomain:o,botLogEndpoint:c,aiRender:m=!0,ocr:y=!0,aiPathPrefixes:C=[]}=a,r=new URL(s.url).pathname,h=i.replace(/^https?:\/\//,"").replace(/\/+$/,"");if(s.method==="POST"){if(r==="/__update-edge-cache")return I(s,t);if(r==="/__purge-edge-cache")return v(s,t);if(r==="/__read-edge-cache")return B(s,t)}if(s.headers.get("x-prerender-host"))return null;if(r===`/${n}.txt`)try{let u=await fetch(`${o}${r}`,{redirect:"manual"});return new Response(u.body,{status:u.status,headers:{"Content-Type":"text/plain","Cache-Control":"public, max-age=3600"}})}catch{return new Response("",{status:404})}if(S.test(r))try{let u=await fetch(`${o}/static${r}`,{redirect:"manual",headers:{"X-Signature":n,"X-Original-Host":h}});return new Response(u.body,{status:u.status,headers:{"Content-Type":u.headers.get("Content-Type")||"text/plain","Cache-Control":"public, max-age=3600"}})}catch{return null}let d=s.headers.get("user-agent")||"",l=V(d);if(!l||!t.V2_CACHE)return null;let O=L.test(d)?"mobile":"desktop",f=`https://${h}${r}`,w=x.has(l.name)?"ai-user":l.isAi?"ai-crawl":"standard",_=u=>e.waitUntil(u().catch(T=>console.error("[bot-proxy]",T)));try{if(l.isAi&&m){let P=await g(r,"ai"),A=await t.V2_CACHE.get(P);if(A)return _(async()=>{console.log(`[BOT] ${l.name} | ${w} | hit_ai | ${r}`),await E(c,n,h,r,d,"hit_ai"),await b(o,n,f,y,C)}),$(A,"HIT-AI",l.name);let j=await g(r,"desktop"),H=await t.V2_CACHE.get(j);return H?(_(async()=>{console.log(`[BOT] ${l.name} | ${w} | hit_desktop_fallback | ${r}`),await E(c,n,h,r,d,"hit_desktop_fallback"),await b(o,n,f,y,C)}),$(H,"HIT-DESKTOP",l.name)):(_(async()=>{console.log(`[BOT] ${l.name} | ${w} | miss_ai | ${r}`),await E(c,n,h,r,d,"miss_ai"),await Promise.all([b(o,n,f,y,C),R(o,n,f)])}),null)}let u=await g(r,O),T=await t.V2_CACHE.get(u);return T?(_(async()=>{console.log(`[BOT] ${l.name} | ${w} | hit | ${r}`),await E(c,n,h,r,d,"hit"),await R(o,n,f)}),$(T,"HIT",l.name)):(_(async()=>{console.log(`[BOT] ${l.name} | ${w} | miss | ${r}`),await E(c,n,h,r,d,"miss"),await R(o,n,f)}),null)}catch(u){return console.error("[bot-proxy]",u),null}}function $(s,t,e){return new Response(s,{headers:{"Content-Type":"text/html; charset=utf-8","X-Cache":t,"X-Bot":e}})}async function E(s,t,e,a,n,i){await fetch(s,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({project_id:t,url:`https://${e}${a}`,domain:e,path:a,user_agent:n,phase:i})})}async function R(s,t,e){await fetch(`${s}/v2/cache/kv`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({items:[{url:e,project_id:t}]})})}function p(s,t=200){return new Response(JSON.stringify(s),{status:t,headers:{"Content-Type":"application/json"}})}async function I(s,t){try{let{entries:e=[]}=await s.json();if(!t.V2_CACHE)return p({success:!1,error:"V2_CACHE \uBC14\uC778\uB529 \uC5C6\uC74C"},500);if(!e.length)return p({success:!1,error:"entries \uD544\uC218"},400);let a=0;for(let n of e){let{url:i,html:o,variant:c="",device:m="desktop"}=n||{};if(!i||!o)continue;let y=c.startsWith("v2_")?c.substring(3):m,C=new URL(i).pathname||"/",k=await g(C,y);await t.V2_CACHE.put(k,o,{expirationTtl:U}),a++}return p({success:!0,updated:a})}catch(e){return p({success:!1,error:e.message},500)}}async function v(s,t){try{let{urls:e=[],variant:a=""}=await s.json();if(!t.V2_CACHE)return p({success:!1,error:"V2_CACHE \uBC14\uC778\uB529 \uC5C6\uC74C"},500);if(!e.length)return p({success:!1,error:"urls \uD544\uC218"},400);let n=a.startsWith("v2_")?a.substring(3):"desktop",i=0;for(let o of e){let c=new URL(o).pathname||"/",m=await g(c,n);await t.V2_CACHE.delete(m),i++}return p({success:!0,deleted:i})}catch(e){return p({success:!1,error:e.message},500)}}async function B(s,t){try{let{url:e,variant:a=""}=await s.json();if(!t.V2_CACHE)return p({success:!1,error:"V2_CACHE \uBC14\uC778\uB529 \uC5C6\uC74C"},500);if(!e)return p({success:!1,error:"url \uD544\uC218"},400);let n=a.startsWith("v2_")?a.substring(3):"desktop",i=new URL(e).pathname||"/",o=await g(i,n),c=await t.V2_CACHE.get(o);return p({success:!0,html:c??null})}catch(e){return p({success:!1,error:e.message},500)}}async function b(s,t,e,a,n){let i={items:[{url:e,project_id:t}],ocr:a};n.length>0&&(i.path_prefixes=n),await fetch(`${s}/v2/cache/kv/ai`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(i)})}export{D 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 E=Object.defineProperty;var D=Object.getOwnPropertyDescriptor;var W=Object.getOwnPropertyNames;var J=Object.prototype.hasOwnProperty;var M=(t,n)=>{for(var e in n)E(t,e,{get:n[e],enumerable:!0})},X=(t,n,e,r)=>{if(n&&typeof n=="object"||typeof n=="function")for(let o of W(n))!J.call(t,o)&&o!==e&&E(t,o,{get:()=>n[o],enumerable:!(r=D(n,o))||r.enumerable});return t};var z=t=>X(E({},"__esModule",{value:!0}),t);var ot={};M(ot,{cloudflareProxy:()=>j});module.exports=z(ot);var T=["chatgpt-user","claude-user","perplexity-user","gemini-user","gemini-deep-research","mistralai-user","grok-user"],B=["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"],P=["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"],N=["ahrefsbot","semrushbot","mj12bot","dotbot","dataforseobot"],G=["uptimerobot","lighthouse","chrome-lighthouse"],I=new Set([...T,...B]),O=new Set(T),F=[...T,...B,...P,...V,...N,...G];function U(t){let n=t.toLowerCase();for(let e of F)if(n.includes(e)){let r;return O.has(e)?r="ai-user":I.has(e)?r="ai-crawl":P.includes(e)?r="search":V.includes(e)?r="sns":N.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 n=new TextEncoder().encode(t),e=await crypto.subtle.digest("MD5",n);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 n=t.indexOf("?");return n!==-1&&(t=t.substring(0,n)),t?t.split("/").map(e=>{if(!e)return e;try{return encodeURIComponent(decodeURIComponent(e))}catch{return encodeURIComponent(e)}}).join("/"):"/"}async function h(t,n){let e=Q(t);return`${await q(e)}_${n}`}var Y=/^\/(?:robots\.txt|llms\.txt|sitemap[^\/]*\.(?:xml|xsl))$/i,Z=/mobile|android|iphone|phone|tablet|webos|ipad/i,tt=604800;async function j(t,n,e,r){let{projectId:o,siteDomain:i,prerenderDomain:a,botLogEndpoint:c,aiRender:m=!0,ocr:y=!0,aiPathPrefixes:b=[]}=r,s=new URL(t.url).pathname,d=i.replace(/^https?:\/\//,"").replace(/\/+$/,"");if(t.method==="POST"){if(s==="/__update-edge-cache")return et(t,n);if(s==="/__purge-edge-cache")return nt(t,n);if(s==="/__read-edge-cache")return rt(t,n)}if(t.headers.get("x-prerender-host"))return null;if(s===`/${o}.txt`)try{let u=await fetch(`${a}${s}`,{redirect:"manual"});return new Response(u.body,{status:u.status,headers:{"Content-Type":"text/plain","Cache-Control":"public, max-age=3600"}})}catch{return new Response("",{status:404})}if(Y.test(s))try{let u=await fetch(`${a}/static${s}`,{redirect:"manual",headers:{"X-Signature":o,"X-Original-Host":d}});return new Response(u.body,{status:u.status,headers:{"Content-Type":u.headers.get("Content-Type")||"text/plain","Cache-Control":"public, max-age=3600"}})}catch{return null}let g=t.headers.get("user-agent")||"",l=U(g);if(!l||!n.V2_CACHE)return null;let K=Z.test(g)?"mobile":"desktop",f=`https://${d}${s}`,w=O.has(l.name)?"ai-user":l.isAi?"ai-crawl":"standard",C=u=>e.waitUntil(u().catch(x=>console.error("[bot-proxy]",x)));try{if(l.isAi&&m){let L=await h(s,"ai"),$=await n.V2_CACHE.get(L);if($)return C(async()=>{console.log(`[BOT] ${l.name} | ${w} | hit_ai | ${s}`),await _(c,o,d,s,g,"hit_ai"),await A(a,o,f,y,b)}),R($,"HIT-AI",l.name);let v=await h(s,"desktop"),H=await n.V2_CACHE.get(v);return H?(C(async()=>{console.log(`[BOT] ${l.name} | ${w} | hit_desktop_fallback | ${s}`),await _(c,o,d,s,g,"hit_desktop_fallback"),await A(a,o,f,y,b)}),R(H,"HIT-DESKTOP",l.name)):(C(async()=>{console.log(`[BOT] ${l.name} | ${w} | miss_ai | ${s}`),await _(c,o,d,s,g,"miss_ai"),await Promise.all([A(a,o,f,y,b),k(a,o,f)])}),null)}let u=await h(s,K),x=await n.V2_CACHE.get(u);return x?(C(async()=>{console.log(`[BOT] ${l.name} | ${w} | hit | ${s}`),await _(c,o,d,s,g,"hit"),await k(a,o,f)}),R(x,"HIT",l.name)):(C(async()=>{console.log(`[BOT] ${l.name} | ${w} | miss | ${s}`),await _(c,o,d,s,g,"miss"),await k(a,o,f)}),null)}catch(u){return console.error("[bot-proxy]",u),null}}function R(t,n,e){return new Response(t,{headers:{"Content-Type":"text/html; charset=utf-8","X-Cache":n,"X-Bot":e}})}async function _(t,n,e,r,o,i){await fetch(t,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({project_id:n,url:`https://${e}${r}`,domain:e,path:r,user_agent:o,phase:i})})}async function k(t,n,e){await fetch(`${t}/v2/cache/kv`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({items:[{url:e,project_id:n}]})})}function p(t,n=200){return new Response(JSON.stringify(t),{status:n,headers:{"Content-Type":"application/json"}})}async function et(t,n){try{let{entries:e=[]}=await t.json();if(!n.V2_CACHE)return p({success:!1,error:"V2_CACHE \uBC14\uC778\uB529 \uC5C6\uC74C"},500);if(!e.length)return p({success:!1,error:"entries \uD544\uC218"},400);let r=0;for(let o of e){let{url:i,html:a,variant:c="",device:m="desktop"}=o||{};if(!i||!a)continue;let y=c.startsWith("v2_")?c.substring(3):m,b=new URL(i).pathname||"/",S=await h(b,y);await n.V2_CACHE.put(S,a,{expirationTtl:tt}),r++}return p({success:!0,updated:r})}catch(e){return p({success:!1,error:e.message},500)}}async function nt(t,n){try{let{urls:e=[],variant:r=""}=await t.json();if(!n.V2_CACHE)return p({success:!1,error:"V2_CACHE \uBC14\uC778\uB529 \uC5C6\uC74C"},500);if(!e.length)return p({success:!1,error:"urls \uD544\uC218"},400);let o=r.startsWith("v2_")?r.substring(3):"desktop",i=0;for(let a of e){let c=new URL(a).pathname||"/",m=await h(c,o);await n.V2_CACHE.delete(m),i++}return p({success:!0,deleted:i})}catch(e){return p({success:!1,error:e.message},500)}}async function rt(t,n){try{let{url:e,variant:r=""}=await t.json();if(!n.V2_CACHE)return p({success:!1,error:"V2_CACHE \uBC14\uC778\uB529 \uC5C6\uC74C"},500);if(!e)return p({success:!1,error:"url \uD544\uC218"},400);let o=r.startsWith("v2_")?r.substring(3):"desktop",i=new URL(e).pathname||"/",a=await h(i,o),c=await n.V2_CACHE.get(a);return p({success:!0,html:c??null})}catch(e){return p({success:!1,error:e.message},500)}}async function A(t,n,e,r,o){let i={items:[{url:e,project_id:n}],ocr:r};o.length>0&&(i.path_prefixes=o),await fetch(`${t}/v2/cache/kv/ai`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(i)})}0&&(module.exports={cloudflareProxy});
@@ -11,13 +11,6 @@ interface CloudflareProxyOptions {
11
11
  /** AI 렌더 경로 prefix (빈 배열 = 전체 경로) */
12
12
  aiPathPrefixes?: string[];
13
13
  }
14
- /**
15
- * Cloudflare Worker에서 봇 요청을 KV 캐시로 프록시.
16
- * 봇이 아니거나 캐시 미스면 null 반환.
17
- *
18
- * AI 봇: ai 캐시 → desktop 폴백 → null (origin)
19
- * 일반 봇: desktop/mobile 캐시 → null (origin)
20
- */
21
14
  declare function cloudflareProxy(request: Request, env: {
22
15
  V2_CACHE?: KVNamespace;
23
16
  [key: string]: unknown;
@@ -11,13 +11,6 @@ interface CloudflareProxyOptions {
11
11
  /** AI 렌더 경로 prefix (빈 배열 = 전체 경로) */
12
12
  aiPathPrefixes?: string[];
13
13
  }
14
- /**
15
- * Cloudflare Worker에서 봇 요청을 KV 캐시로 프록시.
16
- * 봇이 아니거나 캐시 미스면 null 반환.
17
- *
18
- * AI 봇: ai 캐시 → desktop 폴백 → null (origin)
19
- * 일반 봇: desktop/mobile 캐시 → null (origin)
20
- */
21
14
  declare function cloudflareProxy(request: Request, env: {
22
15
  V2_CACHE?: KVNamespace;
23
16
  [key: string]: unknown;
@@ -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-YO3LY7GV.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 k=Object.defineProperty;var Q=Object.getOwnPropertyDescriptor;var Y=Object.getOwnPropertyNames;var Z=Object.getPrototypeOf,q=Object.prototype.hasOwnProperty;var tt=(e,n)=>{for(var t in n)k(e,t,{get:n[t],enumerable:!0})},K=(e,n,t,s)=>{if(n&&typeof n=="object"||typeof n=="function")for(let r of Y(n))!q.call(e,r)&&r!==t&&k(e,r,{get:()=>n[r],enumerable:!(s=Q(n,r))||s.enumerable});return e};var et=(e,n,t)=>(t=e!=null?F(Z(e)):{},K(n||!e||!e.__esModule?k(t,"default",{value:e,enumerable:!0}):t,e)),nt=e=>K(k({},"__esModule",{value:!0}),e);var gt={};tt(gt,{cloudflareProxy:()=>z,nextjsProxy:()=>M});module.exports=nt(gt);var S=["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"],D=["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"],J=["ahrefsbot","semrushbot","mj12bot","dotbot","dataforseobot"],rt=["uptimerobot","lighthouse","chrome-lighthouse"],v=new Set([...S,...U]),P=new Set(S),st=[...S,...U,...D,...X,...J,...rt];function A(e){let n=e.toLowerCase();for(let t of st)if(n.includes(t)){let s;return P.has(t)?s="ai-user":v.has(t)?s="ai-crawl":D.includes(t)?s="search":X.includes(t)?s="sns":J.includes(t)?s="seo":s="monitoring",{name:t,isAi:v.has(t),category:s}}return null}async function ot(e){if(typeof process<"u"&&process.versions?.node){let{createHash:s}=require("crypto");return s("md5").update(e,"utf8").digest("hex")}let n=new TextEncoder().encode(e),t=await crypto.subtle.digest("MD5",n);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 n=e.indexOf("?");return n!==-1&&(e=e.substring(0,n)),e?e.split("/").map(t=>{if(!t)return t;try{return encodeURIComponent(decodeURIComponent(t))}catch{return encodeURIComponent(t)}}).join("/"):"/"}async function y(e,n){let t=at(e);return`${await ot(t)}_${n}`}var W=/^\/(?:robots\.txt|llms\.txt|sitemap[^\/]*\.(?:xml|xsl))$/i,it=/mobile|android|iphone|phone|tablet|webos|ipad/i;async function M(e,n){let{projectId:t,cloudfrontDomain:s,prerenderDomain:r,botLogEndpoint:a,aiRender:i=!0,ocr:l=!0,aiPathPrefixes:b=[]}=n,p=n.siteDomain.replace(/^https?:\/\//,"").replace(/\/+$/,""),w=s.replace(/\/$/,""),C=new URL(e.url),o=C.pathname;if(e.headers.get("x-prerender-host")){if(W.test(o)||o===`/${t}.txt`){let{NextResponse:c}=await import("next/server");return c.next()}return null}if(o===`/${t}.txt`)try{let c=await fetch(`${r}${o}`,{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(W.test(o))try{let c=await fetch(`${r}/static${o}`,{headers:{"X-Signature":t,"X-Original-Host":p}});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 u=e.headers.get("user-agent")||"",g=A(u);if(!g)return null;let h=it.test(u)?"mobile":"desktop",_=`https://${p}${o}`;try{if(g.isAi&&i){let m=await y(o,"ai"),d=await fetch(`${w}/v2/${p}/${m}.html`,{headers:{Accept:"text/html"}});if(d.ok){let x=await d.text();if(x&&x.length>100)return $(a,t,p,o,C.search,u,"hit_ai"),H(r,t,_,l,b),j(x,"HIT-AI",g.name)}let E=await y(o,"desktop"),O=await fetch(`${w}/v2/${p}/${E}.html`,{headers:{Accept:"text/html"}});if(O.ok){let x=await O.text();if(x&&x.length>100)return $(a,t,p,o,C.search,u,"hit_desktop_fallback"),H(r,t,_,l,b),j(x,"HIT-DESKTOP",g.name)}return $(a,t,p,o,C.search,u,"miss_ai"),H(r,t,_,l,b),I(r,t,_),null}let c=await y(o,h),T=await fetch(`${w}/v2/${p}/${c}.html`,{headers:{Accept:"text/html"}});if(T.ok){let m=await T.text();if(m&&m.length>100)return $(a,t,p,o,C.search,u,"hit"),I(r,t,_),j(m,"HIT",g.name)}}catch{}return $(a,t,p,o,C.search,u,"miss"),I(r,t,_),null}function j(e,n,t){return new Response(e,{headers:{"Content-Type":"text/html; charset=utf-8","X-Cache":n,"X-Bot":t}})}function $(e,n,t,s,r,a,i){fetch(e,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({project_id:n,url:`https://${t}${s}${r}`,domain:t,path:s,user_agent:a,phase:i})}).catch(()=>{})}function I(e,n,t){fetch(`${e}/v2/cache`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({items:[{url:t,project_id:n}]})}).catch(()=>{})}function H(e,n,t,s,r){let a={items:[{url:t,project_id:n}],ocr:s};r.length>0&&(a.path_prefixes=r),fetch(`${e}/v2/cache/ai`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(a)}).catch(()=>{})}var ct=/^\/(?:robots\.txt|llms\.txt|sitemap[^\/]*\.(?:xml|xsl))$/i,lt=/mobile|android|iphone|phone|tablet|webos|ipad/i,pt=604800;async function z(e,n,t,s){let{projectId:r,siteDomain:a,prerenderDomain:i,botLogEndpoint:l,aiRender:b=!0,ocr:p=!0,aiPathPrefixes:w=[]}=s,o=new URL(e.url).pathname,u=a.replace(/^https?:\/\//,"").replace(/\/+$/,"");if(e.method==="POST"){if(o==="/__update-edge-cache")return ut(e,n);if(o==="/__purge-edge-cache")return dt(e,n);if(o==="/__read-edge-cache")return ht(e,n)}if(e.headers.get("x-prerender-host"))return null;if(o===`/${r}.txt`)try{let d=await fetch(`${i}${o}`,{redirect:"manual"});return new Response(d.body,{status:d.status,headers:{"Content-Type":"text/plain","Cache-Control":"public, max-age=3600"}})}catch{return new Response("",{status:404})}if(ct.test(o))try{let d=await fetch(`${i}/static${o}`,{redirect:"manual",headers:{"X-Signature":r,"X-Original-Host":u}});return new Response(d.body,{status:d.status,headers:{"Content-Type":d.headers.get("Content-Type")||"text/plain","Cache-Control":"public, max-age=3600"}})}catch{return null}let g=e.headers.get("user-agent")||"",h=A(g);if(!h||!n.V2_CACHE)return null;let _=lt.test(g)?"mobile":"desktop",c=`https://${u}${o}`,T=P.has(h.name)?"ai-user":h.isAi?"ai-crawl":"standard",m=d=>t.waitUntil(d().catch(E=>console.error("[bot-proxy]",E)));try{if(h.isAi&&b){let O=await y(o,"ai"),x=await n.V2_CACHE.get(O);if(x)return m(async()=>{console.log(`[BOT] ${h.name} | ${T} | hit_ai | ${o}`),await R(l,r,u,o,g,"hit_ai"),await L(i,r,c,p,w)}),N(x,"HIT-AI",h.name);let G=await y(o,"desktop"),V=await n.V2_CACHE.get(G);return V?(m(async()=>{console.log(`[BOT] ${h.name} | ${T} | hit_desktop_fallback | ${o}`),await R(l,r,u,o,g,"hit_desktop_fallback"),await L(i,r,c,p,w)}),N(V,"HIT-DESKTOP",h.name)):(m(async()=>{console.log(`[BOT] ${h.name} | ${T} | miss_ai | ${o}`),await R(l,r,u,o,g,"miss_ai"),await Promise.all([L(i,r,c,p,w),B(i,r,c)])}),null)}let d=await y(o,_),E=await n.V2_CACHE.get(d);return E?(m(async()=>{console.log(`[BOT] ${h.name} | ${T} | hit | ${o}`),await R(l,r,u,o,g,"hit"),await B(i,r,c)}),N(E,"HIT",h.name)):(m(async()=>{console.log(`[BOT] ${h.name} | ${T} | miss | ${o}`),await R(l,r,u,o,g,"miss"),await B(i,r,c)}),null)}catch(d){return console.error("[bot-proxy]",d),null}}function N(e,n,t){return new Response(e,{headers:{"Content-Type":"text/html; charset=utf-8","X-Cache":n,"X-Bot":t}})}async function R(e,n,t,s,r,a){await fetch(e,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({project_id:n,url:`https://${t}${s}`,domain:t,path:s,user_agent:r,phase:a})})}async function B(e,n,t){await fetch(`${e}/v2/cache/kv`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({items:[{url:t,project_id:n}]})})}function f(e,n=200){return new Response(JSON.stringify(e),{status:n,headers:{"Content-Type":"application/json"}})}async function ut(e,n){try{let{entries:t=[]}=await e.json();if(!n.V2_CACHE)return f({success:!1,error:"V2_CACHE \uBC14\uC778\uB529 \uC5C6\uC74C"},500);if(!t.length)return f({success:!1,error:"entries \uD544\uC218"},400);let s=0;for(let r of t){let{url:a,html:i,variant:l="",device:b="desktop"}=r||{};if(!a||!i)continue;let p=l.startsWith("v2_")?l.substring(3):b,w=new URL(a).pathname||"/",C=await y(w,p);await n.V2_CACHE.put(C,i,{expirationTtl:pt}),s++}return f({success:!0,updated:s})}catch(t){return f({success:!1,error:t.message},500)}}async function dt(e,n){try{let{urls:t=[],variant:s=""}=await e.json();if(!n.V2_CACHE)return f({success:!1,error:"V2_CACHE \uBC14\uC778\uB529 \uC5C6\uC74C"},500);if(!t.length)return f({success:!1,error:"urls \uD544\uC218"},400);let r=s.startsWith("v2_")?s.substring(3):"desktop",a=0;for(let i of t){let l=new URL(i).pathname||"/",b=await y(l,r);await n.V2_CACHE.delete(b),a++}return f({success:!0,deleted:a})}catch(t){return f({success:!1,error:t.message},500)}}async function ht(e,n){try{let{url:t,variant:s=""}=await e.json();if(!n.V2_CACHE)return f({success:!1,error:"V2_CACHE \uBC14\uC778\uB529 \uC5C6\uC74C"},500);if(!t)return f({success:!1,error:"url \uD544\uC218"},400);let r=s.startsWith("v2_")?s.substring(3):"desktop",a=new URL(t).pathname||"/",i=await y(a,r),l=await n.V2_CACHE.get(i);return f({success:!0,html:l??null})}catch(t){return f({success:!1,error:t.message},500)}}async function L(e,n,t,s,r){let a={items:[{url:t,project_id:n}],ocr:s};r.length>0&&(a.path_prefixes=r),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-YO3LY7GV.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.5",
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};