hexo-swpp 2.4.2 → 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 +14 -24
  2. package/package.json +1 -1
@@ -19,21 +19,10 @@
19
19
  dbVersion.read().then(oldVersion => {
20
20
  if (oldVersion && oldVersion.escape !== escape) {
21
21
  oldVersion.escape = escape
22
- const rules = new VersionList()
23
- rules.refresh = true
24
22
  // noinspection JSUnresolvedVariable
25
- Promise.all([
26
- dbVersion.write(oldVersion),
27
- deleteCache(rules),
28
- updateJson(true)
29
- ]).then(
30
- args => clients.matchAll().then(
31
- list => list.forEach(client => client.postMessage({
32
- type: 'escape',
33
- version: args[2].version
34
- }))
35
- )
36
- )
23
+ caches.delete(CACHE_NAME)
24
+ .then(() => clients.matchAll())
25
+ .then(list => list.forEach(client => client.postMessage({type: 'escape'})))
37
26
  }
38
27
  })
39
28
  })
@@ -48,7 +37,7 @@
48
37
  /**
49
38
  * 删除指定缓存
50
39
  * @param list 要删除的缓存列表
51
- * @return {Promise<Array<string>>} 删除的缓存的URL列表
40
+ * @return {Promise<string[]>} 删除的缓存的URL列表
52
41
  */
53
42
  const deleteCache = list => caches.open(CACHE_NAME).then(cache => cache.keys()
54
43
  .then(keys => Promise.all(
@@ -93,7 +82,7 @@
93
82
  self.addEventListener('message', event => {
94
83
  // [debug message]
95
84
  if (event.data === 'update') {
96
- updateJson(false).then(info =>
85
+ updateJson().then(info =>
97
86
  // noinspection JSUnresolvedVariable
98
87
  event.source.postMessage({
99
88
  type: 'update',
@@ -115,10 +104,9 @@
115
104
 
116
105
  /**
117
106
  * 根据JSON删除缓存
118
- * @param skip {boolean} 是否跳过更新
119
107
  * @returns {Promise<{version, list}>}
120
108
  */
121
- function updateJson(skip) {
109
+ function updateJson() {
122
110
  /**
123
111
  * 解析elements,并把结果输出到list中
124
112
  * @return boolean 是否刷新全站缓存
@@ -138,9 +126,9 @@
138
126
  /** 解析字符串 */
139
127
  const parseJson = json => dbVersion.read().then(oldVersion => {
140
128
  const {info, global} = json
141
- const newVersion = {global, local: info[0].version, escape: oldVersion.escape}
129
+ const newVersion = {global, local: info[0].version, escape: oldVersion?.escape}
142
130
  //新用户不进行更新操作
143
- if (!oldVersion || skip) {
131
+ if (!oldVersion) {
144
132
  dbVersion.write(newVersion)
145
133
  return newVersion
146
134
  }
@@ -159,10 +147,12 @@
159
147
  .then(response => {
160
148
  if (checkResponse(response))
161
149
  return response.json().then(json =>
162
- parseJson(json).then(result =>
163
- result.list ? deleteCache(result.list).then(list => {
164
- return {list, version: result.version}
165
- }) : {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
+ }
166
156
  )
167
157
  )
168
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.2",
3
+ "version": "2.4.4",
4
4
  "main": "index.js",
5
5
  "dependencies": {
6
6
  "hexo-log": "^3.0.0",