@searchos/bot-proxy 1.0.8 → 1.0.9

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 P,c as S,d as $}from"./chunk-BVZHYMX6.js";var A=/^\/(?:robots\.txt|llms\.txt|sitemap[^\/]*\.(?:xml|xsl))$/i,L=/mobile|android|iphone|phone|tablet|webos|ipad/i;async function H(e,n){let{projectId:t,cloudfrontDomain:l,renderDomain:s,botLogEndpoint:i,aiRender:w=!0,ocr:g=!0,aiPathPrefixes:b=[]}=n,o=n.siteDomain.replace(/^https?:\/\//,"").replace(/\/+$/,""),T=l.replace(/\/$/,""),a=new URL(e.url),r=a.pathname;if(e.headers.get("x-prerender-host")){if(A.test(r)||r===`/${t}.txt`){let{NextResponse:h}=await import("next/server");return h.next()}return null}if(r===`/${t}.txt`)return new Response(t,{status:200,headers:{"Content-Type":"text/plain","Cache-Control":"public, max-age=3600"}});if(A.test(r)){try{let h=await fetch(`${s}/static${r}`,{headers:{"X-Signature":t,"X-Original-Host":o}});if(h.ok)return new Response(h.body,{status:200,headers:{"Content-Type":h.headers.get("Content-Type")||"text/plain","Cache-Control":"public, max-age=3600"}})}catch{}return null}let c=e.headers.get("user-agent")||"",m=P(c);if(!m)return null;let D=L.test(c)?"mobile":"desktop",j=S(a.search),y=j?`${r}?${j}`:r,d=`https://${o}${y}`,u=v(e);try{if(m.isAi&&w){let f=await $(y,"ai"),I=await fetch(`${T}/v2/${o}/${f}.html`,{headers:{Accept:"text/html"}});if(I.ok){let p=await I.text();if(p&&p.length>100)return x(i,u,t,o,r,a.search,c,"hit_ai"),_(s,t,d,g,b),R(p,"HIT-AI",m.name)}let E=await $(y,"desktop"),O=await fetch(`${T}/v2/${o}/${E}.html`,{headers:{Accept:"text/html"}});if(O.ok){let p=await O.text();if(p&&p.length>100)return x(i,u,t,o,r,a.search,c,"hit_desktop_fallback"),_(s,t,d,g,b),R(p,"HIT-DESKTOP",m.name)}return x(i,u,t,o,r,a.search,c,"miss_ai"),_(s,t,d,g,b),C(s,t,d),null}let h=await $(y,D),k=await fetch(`${T}/v2/${o}/${h}.html`,{headers:{Accept:"text/html"}});if(k.ok){let f=await k.text();if(f&&f.length>100)return x(i,u,t,o,r,a.search,c,"hit"),C(s,t,d),R(f,"HIT",m.name)}}catch{}return x(i,u,t,o,r,a.search,c,"miss"),C(s,t,d),null}function R(e,n,t){return new Response(e,{headers:{"Content-Type":"text/html; charset=utf-8","X-Cache":n,"X-Bot":t}})}function v(e){let n=e.headers,t=n.get("x-forwarded-for")||"";return n.get("cf-connecting-ip")||n.get("x-real-ip")||t.split(",")[0].trim()||""}function x(e,n,t,l,s,i,w,g){fetch(e,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({project_id:t,url:`https://${l}${s}${i}`,domain:l,path:s,user_agent:w,phase:g,client_ip:n})}).catch(()=>{})}function C(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 _(e,n,t,l,s){let i={items:[{url:t,project_id:n}],ocr:l};s.length>0&&(i.path_prefixes=s),fetch(`${e}/v2/cache/ai`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(i)}).catch(()=>{})}export{H as a};
package/dist/index.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";var tt=Object.create;var I=Object.defineProperty;var et=Object.getOwnPropertyDescriptor;var nt=Object.getOwnPropertyNames;var st=Object.getPrototypeOf,rt=Object.prototype.hasOwnProperty;var ot=(e,n)=>{for(var t in n)I(e,t,{get:n[t],enumerable:!0})},W=(e,n,t,r)=>{if(n&&typeof n=="object"||typeof n=="function")for(let s of nt(n))!rt.call(e,s)&&s!==t&&I(e,s,{get:()=>n[s],enumerable:!(r=et(n,s))||r.enumerable});return e};var X=(e,n,t)=>(t=e!=null?tt(st(e)):{},W(n||!e||!e.__esModule?I(t,"default",{value:e,enumerable:!0}):t,e)),at=e=>W(I({},"__esModule",{value:!0}),e);var xt={};ot(xt,{cloudflareProxy:()=>q,nextjsProxy:()=>Z});module.exports=at(xt);var H=["chatgpt-user","claude-user","perplexity-user","gemini-user","gemini-deep-research","mistralai-user","grok-user"],M=["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"],F=["googlebot","googlebot-image","googlebot-video","googlebot-news","googleother","mediapartners-google","adsbot-google","google-inspectiontool","bingbot","bingpreview","naverbot","yeti","daumoa","baiduspider","yandexbot","duckduckbot","applebot"],Q=["facebookexternalhit","linkedinbot","twitterbot","slackbot","discordbot","telegrambot","whatsapp","pinterestbot","redditbot"],z=["ahrefsbot","semrushbot","mj12bot","dotbot","dataforseobot"],it=["uptimerobot","lighthouse","chrome-lighthouse"],J=new Set([...H,...M]),N=new Set(H),ct=[...H,...M,...F,...Q,...z,...it];function P(e){let n=e.toLowerCase();for(let t of ct)if(n.includes(t)){let r;return N.has(t)?r="ai-user":J.has(t)?r="ai-crawl":F.includes(t)?r="search":Q.includes(t)?r="sns":z.includes(t)?r="seo":r="monitoring",{name:t,isAi:J.has(t),category:r}}return null}var lt=new Set(["utm_source","utm_medium","utm_campaign","utm_term","utm_content","fbclid","fb_action_ids","fb_action_types","fb_source","fb_ref","gclid","gclsrc","dclid","gbraid","wbraid","msclkid","hsa_cam","hsa_grp","hsa_mt","hsa_src","hsa_ad","hsa_acc","hsa_net","hsa_ver","hsa_la","hsa_ol","hsa_kw","_hsenc","_hsmi","_ga","_gl","_bhlid","mc_cid","mc_eid","oly_anon_id","oly_enc_id","ttclid","yclid","irclickid"]);function k(e){if(!e||(e.startsWith("?")&&(e=e.substring(1)),!e))return"";let n=[];for(let t of e.split("&")){if(!t)continue;let r=t.indexOf("="),s=r===-1?t:t.substring(0,r);lt.has(s.toLowerCase())||n.push(t)}return n.join("&")}function G(e){return encodeURIComponent(e).replace(/[!'()*]/g,n=>"%"+n.charCodeAt(0).toString(16).toUpperCase())}function pt(e){if(!e)return"/";let n,t,r=e.slice(0,8).toLowerCase();if(r.startsWith("http://")||r.startsWith("https://"))try{let o=new URL(e);n=o.pathname,t=o.search.startsWith("?")?o.search.substring(1):o.search}catch{n=e,t=""}else{let o=e.indexOf("?");o===-1?(n=e,t=""):(n=e.substring(0,o),t=e.substring(o+1))}n||(n="/");let s=n.split("/").map(o=>{if(!o)return o;try{return G(decodeURIComponent(o))}catch{return G(o)}}).join("/"),i=k(t);return i?`${s}?${i}`:s}async function ut(e){if(typeof process<"u"&&process.versions?.node){let{createHash:r}=await import("crypto");return r("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),r=>r.toString(16).padStart(2,"0")).join("")}async function _(e,n){let t=pt(e);return`${await ut(t)}_${n}`}var Y=/^\/(?:robots\.txt|llms\.txt|sitemap[^\/]*\.(?:xml|xsl))$/i,dt=/mobile|android|iphone|phone|tablet|webos|ipad/i;async function Z(e,n){let{projectId:t,cloudfrontDomain:r,renderDomain:s,botLogEndpoint:i,aiRender:o=!0,ocr:l=!0,aiPathPrefixes:b=[]}=n,p=n.siteDomain.replace(/^https?:\/\//,"").replace(/\/+$/,""),w=r.replace(/\/$/,""),x=new URL(e.url),a=x.pathname;if(e.headers.get("x-prerender-host")){if(Y.test(a)||a===`/${t}.txt`){let{NextResponse:h}=await import("next/server");return h.next()}return null}if(a===`/${t}.txt`)return new Response(t,{status:200,headers:{"Content-Type":"text/plain","Cache-Control":"public, max-age=3600"}});if(Y.test(a)){try{let h=await fetch(`${s}/static${a}`,{headers:{"X-Signature":t,"X-Original-Host":p}});if(h.ok)return new Response(h.body,{status:200,headers:{"Content-Type":h.headers.get("Content-Type")||"text/plain","Cache-Control":"public, max-age=3600"}})}catch{}return null}let u=e.headers.get("user-agent")||"",g=P(u);if(!g)return null;let d=dt.test(u)?"mobile":"desktop",O=k(x.search),$=O?`${a}?${O}`:a,y=`https://${p}${$}`,f=gt(e);try{if(g.isAi&&o){let c=await _($,"ai"),E=await fetch(`${w}/v2/${p}/${c}.html`,{headers:{Accept:"text/html"}});if(E.ok){let C=await E.text();if(C&&C.length>100)return A(i,f,t,p,a,x.search,u,"hit_ai"),L(s,t,y,l,b),B(C,"HIT-AI",g.name)}let j=await _($,"desktop"),R=await fetch(`${w}/v2/${p}/${j}.html`,{headers:{Accept:"text/html"}});if(R.ok){let C=await R.text();if(C&&C.length>100)return A(i,f,t,p,a,x.search,u,"hit_desktop_fallback"),L(s,t,y,l,b),B(C,"HIT-DESKTOP",g.name)}return A(i,f,t,p,a,x.search,u,"miss_ai"),L(s,t,y,l,b),K(s,t,y),null}let h=await _($,d),T=await fetch(`${w}/v2/${p}/${h}.html`,{headers:{Accept:"text/html"}});if(T.ok){let c=await T.text();if(c&&c.length>100)return A(i,f,t,p,a,x.search,u,"hit"),K(s,t,y),B(c,"HIT",g.name)}}catch{}return A(i,f,t,p,a,x.search,u,"miss"),K(s,t,y),null}function B(e,n,t){return new Response(e,{headers:{"Content-Type":"text/html; charset=utf-8","X-Cache":n,"X-Bot":t}})}function gt(e){let n=e.headers,t=n.get("x-forwarded-for")||"";return n.get("cf-connecting-ip")||n.get("x-real-ip")||t.split(",")[0].trim()||""}function A(e,n,t,r,s,i,o,l){let b={"Content-Type":"application/json"};n&&(b["X-Forwarded-For"]=n),fetch(e,{method:"POST",headers:b,body:JSON.stringify({project_id:t,url:`https://${r}${s}${i}`,domain:r,path:s,user_agent:o,phase:l})}).catch(()=>{})}function K(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 L(e,n,t,r,s){let i={items:[{url:t,project_id:n}],ocr:r};s.length>0&&(i.path_prefixes=s),fetch(`${e}/v2/cache/ai`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(i)}).catch(()=>{})}var ht=/^\/(?:robots\.txt|llms\.txt|sitemap[^\/]*\.(?:xml|xsl))$/i,ft=/mobile|android|iphone|phone|tablet|webos|ipad/i,mt=604800;async function q(e,n,t,r){let{projectId:s,siteDomain:i,renderDomain:o,botLogEndpoint:l,aiRender:b=!0,ocr:p=!0,aiPathPrefixes:w=[]}=r,x=new URL(e.url),a=x.pathname,u=i.replace(/^https?:\/\//,"").replace(/\/+$/,"");if(e.method==="POST"){if(a==="/__update-edge-cache")return yt(e,n);if(a==="/__purge-edge-cache")return _t(e,n);if(a==="/__read-edge-cache")return bt(e,n)}if(e.headers.get("x-prerender-host"))return null;if(a===`/${s}.txt`)try{let c=await fetch(`${o}${a}`,{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(ht.test(a))try{let c=await fetch(`${o}/static${a}`,{redirect:"manual",headers:{"X-Signature":s,"X-Original-Host":u}});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 g=e.headers.get("user-agent")||"",d=P(g);if(!d||!n.V2_CACHE)return null;let O=ft.test(g)?"mobile":"desktop",$=k(x.search),y=$?`${a}?${$}`:a,f=`https://${u}${y}`,h=N.has(d.name)?"ai-user":d.isAi?"ai-crawl":"standard",T=c=>t.waitUntil(c().catch(E=>console.error("[bot-proxy]",E)));try{if(d.isAi&&b){let j=await _(y,"ai"),R=await n.V2_CACHE.get(j);if(R)return T(async()=>{console.log(`[BOT] ${d.name} | ${h} | hit_ai | ${a}`),await S(l,s,u,a,g,"hit_ai"),await U(o,s,f,p,w)}),V(R,"HIT-AI",d.name);let C=await _(y,"desktop"),D=await n.V2_CACHE.get(C);return D?(T(async()=>{console.log(`[BOT] ${d.name} | ${h} | hit_desktop_fallback | ${a}`),await S(l,s,u,a,g,"hit_desktop_fallback"),await U(o,s,f,p,w)}),V(D,"HIT-DESKTOP",d.name)):(T(async()=>{console.log(`[BOT] ${d.name} | ${h} | miss_ai | ${a}`),await S(l,s,u,a,g,"miss_ai"),await Promise.all([U(o,s,f,p,w),v(o,s,f)])}),null)}let c=await _(y,O),E=await n.V2_CACHE.get(c);return E?(T(async()=>{console.log(`[BOT] ${d.name} | ${h} | hit | ${a}`),await S(l,s,u,a,g,"hit"),await v(o,s,f)}),V(E,"HIT",d.name)):(T(async()=>{console.log(`[BOT] ${d.name} | ${h} | miss | ${a}`),await S(l,s,u,a,g,"miss"),await v(o,s,f)}),null)}catch(c){return console.error("[bot-proxy]",c),null}}function V(e,n,t){return new Response(e,{headers:{"Content-Type":"text/html; charset=utf-8","X-Cache":n,"X-Bot":t}})}async function S(e,n,t,r,s,i){await fetch(e,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({project_id:n,url:`https://${t}${r}`,domain:t,path:r,user_agent:s,phase:i})})}async function v(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 m(e,n=200){return new Response(JSON.stringify(e),{status:n,headers:{"Content-Type":"application/json"}})}async function yt(e,n){try{let{entries:t=[]}=await e.json();if(!n.V2_CACHE)return m({success:!1,error:"V2_CACHE \uBC14\uC778\uB529 \uC5C6\uC74C"},500);if(!t.length)return m({success:!1,error:"entries \uD544\uC218"},400);let r=0;for(let s of t){let{url:i,html:o,variant:l="",device:b="desktop"}=s||{};if(!i||!o)continue;let p=l.startsWith("v2_")?l.substring(3):b,w=await _(i,p);await n.V2_CACHE.put(w,o,{expirationTtl:mt}),r++}return m({success:!0,updated:r})}catch(t){return m({success:!1,error:t.message},500)}}async function _t(e,n){try{let{urls:t=[],variant:r=""}=await e.json();if(!n.V2_CACHE)return m({success:!1,error:"V2_CACHE \uBC14\uC778\uB529 \uC5C6\uC74C"},500);if(!t.length)return m({success:!1,error:"urls \uD544\uC218"},400);let s=r.startsWith("v2_")?r.substring(3):"desktop",i=0;for(let o of t){let l=await _(o,s);await n.V2_CACHE.delete(l),i++}return m({success:!0,deleted:i})}catch(t){return m({success:!1,error:t.message},500)}}async function bt(e,n){try{let{url:t,variant:r=""}=await e.json();if(!n.V2_CACHE)return m({success:!1,error:"V2_CACHE \uBC14\uC778\uB529 \uC5C6\uC74C"},500);if(!t)return m({success:!1,error:"url \uD544\uC218"},400);let s=r.startsWith("v2_")?r.substring(3):"desktop",i=await _(t,s),o=await n.V2_CACHE.get(i);return m({success:!0,html:o??null})}catch(t){return m({success:!1,error:t.message},500)}}async function U(e,n,t,r,s){let i={items:[{url:t,project_id:n}],ocr:r};s.length>0&&(i.path_prefixes=s),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 tt=Object.create;var I=Object.defineProperty;var et=Object.getOwnPropertyDescriptor;var nt=Object.getOwnPropertyNames;var st=Object.getPrototypeOf,rt=Object.prototype.hasOwnProperty;var ot=(e,n)=>{for(var t in n)I(e,t,{get:n[t],enumerable:!0})},W=(e,n,t,r)=>{if(n&&typeof n=="object"||typeof n=="function")for(let s of nt(n))!rt.call(e,s)&&s!==t&&I(e,s,{get:()=>n[s],enumerable:!(r=et(n,s))||r.enumerable});return e};var X=(e,n,t)=>(t=e!=null?tt(st(e)):{},W(n||!e||!e.__esModule?I(t,"default",{value:e,enumerable:!0}):t,e)),at=e=>W(I({},"__esModule",{value:!0}),e);var xt={};ot(xt,{cloudflareProxy:()=>q,nextjsProxy:()=>Z});module.exports=at(xt);var H=["chatgpt-user","claude-user","perplexity-user","gemini-user","gemini-deep-research","mistralai-user","grok-user"],M=["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"],Q=["googlebot","googlebot-image","googlebot-video","googlebot-news","googleother","mediapartners-google","adsbot-google","google-inspectiontool","bingbot","bingpreview","naverbot","yeti","daumoa","baiduspider","yandexbot","duckduckbot","applebot"],z=["facebookexternalhit","linkedinbot","twitterbot","slackbot","discordbot","telegrambot","whatsapp","pinterestbot","redditbot"],G=["ahrefsbot","semrushbot","mj12bot","dotbot","dataforseobot"],it=["uptimerobot","lighthouse","chrome-lighthouse"],J=new Set([...H,...M]),N=new Set(H),ct=[...H,...M,...Q,...z,...G,...it];function P(e){let n=e.toLowerCase();for(let t of ct)if(n.includes(t)){let r;return N.has(t)?r="ai-user":J.has(t)?r="ai-crawl":Q.includes(t)?r="search":z.includes(t)?r="sns":G.includes(t)?r="seo":r="monitoring",{name:t,isAi:J.has(t),category:r}}return null}var lt=new Set(["utm_source","utm_medium","utm_campaign","utm_term","utm_content","fbclid","fb_action_ids","fb_action_types","fb_source","fb_ref","gclid","gclsrc","dclid","gbraid","wbraid","msclkid","hsa_cam","hsa_grp","hsa_mt","hsa_src","hsa_ad","hsa_acc","hsa_net","hsa_ver","hsa_la","hsa_ol","hsa_kw","_hsenc","_hsmi","_ga","_gl","_bhlid","mc_cid","mc_eid","oly_anon_id","oly_enc_id","ttclid","yclid","irclickid"]);function k(e){if(!e||(e.startsWith("?")&&(e=e.substring(1)),!e))return"";let n=[];for(let t of e.split("&")){if(!t)continue;let r=t.indexOf("="),s=r===-1?t:t.substring(0,r);lt.has(s.toLowerCase())||n.push(t)}return n.join("&")}function F(e){return encodeURIComponent(e).replace(/[!'()*]/g,n=>"%"+n.charCodeAt(0).toString(16).toUpperCase())}function pt(e){if(!e)return"/";let n,t,r=e.slice(0,8).toLowerCase();if(r.startsWith("http://")||r.startsWith("https://"))try{let o=new URL(e);n=o.pathname,t=o.search.startsWith("?")?o.search.substring(1):o.search}catch{n=e,t=""}else{let o=e.indexOf("?");o===-1?(n=e,t=""):(n=e.substring(0,o),t=e.substring(o+1))}n||(n="/");let s=n.split("/").map(o=>{if(!o)return o;try{return F(decodeURIComponent(o))}catch{return F(o)}}).join("/"),i=k(t);return i?`${s}?${i}`:s}async function ut(e){if(typeof process<"u"&&process.versions?.node){let{createHash:r}=await import("crypto");return r("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),r=>r.toString(16).padStart(2,"0")).join("")}async function _(e,n){let t=pt(e);return`${await ut(t)}_${n}`}var Y=/^\/(?:robots\.txt|llms\.txt|sitemap[^\/]*\.(?:xml|xsl))$/i,dt=/mobile|android|iphone|phone|tablet|webos|ipad/i;async function Z(e,n){let{projectId:t,cloudfrontDomain:r,renderDomain:s,botLogEndpoint:i,aiRender:o=!0,ocr:l=!0,aiPathPrefixes:T=[]}=n,p=n.siteDomain.replace(/^https?:\/\//,"").replace(/\/+$/,""),x=r.replace(/\/$/,""),b=new URL(e.url),a=b.pathname;if(e.headers.get("x-prerender-host")){if(Y.test(a)||a===`/${t}.txt`){let{NextResponse:h}=await import("next/server");return h.next()}return null}if(a===`/${t}.txt`)return new Response(t,{status:200,headers:{"Content-Type":"text/plain","Cache-Control":"public, max-age=3600"}});if(Y.test(a)){try{let h=await fetch(`${s}/static${a}`,{headers:{"X-Signature":t,"X-Original-Host":p}});if(h.ok)return new Response(h.body,{status:200,headers:{"Content-Type":h.headers.get("Content-Type")||"text/plain","Cache-Control":"public, max-age=3600"}})}catch{}return null}let u=e.headers.get("user-agent")||"",g=P(u);if(!g)return null;let d=dt.test(u)?"mobile":"desktop",O=k(b.search),$=O?`${a}?${O}`:a,y=`https://${p}${$}`,f=gt(e);try{if(g.isAi&&o){let c=await _($,"ai"),E=await fetch(`${x}/v2/${p}/${c}.html`,{headers:{Accept:"text/html"}});if(E.ok){let w=await E.text();if(w&&w.length>100)return A(i,f,t,p,a,b.search,u,"hit_ai"),L(s,t,y,l,T),B(w,"HIT-AI",g.name)}let j=await _($,"desktop"),R=await fetch(`${x}/v2/${p}/${j}.html`,{headers:{Accept:"text/html"}});if(R.ok){let w=await R.text();if(w&&w.length>100)return A(i,f,t,p,a,b.search,u,"hit_desktop_fallback"),L(s,t,y,l,T),B(w,"HIT-DESKTOP",g.name)}return A(i,f,t,p,a,b.search,u,"miss_ai"),L(s,t,y,l,T),K(s,t,y),null}let h=await _($,d),C=await fetch(`${x}/v2/${p}/${h}.html`,{headers:{Accept:"text/html"}});if(C.ok){let c=await C.text();if(c&&c.length>100)return A(i,f,t,p,a,b.search,u,"hit"),K(s,t,y),B(c,"HIT",g.name)}}catch{}return A(i,f,t,p,a,b.search,u,"miss"),K(s,t,y),null}function B(e,n,t){return new Response(e,{headers:{"Content-Type":"text/html; charset=utf-8","X-Cache":n,"X-Bot":t}})}function gt(e){let n=e.headers,t=n.get("x-forwarded-for")||"";return n.get("cf-connecting-ip")||n.get("x-real-ip")||t.split(",")[0].trim()||""}function A(e,n,t,r,s,i,o,l){fetch(e,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({project_id:t,url:`https://${r}${s}${i}`,domain:r,path:s,user_agent:o,phase:l,client_ip:n})}).catch(()=>{})}function K(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 L(e,n,t,r,s){let i={items:[{url:t,project_id:n}],ocr:r};s.length>0&&(i.path_prefixes=s),fetch(`${e}/v2/cache/ai`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(i)}).catch(()=>{})}var ht=/^\/(?:robots\.txt|llms\.txt|sitemap[^\/]*\.(?:xml|xsl))$/i,ft=/mobile|android|iphone|phone|tablet|webos|ipad/i,mt=604800;async function q(e,n,t,r){let{projectId:s,siteDomain:i,renderDomain:o,botLogEndpoint:l,aiRender:T=!0,ocr:p=!0,aiPathPrefixes:x=[]}=r,b=new URL(e.url),a=b.pathname,u=i.replace(/^https?:\/\//,"").replace(/\/+$/,"");if(e.method==="POST"){if(a==="/__update-edge-cache")return yt(e,n);if(a==="/__purge-edge-cache")return _t(e,n);if(a==="/__read-edge-cache")return bt(e,n)}if(e.headers.get("x-prerender-host"))return null;if(a===`/${s}.txt`)try{let c=await fetch(`${o}${a}`,{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(ht.test(a))try{let c=await fetch(`${o}/static${a}`,{redirect:"manual",headers:{"X-Signature":s,"X-Original-Host":u}});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 g=e.headers.get("user-agent")||"",d=P(g);if(!d||!n.V2_CACHE)return null;let O=ft.test(g)?"mobile":"desktop",$=k(b.search),y=$?`${a}?${$}`:a,f=`https://${u}${y}`,h=N.has(d.name)?"ai-user":d.isAi?"ai-crawl":"standard",C=c=>t.waitUntil(c().catch(E=>console.error("[bot-proxy]",E)));try{if(d.isAi&&T){let j=await _(y,"ai"),R=await n.V2_CACHE.get(j);if(R)return C(async()=>{console.log(`[BOT] ${d.name} | ${h} | hit_ai | ${a}`),await S(l,s,u,a,g,"hit_ai"),await U(o,s,f,p,x)}),V(R,"HIT-AI",d.name);let w=await _(y,"desktop"),D=await n.V2_CACHE.get(w);return D?(C(async()=>{console.log(`[BOT] ${d.name} | ${h} | hit_desktop_fallback | ${a}`),await S(l,s,u,a,g,"hit_desktop_fallback"),await U(o,s,f,p,x)}),V(D,"HIT-DESKTOP",d.name)):(C(async()=>{console.log(`[BOT] ${d.name} | ${h} | miss_ai | ${a}`),await S(l,s,u,a,g,"miss_ai"),await Promise.all([U(o,s,f,p,x),v(o,s,f)])}),null)}let c=await _(y,O),E=await n.V2_CACHE.get(c);return E?(C(async()=>{console.log(`[BOT] ${d.name} | ${h} | hit | ${a}`),await S(l,s,u,a,g,"hit"),await v(o,s,f)}),V(E,"HIT",d.name)):(C(async()=>{console.log(`[BOT] ${d.name} | ${h} | miss | ${a}`),await S(l,s,u,a,g,"miss"),await v(o,s,f)}),null)}catch(c){return console.error("[bot-proxy]",c),null}}function V(e,n,t){return new Response(e,{headers:{"Content-Type":"text/html; charset=utf-8","X-Cache":n,"X-Bot":t}})}async function S(e,n,t,r,s,i){await fetch(e,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({project_id:n,url:`https://${t}${r}`,domain:t,path:r,user_agent:s,phase:i})})}async function v(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 m(e,n=200){return new Response(JSON.stringify(e),{status:n,headers:{"Content-Type":"application/json"}})}async function yt(e,n){try{let{entries:t=[]}=await e.json();if(!n.V2_CACHE)return m({success:!1,error:"V2_CACHE \uBC14\uC778\uB529 \uC5C6\uC74C"},500);if(!t.length)return m({success:!1,error:"entries \uD544\uC218"},400);let r=0;for(let s of t){let{url:i,html:o,variant:l="",device:T="desktop"}=s||{};if(!i||!o)continue;let p=l.startsWith("v2_")?l.substring(3):T,x=await _(i,p);await n.V2_CACHE.put(x,o,{expirationTtl:mt}),r++}return m({success:!0,updated:r})}catch(t){return m({success:!1,error:t.message},500)}}async function _t(e,n){try{let{urls:t=[],variant:r=""}=await e.json();if(!n.V2_CACHE)return m({success:!1,error:"V2_CACHE \uBC14\uC778\uB529 \uC5C6\uC74C"},500);if(!t.length)return m({success:!1,error:"urls \uD544\uC218"},400);let s=r.startsWith("v2_")?r.substring(3):"desktop",i=0;for(let o of t){let l=await _(o,s);await n.V2_CACHE.delete(l),i++}return m({success:!0,deleted:i})}catch(t){return m({success:!1,error:t.message},500)}}async function bt(e,n){try{let{url:t,variant:r=""}=await e.json();if(!n.V2_CACHE)return m({success:!1,error:"V2_CACHE \uBC14\uC778\uB529 \uC5C6\uC74C"},500);if(!t)return m({success:!1,error:"url \uD544\uC218"},400);let s=r.startsWith("v2_")?r.substring(3):"desktop",i=await _(t,s),o=await n.V2_CACHE.get(i);return m({success:!0,html:o??null})}catch(t){return m({success:!1,error:t.message},500)}}async function U(e,n,t,r,s){let i={items:[{url:t,project_id:n}],ocr:r};s.length>0&&(i.path_prefixes=s),await fetch(`${e}/v2/cache/kv/ai`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(i)})}0&&(module.exports={cloudflareProxy,nextjsProxy});
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- import{a as o}from"./chunk-JXQQEZ5V.js";import{a as r}from"./chunk-3FWDO7FS.js";import"./chunk-BVZHYMX6.js";export{o as cloudflareProxy,r as nextjsProxy};
1
+ import{a as o}from"./chunk-JXQQEZ5V.js";import{a as r}from"./chunk-NYRQ66HM.js";import"./chunk-BVZHYMX6.js";export{o as cloudflareProxy,r as nextjsProxy};
package/dist/nextjs.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";var F=Object.create;var w=Object.defineProperty;var G=Object.getOwnPropertyDescriptor;var J=Object.getOwnPropertyNames;var Q=Object.getPrototypeOf,V=Object.prototype.hasOwnProperty;var Y=(e,o)=>{for(var t in o)w(e,t,{get:o[t],enumerable:!0})},j=(e,o,t,n)=>{if(o&&typeof o=="object"||typeof o=="function")for(let s of J(o))!V.call(e,s)&&s!==t&&w(e,s,{get:()=>o[s],enumerable:!(n=G(o,s))||n.enumerable});return e};var B=(e,o,t)=>(t=e!=null?F(Q(e)):{},j(o||!e||!e.__esModule?w(t,"default",{value:e,enumerable:!0}):t,e)),Z=e=>j(w({},"__esModule",{value:!0}),e);var at={};Y(at,{nextjsProxy:()=>M});module.exports=Z(at);var R=["chatgpt-user","claude-user","perplexity-user","gemini-user","gemini-deep-research","mistralai-user","grok-user"],L=["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"],U=["ahrefsbot","semrushbot","mj12bot","dotbot","dataforseobot"],q=["uptimerobot","lighthouse","chrome-lighthouse"],K=new Set([...R,...L]),tt=new Set(R),et=[...R,...L,...P,...v,...U,...q];function D(e){let o=e.toLowerCase();for(let t of et)if(o.includes(t)){let n;return tt.has(t)?n="ai-user":K.has(t)?n="ai-crawl":P.includes(t)?n="search":v.includes(t)?n="sns":U.includes(t)?n="seo":n="monitoring",{name:t,isAi:K.has(t),category:n}}return null}var ot=new Set(["utm_source","utm_medium","utm_campaign","utm_term","utm_content","fbclid","fb_action_ids","fb_action_types","fb_source","fb_ref","gclid","gclsrc","dclid","gbraid","wbraid","msclkid","hsa_cam","hsa_grp","hsa_mt","hsa_src","hsa_ad","hsa_acc","hsa_net","hsa_ver","hsa_la","hsa_ol","hsa_kw","_hsenc","_hsmi","_ga","_gl","_bhlid","mc_cid","mc_eid","oly_anon_id","oly_enc_id","ttclid","yclid","irclickid"]);function T(e){if(!e||(e.startsWith("?")&&(e=e.substring(1)),!e))return"";let o=[];for(let t of e.split("&")){if(!t)continue;let n=t.indexOf("="),s=n===-1?t:t.substring(0,n);ot.has(s.toLowerCase())||o.push(t)}return o.join("&")}function H(e){return encodeURIComponent(e).replace(/[!'()*]/g,o=>"%"+o.charCodeAt(0).toString(16).toUpperCase())}function nt(e){if(!e)return"/";let o,t,n=e.slice(0,8).toLowerCase();if(n.startsWith("http://")||n.startsWith("https://"))try{let r=new URL(e);o=r.pathname,t=r.search.startsWith("?")?r.search.substring(1):r.search}catch{o=e,t=""}else{let r=e.indexOf("?");r===-1?(o=e,t=""):(o=e.substring(0,r),t=e.substring(r+1))}o||(o="/");let s=o.split("/").map(r=>{if(!r)return r;try{return H(decodeURIComponent(r))}catch{return H(r)}}).join("/"),i=T(t);return i?`${s}?${i}`:s}async function st(e){if(typeof process<"u"&&process.versions?.node){let{createHash:n}=await import("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("")}async function S(e,o){let t=nt(e);return`${await st(t)}_${o}`}var W=/^\/(?:robots\.txt|llms\.txt|sitemap[^\/]*\.(?:xml|xsl))$/i,rt=/mobile|android|iphone|phone|tablet|webos|ipad/i;async function M(e,o){let{projectId:t,cloudfrontDomain:n,renderDomain:s,botLogEndpoint:i,aiRender:r=!0,ocr:m=!0,aiPathPrefixes:h=[]}=o,c=o.siteDomain.replace(/^https?:\/\//,"").replace(/\/+$/,""),C=n.replace(/\/$/,""),p=new URL(e.url),a=p.pathname;if(e.headers.get("x-prerender-host")){if(W.test(a)||a===`/${t}.txt`){let{NextResponse:d}=await import("next/server");return d.next()}return null}if(a===`/${t}.txt`)return new Response(t,{status:200,headers:{"Content-Type":"text/plain","Cache-Control":"public, max-age=3600"}});if(W.test(a)){try{let d=await fetch(`${s}/static${a}`,{headers:{"X-Signature":t,"X-Original-Host":c}});if(d.ok)return new Response(d.body,{status:200,headers:{"Content-Type":d.headers.get("Content-Type")||"text/plain","Cache-Control":"public, max-age=3600"}})}catch{}return null}let l=e.headers.get("user-agent")||"",f=D(l);if(!f)return null;let X=rt.test(l)?"mobile":"desktop",O=T(p.search),y=O?`${a}?${O}`:a,u=`https://${c}${y}`,b=it(e);try{if(f.isAi&&r){let x=await S(y,"ai"),A=await fetch(`${C}/v2/${c}/${x}.html`,{headers:{Accept:"text/html"}});if(A.ok){let g=await A.text();if(g&&g.length>100)return _(i,b,t,c,a,p.search,l,"hit_ai"),I(s,t,u,m,h),$(g,"HIT-AI",f.name)}let z=await S(y,"desktop"),N=await fetch(`${C}/v2/${c}/${z}.html`,{headers:{Accept:"text/html"}});if(N.ok){let g=await N.text();if(g&&g.length>100)return _(i,b,t,c,a,p.search,l,"hit_desktop_fallback"),I(s,t,u,m,h),$(g,"HIT-DESKTOP",f.name)}return _(i,b,t,c,a,p.search,l,"miss_ai"),I(s,t,u,m,h),k(s,t,u),null}let d=await S(y,X),E=await fetch(`${C}/v2/${c}/${d}.html`,{headers:{Accept:"text/html"}});if(E.ok){let x=await E.text();if(x&&x.length>100)return _(i,b,t,c,a,p.search,l,"hit"),k(s,t,u),$(x,"HIT",f.name)}}catch{}return _(i,b,t,c,a,p.search,l,"miss"),k(s,t,u),null}function $(e,o,t){return new Response(e,{headers:{"Content-Type":"text/html; charset=utf-8","X-Cache":o,"X-Bot":t}})}function it(e){let o=e.headers,t=o.get("x-forwarded-for")||"";return o.get("cf-connecting-ip")||o.get("x-real-ip")||t.split(",")[0].trim()||""}function _(e,o,t,n,s,i,r,m){let h={"Content-Type":"application/json"};o&&(h["X-Forwarded-For"]=o),fetch(e,{method:"POST",headers:h,body:JSON.stringify({project_id:t,url:`https://${n}${s}${i}`,domain:n,path:s,user_agent:r,phase:m})}).catch(()=>{})}function k(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 I(e,o,t,n,s){let i={items:[{url:t,project_id:o}],ocr:n};s.length>0&&(i.path_prefixes=s),fetch(`${e}/v2/cache/ai`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(i)}).catch(()=>{})}0&&(module.exports={nextjsProxy});
1
+ "use strict";var G=Object.create;var y=Object.defineProperty;var J=Object.getOwnPropertyDescriptor;var Q=Object.getOwnPropertyNames;var F=Object.getPrototypeOf,V=Object.prototype.hasOwnProperty;var Y=(e,o)=>{for(var t in o)y(e,t,{get:o[t],enumerable:!0})},j=(e,o,t,n)=>{if(o&&typeof o=="object"||typeof o=="function")for(let s of Q(o))!V.call(e,s)&&s!==t&&y(e,s,{get:()=>o[s],enumerable:!(n=J(o,s))||n.enumerable});return e};var B=(e,o,t)=>(t=e!=null?G(F(e)):{},j(o||!e||!e.__esModule?y(t,"default",{value:e,enumerable:!0}):t,e)),Z=e=>j(y({},"__esModule",{value:!0}),e);var at={};Y(at,{nextjsProxy:()=>M});module.exports=Z(at);var R=["chatgpt-user","claude-user","perplexity-user","gemini-user","gemini-deep-research","mistralai-user","grok-user"],L=["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"],U=["ahrefsbot","semrushbot","mj12bot","dotbot","dataforseobot"],q=["uptimerobot","lighthouse","chrome-lighthouse"],K=new Set([...R,...L]),tt=new Set(R),et=[...R,...L,...P,...v,...U,...q];function D(e){let o=e.toLowerCase();for(let t of et)if(o.includes(t)){let n;return tt.has(t)?n="ai-user":K.has(t)?n="ai-crawl":P.includes(t)?n="search":v.includes(t)?n="sns":U.includes(t)?n="seo":n="monitoring",{name:t,isAi:K.has(t),category:n}}return null}var ot=new Set(["utm_source","utm_medium","utm_campaign","utm_term","utm_content","fbclid","fb_action_ids","fb_action_types","fb_source","fb_ref","gclid","gclsrc","dclid","gbraid","wbraid","msclkid","hsa_cam","hsa_grp","hsa_mt","hsa_src","hsa_ad","hsa_acc","hsa_net","hsa_ver","hsa_la","hsa_ol","hsa_kw","_hsenc","_hsmi","_ga","_gl","_bhlid","mc_cid","mc_eid","oly_anon_id","oly_enc_id","ttclid","yclid","irclickid"]);function w(e){if(!e||(e.startsWith("?")&&(e=e.substring(1)),!e))return"";let o=[];for(let t of e.split("&")){if(!t)continue;let n=t.indexOf("="),s=n===-1?t:t.substring(0,n);ot.has(s.toLowerCase())||o.push(t)}return o.join("&")}function H(e){return encodeURIComponent(e).replace(/[!'()*]/g,o=>"%"+o.charCodeAt(0).toString(16).toUpperCase())}function nt(e){if(!e)return"/";let o,t,n=e.slice(0,8).toLowerCase();if(n.startsWith("http://")||n.startsWith("https://"))try{let r=new URL(e);o=r.pathname,t=r.search.startsWith("?")?r.search.substring(1):r.search}catch{o=e,t=""}else{let r=e.indexOf("?");r===-1?(o=e,t=""):(o=e.substring(0,r),t=e.substring(r+1))}o||(o="/");let s=o.split("/").map(r=>{if(!r)return r;try{return H(decodeURIComponent(r))}catch{return H(r)}}).join("/"),i=w(t);return i?`${s}?${i}`:s}async function st(e){if(typeof process<"u"&&process.versions?.node){let{createHash:n}=await import("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("")}async function T(e,o){let t=nt(e);return`${await st(t)}_${o}`}var W=/^\/(?:robots\.txt|llms\.txt|sitemap[^\/]*\.(?:xml|xsl))$/i,rt=/mobile|android|iphone|phone|tablet|webos|ipad/i;async function M(e,o){let{projectId:t,cloudfrontDomain:n,renderDomain:s,botLogEndpoint:i,aiRender:r=!0,ocr:u=!0,aiPathPrefixes:S=[]}=o,c=o.siteDomain.replace(/^https?:\/\//,"").replace(/\/+$/,""),C=n.replace(/\/$/,""),p=new URL(e.url),a=p.pathname;if(e.headers.get("x-prerender-host")){if(W.test(a)||a===`/${t}.txt`){let{NextResponse:d}=await import("next/server");return d.next()}return null}if(a===`/${t}.txt`)return new Response(t,{status:200,headers:{"Content-Type":"text/plain","Cache-Control":"public, max-age=3600"}});if(W.test(a)){try{let d=await fetch(`${s}/static${a}`,{headers:{"X-Signature":t,"X-Original-Host":c}});if(d.ok)return new Response(d.body,{status:200,headers:{"Content-Type":d.headers.get("Content-Type")||"text/plain","Cache-Control":"public, max-age=3600"}})}catch{}return null}let l=e.headers.get("user-agent")||"",m=D(l);if(!m)return null;let z=rt.test(l)?"mobile":"desktop",O=w(p.search),_=O?`${a}?${O}`:a,h=`https://${c}${_}`,f=it(e);try{if(m.isAi&&r){let b=await T(_,"ai"),A=await fetch(`${C}/v2/${c}/${b}.html`,{headers:{Accept:"text/html"}});if(A.ok){let g=await A.text();if(g&&g.length>100)return x(i,f,t,c,a,p.search,l,"hit_ai"),I(s,t,h,u,S),$(g,"HIT-AI",m.name)}let X=await T(_,"desktop"),N=await fetch(`${C}/v2/${c}/${X}.html`,{headers:{Accept:"text/html"}});if(N.ok){let g=await N.text();if(g&&g.length>100)return x(i,f,t,c,a,p.search,l,"hit_desktop_fallback"),I(s,t,h,u,S),$(g,"HIT-DESKTOP",m.name)}return x(i,f,t,c,a,p.search,l,"miss_ai"),I(s,t,h,u,S),k(s,t,h),null}let d=await T(_,z),E=await fetch(`${C}/v2/${c}/${d}.html`,{headers:{Accept:"text/html"}});if(E.ok){let b=await E.text();if(b&&b.length>100)return x(i,f,t,c,a,p.search,l,"hit"),k(s,t,h),$(b,"HIT",m.name)}}catch{}return x(i,f,t,c,a,p.search,l,"miss"),k(s,t,h),null}function $(e,o,t){return new Response(e,{headers:{"Content-Type":"text/html; charset=utf-8","X-Cache":o,"X-Bot":t}})}function it(e){let o=e.headers,t=o.get("x-forwarded-for")||"";return o.get("cf-connecting-ip")||o.get("x-real-ip")||t.split(",")[0].trim()||""}function x(e,o,t,n,s,i,r,u){fetch(e,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({project_id:t,url:`https://${n}${s}${i}`,domain:n,path:s,user_agent:r,phase:u,client_ip:o})}).catch(()=>{})}function k(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 I(e,o,t,n,s){let i={items:[{url:t,project_id:o}],ocr:n};s.length>0&&(i.path_prefixes=s),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-3FWDO7FS.js";import"./chunk-BVZHYMX6.js";export{o as nextjsProxy};
1
+ import{a as o}from"./chunk-NYRQ66HM.js";import"./chunk-BVZHYMX6.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.8",
3
+ "version": "1.0.9",
4
4
  "description": "SearchOS 봇 프록시 — Next.js, Cloudflare Worker용 봇 감지 + 캐시 프록시",
5
5
  "type": "module",
6
6
  "exports": {
@@ -1 +0,0 @@
1
- import{b as I,c as S,d as w}from"./chunk-BVZHYMX6.js";var A=/^\/(?:robots\.txt|llms\.txt|sitemap[^\/]*\.(?:xml|xsl))$/i,L=/mobile|android|iphone|phone|tablet|webos|ipad/i;async function B(n,e){let{projectId:t,cloudfrontDomain:l,renderDomain:r,botLogEndpoint:o,aiRender:b=!0,ocr:m=!0,aiPathPrefixes:d=[]}=e,i=e.siteDomain.replace(/^https?:\/\//,"").replace(/\/+$/,""),R=l.replace(/\/$/,""),a=new URL(n.url),s=a.pathname;if(n.headers.get("x-prerender-host")){if(A.test(s)||s===`/${t}.txt`){let{NextResponse:h}=await import("next/server");return h.next()}return null}if(s===`/${t}.txt`)return new Response(t,{status:200,headers:{"Content-Type":"text/plain","Cache-Control":"public, max-age=3600"}});if(A.test(s)){try{let h=await fetch(`${r}/static${s}`,{headers:{"X-Signature":t,"X-Original-Host":i}});if(h.ok)return new Response(h.body,{status:200,headers:{"Content-Type":h.headers.get("Content-Type")||"text/plain","Cache-Control":"public, max-age=3600"}})}catch{}return null}let c=n.headers.get("user-agent")||"",u=I(c);if(!u)return null;let D=L.test(c)?"mobile":"desktop",j=S(a.search),$=j?`${s}?${j}`:s,g=`https://${i}${$}`,f=v(n);try{if(u.isAi&&b){let x=await w($,"ai"),O=await fetch(`${R}/v2/${i}/${x}.html`,{headers:{Accept:"text/html"}});if(O.ok){let p=await O.text();if(p&&p.length>100)return y(o,f,t,i,s,a.search,c,"hit_ai"),_(r,t,g,m,d),T(p,"HIT-AI",u.name)}let E=await w($,"desktop"),P=await fetch(`${R}/v2/${i}/${E}.html`,{headers:{Accept:"text/html"}});if(P.ok){let p=await P.text();if(p&&p.length>100)return y(o,f,t,i,s,a.search,c,"hit_desktop_fallback"),_(r,t,g,m,d),T(p,"HIT-DESKTOP",u.name)}return y(o,f,t,i,s,a.search,c,"miss_ai"),_(r,t,g,m,d),C(r,t,g),null}let h=await w($,D),k=await fetch(`${R}/v2/${i}/${h}.html`,{headers:{Accept:"text/html"}});if(k.ok){let x=await k.text();if(x&&x.length>100)return y(o,f,t,i,s,a.search,c,"hit"),C(r,t,g),T(x,"HIT",u.name)}}catch{}return y(o,f,t,i,s,a.search,c,"miss"),C(r,t,g),null}function T(n,e,t){return new Response(n,{headers:{"Content-Type":"text/html; charset=utf-8","X-Cache":e,"X-Bot":t}})}function v(n){let e=n.headers,t=e.get("x-forwarded-for")||"";return e.get("cf-connecting-ip")||e.get("x-real-ip")||t.split(",")[0].trim()||""}function y(n,e,t,l,r,o,b,m){let d={"Content-Type":"application/json"};e&&(d["X-Forwarded-For"]=e),fetch(n,{method:"POST",headers:d,body:JSON.stringify({project_id:t,url:`https://${l}${r}${o}`,domain:l,path:r,user_agent:b,phase:m})}).catch(()=>{})}function C(n,e,t){fetch(`${n}/v2/cache`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({items:[{url:t,project_id:e}]})}).catch(()=>{})}function _(n,e,t,l,r){let o={items:[{url:t,project_id:e}],ocr:l};r.length>0&&(o.path_prefixes=r),fetch(`${n}/v2/cache/ai`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(o)}).catch(()=>{})}export{B as a};