swpp-backends 2.1.2 → 2.1.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/dist/ServiceWorkerBuilder.js +1 -1
- package/dist/index.js +1 -1
- package/dist/resources/sw-template.js +19 -11
- package/package.json +1 -1
|
@@ -59,7 +59,7 @@ function buildServiceWorker() {
|
|
|
59
59
|
url = new URL(request.url)
|
|
60
60
|
}
|
|
61
61
|
`).replaceAll('// [modifyRequest else-if]', `
|
|
62
|
-
else if (modify) handleFetch(
|
|
62
|
+
else if (modify) handleFetch(fetch(request).catch(err => new Response(err, {status: -1})))
|
|
63
63
|
`);
|
|
64
64
|
}
|
|
65
65
|
if (blockRequest) {
|
package/dist/index.js
CHANGED
|
@@ -10,7 +10,7 @@ const VersionAnalyzer_1 = require("./VersionAnalyzer");
|
|
|
10
10
|
const DomBuilder_1 = require("./DomBuilder");
|
|
11
11
|
// noinspection JSUnusedGlobalSymbols
|
|
12
12
|
exports.default = {
|
|
13
|
-
version: '2.1.
|
|
13
|
+
version: '2.1.3',
|
|
14
14
|
cache: {
|
|
15
15
|
readEjectData: Utils_1.readEjectData, readUpdateJson: Variant_1.readUpdateJson,
|
|
16
16
|
readRules: Variant_1.readRules, readMergeVersionMap: Variant_1.readMergeVersionMap,
|
|
@@ -121,7 +121,7 @@
|
|
|
121
121
|
const spare = getSpareUrls(request.url)
|
|
122
122
|
if (spare) handleFetch(fetchFile(request, false, spare))
|
|
123
123
|
// [modifyRequest else-if]
|
|
124
|
-
else handleFetch(fetch(request))
|
|
124
|
+
else handleFetch(fetch(request).catch(err => new Response(err, {status: -1})))
|
|
125
125
|
}
|
|
126
126
|
})
|
|
127
127
|
|
|
@@ -134,6 +134,7 @@
|
|
|
134
134
|
type: 'update',
|
|
135
135
|
update: info.list,
|
|
136
136
|
version: info.version,
|
|
137
|
+
old: info.old
|
|
137
138
|
})
|
|
138
139
|
)
|
|
139
140
|
})
|
|
@@ -152,7 +153,7 @@
|
|
|
152
153
|
|
|
153
154
|
/**
|
|
154
155
|
* 根据JSON删除缓存
|
|
155
|
-
* @returns {Promise<{version, list}>}
|
|
156
|
+
* @returns {Promise<{version, list, old}>}
|
|
156
157
|
*/
|
|
157
158
|
const updateJson = () => {
|
|
158
159
|
/**
|
|
@@ -171,14 +172,17 @@
|
|
|
171
172
|
// 跨版本幅度过大,直接清理全站
|
|
172
173
|
return true
|
|
173
174
|
}
|
|
174
|
-
/**
|
|
175
|
+
/**
|
|
176
|
+
* 解析字符串
|
|
177
|
+
* @return {Promise<any>}
|
|
178
|
+
*/
|
|
175
179
|
const parseJson = json => dbVersion.read().then(oldVersion => {
|
|
176
180
|
const {info, global} = json
|
|
177
181
|
const newVersion = {global, local: info[0].version, escape: oldVersion?.escape ?? 0}
|
|
178
182
|
//新用户不进行更新操作
|
|
179
183
|
if (!oldVersion) {
|
|
180
184
|
dbVersion.write(newVersion)
|
|
181
|
-
return newVersion
|
|
185
|
+
return {version: newVersion, old: oldVersion}
|
|
182
186
|
}
|
|
183
187
|
let list = new VersionList()
|
|
184
188
|
let refresh = parseChange(list, info, oldVersion.local)
|
|
@@ -189,19 +193,20 @@
|
|
|
189
193
|
if (global !== oldVersion.global) list.force = true
|
|
190
194
|
else list.refresh = true
|
|
191
195
|
}
|
|
192
|
-
return {list, version: newVersion}
|
|
196
|
+
return {list, version: newVersion, old: oldVersion}
|
|
193
197
|
})
|
|
194
198
|
return fetchFile(new Request('/update.json'), false)
|
|
195
199
|
.then(response => {
|
|
196
200
|
if (checkResponse(response))
|
|
197
201
|
return response.json().then(json =>
|
|
198
202
|
parseJson(json).then(result => {
|
|
199
|
-
|
|
203
|
+
const info = {version: result.version, old: result.old}
|
|
204
|
+
if (result.list)
|
|
205
|
+
return deleteCache(result.list)
|
|
200
206
|
.then(list => list.length === 0 ? null : list)
|
|
201
|
-
.then(list => ({list,
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
)
|
|
207
|
+
.then(list => Object.assign({list}, info))
|
|
208
|
+
else return info
|
|
209
|
+
})
|
|
205
210
|
)
|
|
206
211
|
else throw `加载 update.json 时遇到异常,状态码:${response.status}`
|
|
207
212
|
})
|
|
@@ -232,7 +237,10 @@
|
|
|
232
237
|
if (this.force) return true
|
|
233
238
|
// noinspection JSValidateTypes
|
|
234
239
|
url = new URL(url)
|
|
235
|
-
if (this.refresh)
|
|
240
|
+
if (this.refresh) {
|
|
241
|
+
// noinspection JSCheckFunctionSignatures
|
|
242
|
+
return findCache(url).clean
|
|
243
|
+
}
|
|
236
244
|
else {
|
|
237
245
|
for (let it of list) {
|
|
238
246
|
if (it.match(url)) return true
|