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