sinzmise-cetastories-en 2.0.0-1732438479324 → 2.0.0-1732441112276

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/config.yaml CHANGED
@@ -1,5 +1,37 @@
1
1
  name: CetaHouseEnCache
2
2
  catch_rules:
3
+ - rule: _ #ClientWorker语法糖,匹配当前域,返回一个域名带端口
4
+ transform_rules: #转换规则,最上面的优先最高
5
+ - search: \#.* #在发送请求时匹配#后内容并移除
6
+ searchin: url
7
+ replace: ''
8
+ - search: \?.* #在发送请求时匹配?后内容并移除,仅限静态请求
9
+ replace: ''
10
+ - search: ([^\/.]+)\/index(|\.html)$ #url优化
11
+ action: redirect
12
+ redirect:
13
+ to: $1/
14
+ - search: ([^\/.]+)\/$
15
+ replace: $1/index.html
16
+ - search: _
17
+ replace:
18
+ - _ #保留原始请求
19
+ - en.vercel.blog.sinzmise.top #Vercel托管
20
+ - jsd.cdn.storisinz.site/npm/sinzmise-cetastories-en #NPM托管
21
+ - jsd.cdn.storisinz.site/gh/SinzMise/blog@en #gh托管
22
+
23
+ - search: \.html$
24
+ header:
25
+ Content-Type: text/html;charset=UTF-8 #修复标头
26
+
27
+ - search: _
28
+ action: fetch
29
+ fetch:
30
+ status: 200
31
+ engine: classic
32
+ preflight: false
33
+ timeout: 5000
34
+
3
35
  - rule: ^https\:\/\/((cdn|fastly|gcore|test1|quantil)\.jsdelivr\.net\/npm|unpkg\.com)
4
36
  transform_rules:
5
37
  - search: _
@@ -24,4 +56,3 @@ catch_rules:
24
56
  - _
25
57
  - https://jsd.cdn.storisinz.site/gh
26
58
  - https://code.webcache.cn/gh
27
-
package/cw.js CHANGED
@@ -1 +1 @@
1
- importScripts("https://jsd.cdn.storisinz.site/npm/clientworker/dist/cw.js");const CACHE_NAME="CetaHouseEnCache";let cachelist=[];self.addEventListener("install",(async function(e){self.skipWaiting(),e.waitUntil(caches.open(CACHE_NAME).then((function(e){return console.log("Opened cache"),e.addAll(cachelist)})))})),self.addEventListener("fetch",(async e=>{try{e.respondWith(handle(e.request))}catch(t){e.respondWith(handleerr(e.request,t))}}));const handleerr=async(e,t)=>new Response(`<h1>CDN splitter encountered a fatal error</h1>\n <b>${t}</b>`,{headers:{"content-type":"text/html; charset=utf-8"}}),lfetch=async(e,t)=>{let s=new AbortController;const n=async e=>new Response(await e.arrayBuffer(),{status:e.status,headers:e.headers});return Promise.any||(Promise.any=function(e){return new Promise(((t,s)=>{let n=(e=Array.isArray(e)?e:[]).length,r=[];if(0===n)return s(new AggregateError("All promises were rejected"));e.forEach((e=>{e.then((e=>{t(e)}),(e=>{n--,r.push(e),0===n&&s(new AggregateError(r))}))}))}))}),Promise.any(e.map((e=>new Promise(((t,r)=>{fetch(e,{signal:s.signal}).then(n).then((e=>{200==e.status?(s.abort(),t(e)):r(e)}))})))))},fullpath=e=>((e=e.split("?")[0].split("#")[0]).match(/\/$/)&&(e+="index"),e.match(/\.[a-zA-Z]+$/)||(e+=".html"),e),generate_blog_urls=(e,t,s)=>{const n=[`https://jsd.cdn.storisinz.site/npm/${e}@${t}`,"https://en.vercel.blog.sinzmise.top","https://en.netlify.blog.sinzmise.top","https://jsd.cdn.storisinz.site/gh/SinzMise/blog@en",`https://registry.npmmirror.com/${e}/${t}/files`];for(var r in n)n[r]+=s;return n},mirror=["https://registry.npmmirror.com/sinzmise-cetastories-en/latest","https://registry.npmjs.org/sinzmise-cetastories-en/latest","https://mirrors.cloud.tencent.com/npm/sinzmise-cetastories-en/latest","https://registry.npmmirror.com/sinzmise-cetastories-en/latest"],get_newest_version=async e=>lfetch(e,e[0]).then((e=>e.json())).then(res.version);self.db={read:(e,t)=>(t||(t={type:"text"}),new Promise(((t,s)=>{caches.open(CACHE_NAME).then((s=>{s.match(new Request(`https://LOCALCACHE/${encodeURIComponent(e)}`)).then((function(e){e||t(null),e.text().then((e=>t(e)))})).catch((()=>{t(null)}))}))}))),write:(e,t)=>new Promise(((s,n)=>{caches.open(CACHE_NAME).then((function(n){n.put(new Request(`https://LOCALCACHE/${encodeURIComponent(e)}`),new Response(t)),s()})).catch((()=>{n()}))}))};const set_newest_version=async e=>lfetch(e,e[0]).then((e=>e.json())).then((async e=>{await db.write("blog_version",e.version)}));function getFileType(e){return suffix=e.split(".")[e.split(".").length-1],"html"==suffix||"htm"==suffix?"text/html":"js"==suffix?"text/javascript":"css"==suffix?"text/css":"jpg"==suffix||"jpeg"==suffix?"image/jpeg":"ico"==suffix?"image/x-icon":"png"==suffix?"image/png":"text/plain"}setInterval((async()=>{await set_newest_version(mirror)}),6e4),setTimeout((async()=>{await set_newest_version(mirror)}),5e3);const handle=async e=>{const t=e.url,s=new URL(t),n=s.pathname,r=s.hostname;return lxs=[],"en.blog.sinzmise.top"===r?lfetch(generate_blog_urls("sinzmise-cetastories-en",await db.read("blog_version")||"latest",fullpath(n))).then((e=>e.arrayBuffer())).then((e=>new Response(e,{headers:{"Content-Type":`${getFileType(fullpath(n).split("/")[fullpath(n).split("/").length-1].split("\\")[fullpath(n).split("/")[fullpath(n).split("/").length-1].split("\\").length-1])};charset=utf-8`}}))):fetch(e)};
1
+ importScripts("https://jsd.cdn.storisinz.site/npm/clientworker/dist/cw.js");