hexo-swpp 2.2.2 → 2.2.3

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/package.json +1 -1
  2. package/sw-template.js +10 -15
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hexo-swpp",
3
- "version": "2.2.2",
3
+ "version": "2.2.3",
4
4
  "main": "index.js",
5
5
  "dependencies": {
6
6
  "hexo-log": "^3.0.0",
package/sw-template.js CHANGED
@@ -12,6 +12,7 @@
12
12
  const { cacheList, modifyRequest, fetchFile, getSpareUrls } = require('../sw-rules')
13
13
 
14
14
  // 检查请求是否成功
15
+ // noinspection JSUnusedLocalSymbols
15
16
  const checkResponse = response => response.ok || [301, 302, 307].includes(response.status)
16
17
 
17
18
  /**
@@ -39,7 +40,7 @@
39
40
  const key = `${url.protocol}//${url.host}${url.pathname}`
40
41
  event.respondWith(caches.match(key).then(cache =>
41
42
  cache ? cache : fetchFile(newRequest, true).then(response => {
42
- if (checkResponse(response)) {
43
+ if (response.status === 200) {
43
44
  const clone = response.clone()
44
45
  caches.open(CACHE_NAME).then(it => it.put(key, clone))
45
46
  }
@@ -128,20 +129,14 @@
128
129
  })
129
130
  }
130
131
  return fetchFile(new Request('/update.json'), false)
131
- .then(response => {
132
- if (checkResponse(response))
133
- return response.json().then(json =>
134
- parseJson(json).then(result => result.list ?
135
- deleteCache(result.list).then(list => {
136
- return {
137
- list,
138
- version: result.version
139
- }
140
- }) : {version: result}
141
- )
142
- )
143
- else throw `加载 update.json 时遇到异常,状态码:${response.status}`
144
- })
132
+ .then(response => response.json())
133
+ .then(json =>
134
+ parseJson(json).then(result =>
135
+ result.list ? deleteCache(result.list).then(list => {
136
+ return {list, version: result.version}
137
+ }) : {version: result}
138
+ )
139
+ )
145
140
  }
146
141
 
147
142
  /**