hexo-swpp 2.0.2 → 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.
- package/index.js +5 -7
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -71,30 +71,28 @@ if (pluginConfig?.enable) {
|
|
|
71
71
|
} else if (pluginConfig.sw.spareUrl && getSpareUrls) {
|
|
72
72
|
cache += `
|
|
73
73
|
const fetchFile = (request, banCache, spare = null) => {
|
|
74
|
-
if (!spare)
|
|
75
|
-
spare = getSpareUrls(request.url)
|
|
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
79
|
return new Promise((resolve, reject) => {
|
|
82
80
|
const plusError = () => {
|
|
83
81
|
if (++error === list.length) reject(\`请求 \${request.url} 失败\`)
|
|
84
82
|
}
|
|
85
83
|
const pull = () => {
|
|
86
|
-
|
|
87
|
-
|
|
84
|
+
const flag = controllers.length
|
|
85
|
+
if (flag === list.length) return
|
|
88
86
|
controllers.push({
|
|
89
87
|
ctrl: new AbortController(),
|
|
90
88
|
id: setTimeout(pull, spare.timeout)
|
|
91
89
|
})
|
|
92
|
-
fetch(new Request(list[flag
|
|
90
|
+
fetch(new Request(list[flag], request)).then(response => {
|
|
93
91
|
if (response.status < 303) {
|
|
94
92
|
for (let i in controllers) {
|
|
95
93
|
if (i !== flag) controllers[i].ctrl.abort()
|
|
96
|
-
clearTimeout(controllers[i].id)
|
|
97
94
|
}
|
|
95
|
+
clearTimeout(controllers[controllers.length - 1].id)
|
|
98
96
|
resolve(response)
|
|
99
97
|
} else plusError()
|
|
100
98
|
}).catch(plusError)
|