hexo-swpp 2.0.1 → 2.0.2

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/index.js +25 -23
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -70,7 +70,7 @@ if (pluginConfig?.enable) {
70
70
  `
71
71
  } else if (pluginConfig.sw.spareUrl && getSpareUrls) {
72
72
  cache += `
73
- const fetchFile = (request, banCache, spare = null) => new Promise((resolve, reject) => {
73
+ const fetchFile = (request, banCache, spare = null) => {
74
74
  if (!spare)
75
75
  spare = getSpareUrls(request.url)
76
76
  if (!spare) return fetch(request, {cache: banCache ? 'no-store' : 'default'})
@@ -78,28 +78,30 @@ if (pluginConfig?.enable) {
78
78
  const controllers = []
79
79
  let index = 0
80
80
  let error = 0
81
- const plusError = () => {
82
- if (++error === list.length) reject(\`请求 \${request.url} 失败\`)
83
- }
84
- const pull = () => {
85
- if (index === list.length) return
86
- const flag = ++index
87
- controllers.push({
88
- ctrl: new AbortController(),
89
- id: setTimeout(pull, spare.timeout)
90
- })
91
- fetch(new Request(list[flag - 1], request)).then(response => {
92
- if (response.status < 303) {
93
- for (let i in controllers) {
94
- if (i !== flag) controllers[i].ctrl.abort()
95
- clearTimeout(controllers[i].id)
96
- }
97
- resolve(response)
98
- } else plusError()
99
- }).catch(plusError)
100
- }
101
- pull()
102
- })
81
+ return new Promise((resolve, reject) => {
82
+ const plusError = () => {
83
+ if (++error === list.length) reject(\`请求 \${request.url} 失败\`)
84
+ }
85
+ const pull = () => {
86
+ if (index === list.length) return
87
+ const flag = ++index
88
+ controllers.push({
89
+ ctrl: new AbortController(),
90
+ id: setTimeout(pull, spare.timeout)
91
+ })
92
+ fetch(new Request(list[flag - 1], request)).then(response => {
93
+ if (response.status < 303) {
94
+ for (let i in controllers) {
95
+ if (i !== flag) controllers[i].ctrl.abort()
96
+ clearTimeout(controllers[i].id)
97
+ }
98
+ resolve(response)
99
+ } else plusError()
100
+ }).catch(plusError)
101
+ }
102
+ pull()
103
+ })
104
+ }
103
105
  `
104
106
  } else cache += '\nconst fetchFile = (request, banCache) => fetch(request, {cache: banCache ? "no-store" : "default"})'
105
107
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hexo-swpp",
3
- "version": "2.0.1",
3
+ "version": "2.0.2",
4
4
  "main": "index.js",
5
5
  "dependencies": {
6
6
  "hexo-log": "^3.0.0",