q78kgblog 0.0.0-1714651155871 → 0.0.0-1714654046710
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/404.html +4 -4
- package/about/index.html +5 -5
- package/archives/2022/06/index.html +4 -4
- package/archives/2022/index.html +4 -4
- package/archives/2023/02/index.html +4 -4
- package/archives/2023/04/index.html +4 -4
- package/archives/2023/05/index.html +4 -4
- package/archives/2023/08/index.html +4 -4
- package/archives/2023/09/index.html +4 -4
- package/archives/2023/index.html +4 -4
- package/archives/2024/01/index.html +4 -4
- package/archives/2024/02/index.html +4 -4
- package/archives/2024/index.html +4 -4
- package/archives/index.html +4 -4
- package/atom.xml +11 -11
- package/baidusitemap.xml +10 -10
- package/bangumis/index.html +4 -4
- package/bigpie/index.html +3 -3
- package/categories/Hello-World/index.html +4 -4
- package/categories/Hexo/index.html +4 -4
- package/categories/index.html +3 -3
- package/categories//345/271/264/347/273/210/346/200/273/347/273/223/index.html +4 -4
- package/categories//346/201/260/351/245/255/index.html +4 -4
- package/categories//347/264/240/346/235/220/index.html +4 -4
- package/categories//351/227/262/350/201/212/346/235/202/350/260/210/index.html +4 -4
- package/content.json +1 -1
- package/fcircle/index.html +3 -3
- package/fontawesome/index.html +3 -3
- package/index.html +14 -14
- package/links/index.html +3 -3
- package/othersite/index.html +3 -3
- package/package.json +1 -1
- package/posts/164ef646/index.html +6 -6
- package/posts/228c2ef8/index.html +6 -6
- package/posts/4a17b156/index.html +6 -6
- package/posts/6f3c565b/index.html +6 -6
- package/posts/7da7c3f6/index.html +6 -6
- package/posts/a9a6c1fb/index.html +6 -6
- package/posts/c262e439/index.html +6 -6
- package/posts/c81531cf/index.html +6 -6
- package/posts/da2093a1/index.html +6 -6
- package/posts/e54f7476/index.html +6 -6
- package/random.html +5 -5
- package/sitemap.txt +5 -5
- package/sitemap.xml +16 -16
- package/sw.js +172 -196
- package/tags/AI/index.html +5 -5
- package/tags/Butterfly/index.html +5 -5
- package/tags/Cloudflare/index.html +5 -5
- package/tags/DiffSinger/index.html +5 -5
- package/tags/Hexo/index.html +5 -5
- package/tags/Next/index.html +5 -5
- package/tags/RAID/index.html +5 -5
- package/tags/VPS/index.html +5 -5
- package/tags/Vercel/index.html +5 -5
- package/tags/Workers/index.html +5 -5
- package/tags/hello-world/index.html +5 -5
- package/tags/index.html +4 -4
- package/tags//344/270/273/351/242/230/index.html +5 -5
- package/tags//344/272/221/346/234/215/345/212/241/345/231/250/index.html +5 -5
- package/tags//344/276/277/345/256/234/index.html +5 -5
- package/tags//345/206/231/344/275/234/index.html +5 -5
- package/tags//345/245/263/346/200/247/346/204/217/350/257/206/index.html +5 -5
- package/tags//345/255/246/344/271/240/index.html +5 -5
- package/tags//345/256/266/351/207/214/344/272/221/index.html +5 -5
- package/tags//345/271/264/347/273/210/346/200/273/347/273/223/index.html +5 -5
- package/tags//346/200/247/344/273/267/346/257/224/index.html +5 -5
- package/tags//346/212/230/350/205/276/index.html +5 -5
- package/tags//346/217/220/344/276/233/345/225/206/index.html +5 -5
- package/tags//346/227/245/345/270/270/index.html +5 -5
- package/tags//346/234/215/345/212/241/345/231/250/index.html +5 -5
- package/tags//346/265/252/346/275/256/index.html +5 -5
- package/tags//347/256/200/347/210/261/index.html +5 -5
- package/tags//350/207/252/345/212/250/346/240/207/346/263/250/index.html +5 -5
- package/tags//350/256/272/346/226/207/index.html +5 -5
- package/tags//350/260/267/346/255/214/347/277/273/350/257/221/index.html +5 -5
- package/tags//350/264/237/350/275/275/345/235/207/350/241/241/index.html +5 -5
- package/tags//351/207/221/345/217/245/index.html +5 -5
- package/tags//351/255/224/346/224/271/index.html +5 -5
package/sw.js
CHANGED
@@ -1,215 +1,191 @@
|
|
1
|
-
const CACHE_NAME =
|
1
|
+
const CACHE_NAME = 'ICDNCache';
|
2
2
|
let cachelist = [];
|
3
|
-
|
4
|
-
self.
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
3
|
+
self.addEventListener('install', async function (installEvent) {
|
4
|
+
self.skipWaiting();
|
5
|
+
installEvent.waitUntil(
|
6
|
+
caches.open(CACHE_NAME)
|
7
|
+
.then(function (cache) {
|
8
|
+
console.log('Opened cache');
|
9
|
+
return cache.addAll(cachelist);
|
10
|
+
})
|
11
|
+
);
|
12
12
|
});
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
if (err instanceof AggregateError || !(err instanceof Response)) {
|
19
|
-
const urlPath = new URL(event.request.url).pathname;
|
20
|
-
if (fullpath(urlPath).indexOf(".html") != -1) {
|
21
|
-
event.respondWith(fetch("/404.html"));
|
22
|
-
} else {
|
23
|
-
event.respondWith(handleerr(event.request, err));
|
24
|
-
}
|
25
|
-
} else {
|
26
|
-
event.respondWith(handleerr(event.request, err));
|
13
|
+
self.addEventListener('fetch', async event => {
|
14
|
+
try {
|
15
|
+
event.respondWith(handle(event.request))
|
16
|
+
} catch (msg) {
|
17
|
+
event.respondWith(handleerr(event.request, msg))
|
27
18
|
}
|
28
|
-
}
|
29
19
|
});
|
30
|
-
|
31
20
|
const handleerr = async (req, msg) => {
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
{ headers: { "content-type": "text/html; charset=utf-8" } }
|
36
|
-
);
|
37
|
-
};
|
38
|
-
|
21
|
+
return new Response(`<h1>CDN分流器遇到了致命错误</h1>
|
22
|
+
<b>${msg}</b>`, { headers: { "content-type": "text/html; charset=utf-8" } })
|
23
|
+
}
|
39
24
|
const lfetch = async (urls, url) => {
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
};
|
44
|
-
if (!Promise.any) {
|
45
|
-
Promise.any = function (promises) {
|
46
|
-
return new Promise((resolve, reject) => {
|
47
|
-
promises = Array.isArray(promises) ? promises : [];
|
48
|
-
let len = promises.length;
|
49
|
-
let errs = [];
|
50
|
-
if (len === 0) return reject(new AggregateError("All promises were rejected"));
|
51
|
-
promises.forEach((promise) => {
|
52
|
-
promise.then(
|
53
|
-
(value) => {
|
54
|
-
resolve(value);
|
55
|
-
},
|
56
|
-
(err) => {
|
57
|
-
len--;
|
58
|
-
errs.push(err);
|
59
|
-
if (len === 0) {
|
60
|
-
reject(new AggregateError(errs));
|
61
|
-
}
|
62
|
-
}
|
63
|
-
);
|
64
|
-
});
|
65
|
-
});
|
25
|
+
let controller = new AbortController();
|
26
|
+
const PauseProgress = async (res) => {
|
27
|
+
return new Response(await (res).arrayBuffer(), { status: res.status, headers: res.headers });
|
66
28
|
};
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
29
|
+
if (!Promise.any) {
|
30
|
+
Promise.any = function (promises) {
|
31
|
+
return new Promise((resolve, reject) => {
|
32
|
+
promises = Array.isArray(promises) ? promises : []
|
33
|
+
let len = promises.length
|
34
|
+
let errs = []
|
35
|
+
if (len === 0) return reject(new AggregateError('All promises were rejected'))
|
36
|
+
promises.forEach((promise) => {
|
37
|
+
promise.then(value => {
|
38
|
+
resolve(value)
|
39
|
+
}, err => {
|
40
|
+
len--
|
41
|
+
errs.push(err)
|
42
|
+
if (len === 0) {
|
43
|
+
reject(new AggregateError(errs))
|
44
|
+
}
|
45
|
+
})
|
46
|
+
})
|
47
|
+
})
|
48
|
+
}
|
49
|
+
}
|
50
|
+
return Promise.any(urls.map(urls => {
|
51
|
+
return new Promise((resolve, reject) => {
|
52
|
+
fetch(urls, {
|
53
|
+
signal: controller.signal
|
54
|
+
})
|
55
|
+
.then(PauseProgress)
|
56
|
+
.then(res => {
|
57
|
+
if (res.status == 200) {
|
58
|
+
controller.abort();
|
59
|
+
resolve(res)
|
60
|
+
} else {
|
61
|
+
reject(res)
|
62
|
+
}
|
63
|
+
})
|
73
64
|
})
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
);
|
86
|
-
};
|
87
|
-
|
65
|
+
}))
|
66
|
+
}
|
67
|
+
self.addEventListener('fetch', async event => {
|
68
|
+
try{
|
69
|
+
event.respondWith(handle(event.request))
|
70
|
+
}catch(err){
|
71
|
+
if(fullpath(urlPath).indexOf(".html")!=-1){
|
72
|
+
event.respondWith(fetch("/404.html"))
|
73
|
+
}
|
74
|
+
}
|
75
|
+
});
|
88
76
|
const fullpath = (path) => {
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
}
|
98
|
-
|
77
|
+
path = path.split('?')[0].split('#')[0]
|
78
|
+
if (path.match(/\/$/)) {
|
79
|
+
path += 'index'
|
80
|
+
}
|
81
|
+
if (!path.match(/\.[a-zA-Z]+$/)) {
|
82
|
+
path += '.html'
|
83
|
+
}
|
84
|
+
return path
|
85
|
+
}
|
99
86
|
const generate_blog_urls = (packagename, blogversion, path) => {
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
}
|
113
|
-
|
87
|
+
const npmmirror = [
|
88
|
+
// `https://unpkg.zhimg.com/${packagename}@${blogversion}`,
|
89
|
+
// `https://npm.elemecdn.com/${packagename}@${blogversion}`,
|
90
|
+
// `https://cdn1.tianli0.top/npm/${packagename}@${blogversion}`,
|
91
|
+
// `https://cdn.afdelivr.top/npm/${packagename}@${blogversion}`,
|
92
|
+
//`https://ariasakablog.s3.ladydaily.com`,
|
93
|
+
`https://registry.npmmirror.com/${packagename}/${blogversion}/files`
|
94
|
+
]
|
95
|
+
for (var i in npmmirror) {
|
96
|
+
npmmirror[i] += path
|
97
|
+
}
|
98
|
+
return npmmirror
|
99
|
+
}
|
114
100
|
const mirror = [
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
]
|
120
|
-
|
101
|
+
// `https://registry.npmmirror.com/ariasakablog/latest`,
|
102
|
+
// `https://registry.npmjs.org/ariasakablog/latest`,
|
103
|
+
// `https://mirrors.cloud.tencent.com/npm/ariasakablog/latest`,
|
104
|
+
`https://registry.npmmirror.com/q78kgblog/latest`
|
105
|
+
]
|
121
106
|
const get_newest_version = async (mirror) => {
|
122
|
-
|
123
|
-
.then(
|
124
|
-
.then(res.version)
|
125
|
-
}
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
res.text().then((text) => resolve(text));
|
139
|
-
})
|
140
|
-
.catch(() => {
|
141
|
-
resolve(null);
|
142
|
-
});
|
143
|
-
});
|
144
|
-
});
|
145
|
-
},
|
146
|
-
write: (key, value) => {
|
147
|
-
return new Promise((resolve, reject) => {
|
148
|
-
caches
|
149
|
-
.open(CACHE_NAME)
|
150
|
-
.then(function (cache) {
|
151
|
-
cache.put(new Request(`https://LOCALCACHE/${encodeURIComponent(key)}`), new Response(value));
|
152
|
-
resolve();
|
107
|
+
return lfetch(mirror, mirror[0])
|
108
|
+
.then(res => res.json())
|
109
|
+
.then(res.version)
|
110
|
+
}
|
111
|
+
self.db = { //全局定义db,只要read和write,看不懂可以略过
|
112
|
+
read: (key, config) => {
|
113
|
+
if (!config) { config = { type: "text" } }
|
114
|
+
return new Promise((resolve, reject) => {
|
115
|
+
caches.open(CACHE_NAME).then(cache => {
|
116
|
+
cache.match(new Request(`https://LOCALCACHE/${encodeURIComponent(key)}`)).then(function (res) {
|
117
|
+
if (!res) resolve(null)
|
118
|
+
res.text().then(text => resolve(text))
|
119
|
+
}).catch(() => {
|
120
|
+
resolve(null)
|
121
|
+
})
|
122
|
+
})
|
153
123
|
})
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
return;
|
167
|
-
});
|
168
|
-
};
|
124
|
+
},
|
125
|
+
write: (key, value) => {
|
126
|
+
return new Promise((resolve, reject) => {
|
127
|
+
caches.open(CACHE_NAME).then(function (cache) {
|
128
|
+
cache.put(new Request(`https://LOCALCACHE/${encodeURIComponent(key)}`), new Response(value));
|
129
|
+
resolve()
|
130
|
+
}).catch(() => {
|
131
|
+
reject()
|
132
|
+
})
|
133
|
+
})
|
134
|
+
}
|
135
|
+
}
|
169
136
|
|
170
|
-
|
171
|
-
|
172
|
-
|
137
|
+
const set_newest_version = async (mirror) => { //改为最新版本写入数据库
|
138
|
+
return lfetch(mirror, mirror[0])
|
139
|
+
.then(res => res.json()) //JSON Parse
|
140
|
+
.then(async res => {
|
141
|
+
await db.write('blog_version', res.version) //写入
|
142
|
+
return;
|
143
|
+
})
|
144
|
+
}
|
173
145
|
|
174
|
-
|
175
|
-
|
176
|
-
},
|
146
|
+
setInterval(async() => {
|
147
|
+
await set_newest_version(mirror) //定时更新,一分钟一次
|
148
|
+
}, 60*1000);
|
177
149
|
|
150
|
+
setTimeout(async() => {
|
151
|
+
await set_newest_version(mirror)//打开五秒后更新,避免堵塞
|
152
|
+
},5000)
|
178
153
|
function getFileType(fileName) {
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
154
|
+
suffix=fileName.split('.')[fileName.split('.').length-1]
|
155
|
+
if(suffix=="html"||suffix=="htm") {
|
156
|
+
return 'text/html';
|
157
|
+
}
|
158
|
+
if(suffix=="js") {
|
159
|
+
return 'text/javascript';
|
160
|
+
}
|
161
|
+
if(suffix=="css") {
|
162
|
+
return 'text/css';
|
163
|
+
}
|
164
|
+
if(suffix=="jpg"||suffix=="jpeg") {
|
165
|
+
return 'image/jpeg';
|
166
|
+
}
|
167
|
+
if(suffix=="ico") {
|
168
|
+
return 'image/x-icon';
|
169
|
+
}
|
170
|
+
if(suffix=="png") {
|
171
|
+
return 'image/png';
|
172
|
+
}
|
173
|
+
return 'text/plain';
|
197
174
|
}
|
198
|
-
|
175
|
+
const handle = async(req)=>{
|
176
|
+
const urlStr = req.url
|
177
|
+
const urlObj = new URL(urlStr);
|
178
|
+
const urlPath = urlObj.pathname;
|
179
|
+
const domain = urlObj.hostname;
|
180
|
+
//从这里开始
|
181
|
+
lxs=[]
|
182
|
+
if(domain === "anjiurine.top"){//这里写你需要拦截的域名
|
183
|
+
var l=lfetch(generate_blog_urls('q78kgblog',await db.read('blog_version') || 'latest',fullpath(urlPath)))
|
184
|
+
return l
|
185
|
+
.then(res=>res.arrayBuffer())
|
186
|
+
.then(buffer=>new Response(buffer,{headers:{"Content-Type":`${getFileType(fullpath(urlPath).split("/")[fullpath(urlPath).split("/").length-1].split("\\")[fullpath(urlPath).split("/")[fullpath(urlPath).split("/").length-1].split("\\").length-1])};charset=utf-8`}}));//重新定义header
|
187
|
+
}
|
188
|
+
else{
|
189
|
+
return fetch(req);
|
190
|
+
}
|
199
191
|
}
|
200
|
-
|
201
|
-
const handle = async (req) => {
|
202
|
-
const urlStr = req.url;
|
203
|
-
const urlObj = new URL(urlStr);
|
204
|
-
const urlPath = urlObj.pathname;
|
205
|
-
const domain = urlObj.hostname;
|
206
|
-
|
207
|
-
if (domain === "anjiurine.top") {
|
208
|
-
var l = lfetch(generate_blog_urls("q78kgblog", (await db.read("blog_version")) || "latest", fullpath(urlPath)));
|
209
|
-
return l
|
210
|
-
.then((res) => res.arrayBuffer())
|
211
|
-
.then((buffer) => new Response(buffer, { headers: { "Content-Type": `${getFileType(fullpath(urlPath).split("/")[fullpath(urlPath).split("/").length - 1].split("\\")[fullpath(urlPath).split("/")[fullpath(urlPath).split("/").length - 1].split("\\").length - 1])};charset=utf-8` } }));
|
212
|
-
} else {
|
213
|
-
return fetch(req);
|
214
|
-
}
|
215
|
-
};
|