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.
- package/index.js +25 -23
- 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) =>
|
|
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
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
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
|
}
|