@searchos/bot-proxy 1.0.4 → 1.0.6
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-MKJTG6WJ.js +1 -0
- package/dist/chunk-N5GEUXIH.js +1 -0
- package/dist/cloudflare.cjs +1 -1
- package/dist/cloudflare.d.cts +1 -8
- package/dist/cloudflare.d.ts +1 -8
- package/dist/cloudflare.js +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.js +1 -1
- package/dist/nextjs.cjs +1 -1
- package/dist/nextjs.d.cts +1 -1
- package/dist/nextjs.d.ts +1 -1
- package/dist/nextjs.js +1 -1
- package/package.json +1 -1
- package/dist/chunk-3GWBNF6R.js +0 -1
- package/dist/chunk-HLBLRAGQ.js +0 -1
|
@@ -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,renderDomain: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};
|
|
@@ -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,renderDomain: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};
|
package/dist/cloudflare.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var
|
|
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,renderDomain: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});
|
package/dist/cloudflare.d.cts
CHANGED
|
@@ -2,7 +2,7 @@ interface CloudflareProxyOptions {
|
|
|
2
2
|
projectId: string;
|
|
3
3
|
/** 사이트 도메인 (예: "example.com") */
|
|
4
4
|
siteDomain: string;
|
|
5
|
-
|
|
5
|
+
renderDomain: string;
|
|
6
6
|
botLogEndpoint: string;
|
|
7
7
|
/** AI 렌더 활성화 (기본: true). true면 AI 봇에게 ai 캐시를 우선 서빙 */
|
|
8
8
|
aiRender?: boolean;
|
|
@@ -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;
|
package/dist/cloudflare.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ interface CloudflareProxyOptions {
|
|
|
2
2
|
projectId: string;
|
|
3
3
|
/** 사이트 도메인 (예: "example.com") */
|
|
4
4
|
siteDomain: string;
|
|
5
|
-
|
|
5
|
+
renderDomain: string;
|
|
6
6
|
botLogEndpoint: string;
|
|
7
7
|
/** AI 렌더 활성화 (기본: true). true면 AI 봇에게 ai 캐시를 우선 서빙 */
|
|
8
8
|
aiRender?: boolean;
|
|
@@ -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;
|
package/dist/cloudflare.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as o}from"./chunk-
|
|
1
|
+
import{a as o}from"./chunk-MKJTG6WJ.js";import"./chunk-62QI7OUQ.js";export{o as cloudflareProxy};
|
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var F=Object.create;var
|
|
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,r)=>{if(n&&typeof n=="object"||typeof n=="function")for(let s of Y(n))!q.call(e,s)&&s!==t&&k(e,s,{get:()=>n[s],enumerable:!(r=Q(n,s))||r.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"],st=["uptimerobot","lighthouse","chrome-lighthouse"],v=new Set([...S,...U]),P=new Set(S),rt=[...S,...U,...D,...X,...J,...st];function A(e){let n=e.toLowerCase();for(let t of rt)if(n.includes(t)){let r;return P.has(t)?r="ai-user":v.has(t)?r="ai-crawl":D.includes(t)?r="search":X.includes(t)?r="sns":J.includes(t)?r="seo":r="monitoring",{name:t,isAi:v.has(t),category:r}}return null}async function ot(e){if(typeof process<"u"&&process.versions?.node){let{createHash:r}=require("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("")}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:r,renderDomain:s,botLogEndpoint:a,aiRender:i=!0,ocr:l=!0,aiPathPrefixes:b=[]}=n,p=n.siteDomain.replace(/^https?:\/\//,"").replace(/\/+$/,""),w=r.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(`${s}${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(`${s}/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(s,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(s,t,_,l,b),j(x,"HIT-DESKTOP",g.name)}return $(a,t,p,o,C.search,u,"miss_ai"),H(s,t,_,l,b),I(s,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(s,t,_),j(m,"HIT",g.name)}}catch{}return $(a,t,p,o,C.search,u,"miss"),I(s,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,r,s,a,i){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: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,r,s){let a={items:[{url:t,project_id:n}],ocr:r};s.length>0&&(a.path_prefixes=s),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,r){let{projectId:s,siteDomain:a,renderDomain:i,botLogEndpoint:l,aiRender:b=!0,ocr:p=!0,aiPathPrefixes:w=[]}=r,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===`/${s}.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":s,"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,s,u,o,g,"hit_ai"),await L(i,s,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,s,u,o,g,"hit_desktop_fallback"),await L(i,s,c,p,w)}),N(V,"HIT-DESKTOP",h.name)):(m(async()=>{console.log(`[BOT] ${h.name} | ${T} | miss_ai | ${o}`),await R(l,s,u,o,g,"miss_ai"),await Promise.all([L(i,s,c,p,w),B(i,s,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,s,u,o,g,"hit"),await B(i,s,c)}),N(E,"HIT",h.name)):(m(async()=>{console.log(`[BOT] ${h.name} | ${T} | miss | ${o}`),await R(l,s,u,o,g,"miss"),await B(i,s,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,r,s,a){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: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 r=0;for(let s of t){let{url:a,html:i,variant:l="",device:b="desktop"}=s||{};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}),r++}return f({success:!0,updated:r})}catch(t){return f({success:!1,error:t.message},500)}}async function dt(e,n){try{let{urls:t=[],variant:r=""}=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 s=r.startsWith("v2_")?r.substring(3):"desktop",a=0;for(let i of t){let l=new URL(i).pathname||"/",b=await y(l,s);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:r=""}=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 s=r.startsWith("v2_")?r.substring(3):"desktop",a=new URL(t).pathname||"/",i=await y(a,s),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,r,s){let a={items:[{url:t,project_id:n}],ocr:r};s.length>0&&(a.path_prefixes=s),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-
|
|
1
|
+
import{a as o}from"./chunk-MKJTG6WJ.js";import{a as r}from"./chunk-N5GEUXIH.js";import"./chunk-62QI7OUQ.js";export{o as cloudflareProxy,r as nextjsProxy};
|
package/dist/nextjs.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
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,
|
|
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,renderDomain: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 l=e.headers.get("user-agent")||"",g=P(l);if(!g)return null;let v=Z.test(l)?"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 p=await R.text();if(p&&p.length>100)return m(i,t,a,s,d.search,l,"hit_ai"),$(r,t,h,y,T),O(p,"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 p=await E.text();if(p&&p.length>100)return m(i,t,a,s,d.search,l,"hit_desktop_fallback"),$(r,t,h,y,T),O(p,"HIT-DESKTOP",g.name)}return m(i,t,a,s,d.search,l,"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,l,"hit"),S(r,t,h),O(u,"HIT",g.name)}}catch{}return m(i,t,a,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 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.d.cts
CHANGED
package/dist/nextjs.d.ts
CHANGED
package/dist/nextjs.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as o}from"./chunk-
|
|
1
|
+
import{a as o}from"./chunk-N5GEUXIH.js";import"./chunk-62QI7OUQ.js";export{o as nextjsProxy};
|
package/package.json
CHANGED
package/dist/chunk-3GWBNF6R.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
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};
|
package/dist/chunk-HLBLRAGQ.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{a as E,b as R,c as w}from"./chunk-62QI7OUQ.js";var S=/^\/(?:robots\.txt|llms\.txt|sitemap[^\/]*\.(?:xml|xsl))$/i,I=/mobile|android|iphone|phone|tablet|webos|ipad/i;async function V(s,n,r,p){let{projectId:t,siteDomain:u,prerenderDomain:i,botLogEndpoint:h,aiRender:k=!0,ocr:$=!0,aiPathPrefixes:C=[]}=p,e=new URL(s.url).pathname,c=u.replace(/^https?:\/\//,"").replace(/\/+$/,"");if(s.headers.get("x-prerender-host"))return null;if(e===`/${t}.txt`)try{let o=await fetch(`${i}${e}`,{redirect:"manual"});return new Response(o.body,{status:o.status,headers:{"Content-Type":"text/plain","Cache-Control":"public, max-age=3600"}})}catch{return new Response("",{status:404})}if(S.test(e))try{let o=await fetch(`${i}/static${e}`,{redirect:"manual",headers:{"X-Signature":t,"X-Original-Host":c}});return new Response(o.body,{status:o.status,headers:{"Content-Type":o.headers.get("Content-Type")||"text/plain","Cache-Control":"public, max-age=3600"}})}catch{return null}let l=s.headers.get("user-agent")||"",a=R(l);if(!a||!n.V2_CACHE)return null;let P=I.test(l)?"mobile":"desktop",d=`https://${c}${e}`,g=E.has(a.name)?"ai-user":a.isAi?"ai-crawl":"standard",m=o=>r.waitUntil(o().catch(f=>console.error("[bot-proxy]",f)));try{if(a.isAi&&k){let A=await w(e,"ai"),x=await n.V2_CACHE.get(A);if(x)return m(async()=>{console.log(`[BOT] ${a.name} | ${g} | hit_ai | ${e}`),await y(h,t,c,e,l,"hit_ai"),await _(i,t,d,$,C)}),b(x,"HIT-AI",a.name);let H=await w(e,"desktop"),O=await n.V2_CACHE.get(H);return O?(m(async()=>{console.log(`[BOT] ${a.name} | ${g} | hit_desktop_fallback | ${e}`),await y(h,t,c,e,l,"hit_desktop_fallback"),await _(i,t,d,$,C)}),b(O,"HIT-DESKTOP",a.name)):(m(async()=>{console.log(`[BOT] ${a.name} | ${g} | miss_ai | ${e}`),await y(h,t,c,e,l,"miss_ai"),await Promise.all([_(i,t,d,$,C),T(i,t,d)])}),null)}let o=await w(e,P),f=await n.V2_CACHE.get(o);return f?(m(async()=>{console.log(`[BOT] ${a.name} | ${g} | hit | ${e}`),await y(h,t,c,e,l,"hit"),await T(i,t,d)}),b(f,"HIT",a.name)):(m(async()=>{console.log(`[BOT] ${a.name} | ${g} | miss | ${e}`),await y(h,t,c,e,l,"miss"),await T(i,t,d)}),null)}catch(o){return console.error("[bot-proxy]",o),null}}function b(s,n,r){return new Response(s,{headers:{"Content-Type":"text/html; charset=utf-8","X-Cache":n,"X-Bot":r}})}async function y(s,n,r,p,t,u){await fetch(s,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({project_id:n,url:`https://${r}${p}`,domain:r,path:p,user_agent:t,phase:u})})}async function T(s,n,r){await fetch(`${s}/v2/cache/kv`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({items:[{url:r,project_id:n}]})})}async function _(s,n,r,p,t){let u={items:[{url:r,project_id:n}],ocr:p};t.length>0&&(u.path_prefixes=t),await fetch(`${s}/v2/cache/kv/ai`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(u)})}export{V as a};
|