swpp-backends 0.0.6-alpha → 0.0.8-alpha
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/fileAnalyzer.js +21 -19
- package/package.json +1 -1
package/dist/fileAnalyzer.js
CHANGED
|
@@ -214,7 +214,7 @@ exports.buildVersionJson = buildVersionJson;
|
|
|
214
214
|
*/
|
|
215
215
|
async function eachAllLinkInUrl(domain, url, result, event) {
|
|
216
216
|
if (url.startsWith('//'))
|
|
217
|
-
url = 'http' + url;
|
|
217
|
+
url = 'http:' + url;
|
|
218
218
|
if (url in result)
|
|
219
219
|
return event?.(url);
|
|
220
220
|
if (!url.startsWith('http') || isExclude(domain, url))
|
|
@@ -237,9 +237,6 @@ async function eachAllLinkInUrl(domain, url, result, event) {
|
|
|
237
237
|
copyTree(url);
|
|
238
238
|
}
|
|
239
239
|
}
|
|
240
|
-
else {
|
|
241
|
-
event?.(value);
|
|
242
|
-
}
|
|
243
240
|
};
|
|
244
241
|
copyTree(url);
|
|
245
242
|
return;
|
|
@@ -256,23 +253,30 @@ async function eachAllLinkInUrl(domain, url, result, event) {
|
|
|
256
253
|
}
|
|
257
254
|
const pathname = new URL(url).pathname;
|
|
258
255
|
let content;
|
|
259
|
-
const relay = [];
|
|
260
256
|
const nextEvent = (it) => {
|
|
261
|
-
|
|
262
|
-
|
|
257
|
+
result[url].push(it);
|
|
258
|
+
};
|
|
259
|
+
const update = () => {
|
|
260
|
+
if (stable)
|
|
261
|
+
result[url] = [];
|
|
262
|
+
else
|
|
263
|
+
result[url] = crypto.createHash('md5').update(content).digest('hex');
|
|
263
264
|
};
|
|
264
265
|
switch (true) {
|
|
265
266
|
case pathname.endsWith('.html'):
|
|
266
267
|
case pathname.endsWith('/'):
|
|
267
268
|
content = await response.text();
|
|
269
|
+
update();
|
|
268
270
|
await eachAllLinkInHtml(domain, content, result, nextEvent);
|
|
269
271
|
break;
|
|
270
272
|
case pathname.endsWith('.css'):
|
|
271
273
|
content = await response.text();
|
|
274
|
+
update();
|
|
272
275
|
await eachAllLinkInCss(domain, content, result, nextEvent);
|
|
273
276
|
break;
|
|
274
277
|
case pathname.endsWith('.js'):
|
|
275
278
|
content = await response.text();
|
|
279
|
+
update();
|
|
276
280
|
await eachAllLinkInJavaScript(domain, content, result, nextEvent);
|
|
277
281
|
break;
|
|
278
282
|
default:
|
|
@@ -285,14 +289,6 @@ async function eachAllLinkInUrl(domain, url, result, event) {
|
|
|
285
289
|
}
|
|
286
290
|
break;
|
|
287
291
|
}
|
|
288
|
-
if (content) {
|
|
289
|
-
if (stable) {
|
|
290
|
-
result[url] = relay;
|
|
291
|
-
}
|
|
292
|
-
else {
|
|
293
|
-
result[url] = crypto.createHash('md5').update(content).digest('hex');
|
|
294
|
-
}
|
|
295
|
-
}
|
|
296
292
|
}
|
|
297
293
|
exports.eachAllLinkInUrl = eachAllLinkInUrl;
|
|
298
294
|
/**
|
|
@@ -313,7 +309,9 @@ async function eachAllLinkInHtml(domain, content, result, event) {
|
|
|
313
309
|
let url = undefined;
|
|
314
310
|
switch (node.tagName) {
|
|
315
311
|
case 'link':
|
|
316
|
-
|
|
312
|
+
// noinspection SpellCheckingInspection
|
|
313
|
+
if (node.attributes.rel !== 'preconnect')
|
|
314
|
+
url = node.attributes.href;
|
|
317
315
|
break;
|
|
318
316
|
case 'script':
|
|
319
317
|
case 'img':
|
|
@@ -335,8 +333,10 @@ async function eachAllLinkInHtml(domain, content, result, event) {
|
|
|
335
333
|
else if (node.tagName === 'style') {
|
|
336
334
|
await eachAllLinkInCss(domain, node.rawText, result, event);
|
|
337
335
|
}
|
|
338
|
-
|
|
339
|
-
|
|
336
|
+
if (node.childNodes) {
|
|
337
|
+
for (let childNode of node.childNodes) {
|
|
338
|
+
await each(childNode);
|
|
339
|
+
}
|
|
340
340
|
}
|
|
341
341
|
};
|
|
342
342
|
await each(fast_html_parser_1.default.parse(content, { style: true, script: true }));
|
|
@@ -427,7 +427,9 @@ async function eachAllLinkInJavaScript(domain, content, result, event) {
|
|
|
427
427
|
exports.eachAllLinkInJavaScript = eachAllLinkInJavaScript;
|
|
428
428
|
/** 判断一个 URL 是否是外部链接 */
|
|
429
429
|
function isExternalLink(domain, url) {
|
|
430
|
-
|
|
430
|
+
if (url[0] === '/' && url[1] !== '/')
|
|
431
|
+
return false;
|
|
432
|
+
return !new RegExp(`^(https?:)?\\/\\/${domain}`).test(url);
|
|
431
433
|
}
|
|
432
434
|
/**
|
|
433
435
|
* 查询指定 URL 对应的缓存规则
|