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