hexo-swpp 2.4.3 → 2.4.4
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/lib/sw-template.js +10 -9
- package/package.json +1 -1
package/lib/sw-template.js
CHANGED
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
/**
|
|
38
38
|
* 删除指定缓存
|
|
39
39
|
* @param list 要删除的缓存列表
|
|
40
|
-
* @return {Promise<
|
|
40
|
+
* @return {Promise<string[]>} 删除的缓存的URL列表
|
|
41
41
|
*/
|
|
42
42
|
const deleteCache = list => caches.open(CACHE_NAME).then(cache => cache.keys()
|
|
43
43
|
.then(keys => Promise.all(
|
|
@@ -82,7 +82,7 @@
|
|
|
82
82
|
self.addEventListener('message', event => {
|
|
83
83
|
// [debug message]
|
|
84
84
|
if (event.data === 'update') {
|
|
85
|
-
updateJson(
|
|
85
|
+
updateJson().then(info =>
|
|
86
86
|
// noinspection JSUnresolvedVariable
|
|
87
87
|
event.source.postMessage({
|
|
88
88
|
type: 'update',
|
|
@@ -104,10 +104,9 @@
|
|
|
104
104
|
|
|
105
105
|
/**
|
|
106
106
|
* 根据JSON删除缓存
|
|
107
|
-
* @param skip {boolean} 是否跳过更新
|
|
108
107
|
* @returns {Promise<{version, list}>}
|
|
109
108
|
*/
|
|
110
|
-
function updateJson(
|
|
109
|
+
function updateJson() {
|
|
111
110
|
/**
|
|
112
111
|
* 解析elements,并把结果输出到list中
|
|
113
112
|
* @return boolean 是否刷新全站缓存
|
|
@@ -129,7 +128,7 @@
|
|
|
129
128
|
const {info, global} = json
|
|
130
129
|
const newVersion = {global, local: info[0].version, escape: oldVersion?.escape}
|
|
131
130
|
//新用户不进行更新操作
|
|
132
|
-
if (!oldVersion
|
|
131
|
+
if (!oldVersion) {
|
|
133
132
|
dbVersion.write(newVersion)
|
|
134
133
|
return newVersion
|
|
135
134
|
}
|
|
@@ -148,10 +147,12 @@
|
|
|
148
147
|
.then(response => {
|
|
149
148
|
if (checkResponse(response))
|
|
150
149
|
return response.json().then(json =>
|
|
151
|
-
parseJson(json).then(result =>
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
150
|
+
parseJson(json).then(result => {
|
|
151
|
+
return result.list ? deleteCache(result.list)
|
|
152
|
+
.then(list => list.length === 0 ? null : list)
|
|
153
|
+
.then(list => ({list, version: result.version}))
|
|
154
|
+
: {version: result}
|
|
155
|
+
}
|
|
155
156
|
)
|
|
156
157
|
)
|
|
157
158
|
else throw `加载 update.json 时遇到异常,状态码:${response.status}`
|