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.
Files changed (2) hide show
  1. package/lib/sw-template.js +10 -9
  2. package/package.json +1 -1
@@ -37,7 +37,7 @@
37
37
  /**
38
38
  * 删除指定缓存
39
39
  * @param list 要删除的缓存列表
40
- * @return {Promise<Array<string>>} 删除的缓存的URL列表
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(false).then(info =>
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(skip) {
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 || skip) {
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
- result.list ? deleteCache(result.list).then(list => {
153
- return {list, version: result.version}
154
- }) : {version: result}
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}`
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hexo-swpp",
3
- "version": "2.4.3",
3
+ "version": "2.4.4",
4
4
  "main": "index.js",
5
5
  "dependencies": {
6
6
  "hexo-log": "^3.0.0",