@searchos/bot-proxy 1.0.7 → 1.0.8
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.
- package/dist/chunk-3FWDO7FS.js +1 -0
- package/dist/index.cjs +1 -1
- package/dist/index.js +1 -1
- package/dist/nextjs.cjs +1 -1
- package/dist/nextjs.js +1 -1
- package/package.json +1 -1
- package/dist/chunk-RMNMMVLT.js +0 -1
|
@@ -0,0 +1 @@
|
|
|
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};
|
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})},D=(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 W=(e,n,t)=>(t=e!=null?tt(st(e)):{},D(n||!e||!e.__esModule?I(t,"default",{value:e,enumerable:!0}):t,e)),at=e=>D(I({},"__esModule",{value:!0}),e);var bt={};ot(bt,{cloudflareProxy:()=>Z,nextjsProxy:()=>Y});module.exports=at(bt);var j=["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"],M=["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"],X=new Set([...j,...J]),H=new Set(j),ct=[...j,...J,...M,...Q,...z,...it];function P(e){let n=e.toLowerCase();for(let t of ct)if(n.includes(t)){let r;return H.has(t)?r="ai-user":X.has(t)?r="ai-crawl":M.includes(t)?r="search":Q.includes(t)?r="sns":z.includes(t)?r="seo":r="monitoring",{name:t,isAi:X.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 F=/^\/(?:robots\.txt|llms\.txt|sitemap[^\/]*\.(?:xml|xsl))$/i,dt=/mobile|android|iphone|phone|tablet|webos|ipad/i;async function Y(e,n){let{projectId:t,cloudfrontDomain:r,renderDomain:s,botLogEndpoint:i,aiRender:o=!0,ocr:d=!0,aiPathPrefixes:T=[]}=n,l=n.siteDomain.replace(/^https?:\/\//,"").replace(/\/+$/,""),w=r.replace(/\/$/,""),b=new URL(e.url),a=b.pathname;if(e.headers.get("x-prerender-host")){if(F.test(a)||a===`/${t}.txt`){let{NextResponse:c}=await import("next/server");return c.next()}return null}if(a===`/${t}.txt`)try{let c=await fetch(`${s}${a}`,{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(F.test(a))try{let c=await fetch(`${s}/static${a}`,{headers:{"X-Signature":t,"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 p=e.headers.get("user-agent")||"",g=P(p);if(!g)return null;let h=dt.test(p)?"mobile":"desktop",S=k(b.search),$=S?`${a}?${S}`:a,f=`https://${l}${$}`;try{if(g.isAi&&o){let y=await _($,"ai"),u=await fetch(`${w}/v2/${l}/${y}.html`,{headers:{Accept:"text/html"}});if(u.ok){let x=await u.text();if(x&&x.length>100)return R(i,t,l,a,b.search,p,"hit_ai"),K(s,t,f,d,T),N(x,"HIT-AI",g.name)}let E=await _($,"desktop"),O=await fetch(`${w}/v2/${l}/${E}.html`,{headers:{Accept:"text/html"}});if(O.ok){let x=await O.text();if(x&&x.length>100)return R(i,t,l,a,b.search,p,"hit_desktop_fallback"),K(s,t,f,d,T),N(x,"HIT-DESKTOP",g.name)}return R(i,t,l,a,b.search,p,"miss_ai"),K(s,t,f,d,T),B(s,t,f),null}let c=await _($,h),C=await fetch(`${w}/v2/${l}/${c}.html`,{headers:{Accept:"text/html"}});if(C.ok){let y=await C.text();if(y&&y.length>100)return R(i,t,l,a,b.search,p,"hit"),B(s,t,f),N(y,"HIT",g.name)}}catch{}return R(i,t,l,a,b.search,p,"miss"),B(s,t,f),null}function N(e,n,t){return new Response(e,{headers:{"Content-Type":"text/html; charset=utf-8","X-Cache":n,"X-Bot":t}})}function R(e,n,t,r,s,i,o){fetch(e,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({project_id:n,url:`https://${t}${r}${s}`,domain:t,path:r,user_agent:i,phase:o})}).catch(()=>{})}function B(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 K(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,gt=/mobile|android|iphone|phone|tablet|webos|ipad/i,mt=604800;async function Z(e,n,t,r){let{projectId:s,siteDomain:i,renderDomain:o,botLogEndpoint:d,aiRender:T=!0,ocr:l=!0,aiPathPrefixes:w=[]}=r,b=new URL(e.url),a=b.pathname,p=i.replace(/^https?:\/\//,"").replace(/\/+$/,"");if(e.method==="POST"){if(a==="/__update-edge-cache")return ft(e,n);if(a==="/__purge-edge-cache")return yt(e,n);if(a==="/__read-edge-cache")return _t(e,n)}if(e.headers.get("x-prerender-host"))return null;if(a===`/${s}.txt`)try{let u=await fetch(`${o}${a}`,{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(ht.test(a))try{let u=await fetch(`${o}/static${a}`,{redirect:"manual",headers:{"X-Signature":s,"X-Original-Host":p}});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=e.headers.get("user-agent")||"",h=P(g);if(!h||!n.V2_CACHE)return null;let S=gt.test(g)?"mobile":"desktop",$=k(b.search),f=$?`${a}?${$}`:a,c=`https://${p}${f}`,C=H.has(h.name)?"ai-user":h.isAi?"ai-crawl":"standard",y=u=>t.waitUntil(u().catch(E=>console.error("[bot-proxy]",E)));try{if(h.isAi&&T){let O=await _(f,"ai"),x=await n.V2_CACHE.get(O);if(x)return y(async()=>{console.log(`[BOT] ${h.name} | ${C} | hit_ai | ${a}`),await A(d,s,p,a,g,"hit_ai"),await v(o,s,c,l,w)}),L(x,"HIT-AI",h.name);let q=await _(f,"desktop"),U=await n.V2_CACHE.get(q);return U?(y(async()=>{console.log(`[BOT] ${h.name} | ${C} | hit_desktop_fallback | ${a}`),await A(d,s,p,a,g,"hit_desktop_fallback"),await v(o,s,c,l,w)}),L(U,"HIT-DESKTOP",h.name)):(y(async()=>{console.log(`[BOT] ${h.name} | ${C} | miss_ai | ${a}`),await A(d,s,p,a,g,"miss_ai"),await Promise.all([v(o,s,c,l,w),V(o,s,c)])}),null)}let u=await _(f,S),E=await n.V2_CACHE.get(u);return E?(y(async()=>{console.log(`[BOT] ${h.name} | ${C} | hit | ${a}`),await A(d,s,p,a,g,"hit"),await V(o,s,c)}),L(E,"HIT",h.name)):(y(async()=>{console.log(`[BOT] ${h.name} | ${C} | miss | ${a}`),await A(d,s,p,a,g,"miss"),await V(o,s,c)}),null)}catch(u){return console.error("[bot-proxy]",u),null}}function L(e,n,t){return new Response(e,{headers:{"Content-Type":"text/html; charset=utf-8","X-Cache":n,"X-Bot":t}})}async function A(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 ft(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:d="",device:T="desktop"}=s||{};if(!i||!o)continue;let l=d.startsWith("v2_")?d.substring(3):T,w=await _(i,l);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 yt(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 d=await _(o,s);await n.V2_CACHE.delete(d),i++}return m({success:!0,deleted:i})}catch(t){return m({success:!1,error:t.message},500)}}async function _t(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 v(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"],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});
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as o}from"./chunk-JXQQEZ5V.js";import{a as r}from"./chunk-
|
|
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};
|
package/dist/nextjs.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var
|
|
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});
|
package/dist/nextjs.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as o}from"./chunk-
|
|
1
|
+
import{a as o}from"./chunk-3FWDO7FS.js";import"./chunk-BVZHYMX6.js";export{o as nextjsProxy};
|
package/package.json
CHANGED
package/dist/chunk-RMNMMVLT.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{b as k,c as I,d as x}from"./chunk-BVZHYMX6.js";var S=/^\/(?:robots\.txt|llms\.txt|sitemap[^\/]*\.(?:xml|xsl))$/i,E=/mobile|android|iphone|phone|tablet|webos|ipad/i;async function K(s,r){let{projectId:t,cloudfrontDomain:l,renderDomain:e,botLogEndpoint:a,aiRender:y=!0,ocr:$=!0,aiPathPrefixes:b=[]}=r,o=r.siteDomain.replace(/^https?:\/\//,"").replace(/\/+$/,""),w=l.replace(/\/$/,""),c=new URL(s.url),n=c.pathname;if(s.headers.get("x-prerender-host")){if(S.test(n)||n===`/${t}.txt`){let{NextResponse:i}=await import("next/server");return i.next()}return null}if(n===`/${t}.txt`)try{let i=await fetch(`${e}${n}`,{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(S.test(n))try{let i=await fetch(`${e}/static${n}`,{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 h=s.headers.get("user-agent")||"",d=k(h);if(!d)return null;let A=E.test(h)?"mobile":"desktop",_=I(c.search),f=_?`${n}?${_}`:n,u=`https://${o}${f}`;try{if(d.isAi&&y){let m=await x(f,"ai"),O=await fetch(`${w}/v2/${o}/${m}.html`,{headers:{Accept:"text/html"}});if(O.ok){let p=await O.text();if(p&&p.length>100)return g(a,t,o,n,c.search,h,"hit_ai"),C(e,t,u,$,b),T(p,"HIT-AI",d.name)}let D=await x(f,"desktop"),P=await fetch(`${w}/v2/${o}/${D}.html`,{headers:{Accept:"text/html"}});if(P.ok){let p=await P.text();if(p&&p.length>100)return g(a,t,o,n,c.search,h,"hit_desktop_fallback"),C(e,t,u,$,b),T(p,"HIT-DESKTOP",d.name)}return g(a,t,o,n,c.search,h,"miss_ai"),C(e,t,u,$,b),R(e,t,u),null}let i=await x(f,A),j=await fetch(`${w}/v2/${o}/${i}.html`,{headers:{Accept:"text/html"}});if(j.ok){let m=await j.text();if(m&&m.length>100)return g(a,t,o,n,c.search,h,"hit"),R(e,t,u),T(m,"HIT",d.name)}}catch{}return g(a,t,o,n,c.search,h,"miss"),R(e,t,u),null}function T(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,l,e,a,y){fetch(s,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({project_id:r,url:`https://${t}${l}${e}`,domain:t,path:l,user_agent:a,phase:y})}).catch(()=>{})}function R(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 C(s,r,t,l,e){let a={items:[{url:t,project_id:r}],ocr:l};e.length>0&&(a.path_prefixes=e),fetch(`${s}/v2/cache/ai`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(a)}).catch(()=>{})}export{K as a};
|