@uxf/scripts 1.6.0 → 1.6.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uxf/scripts",
3
- "version": "1.6.0",
3
+ "version": "1.6.2",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "bin": {
package/src/Sitemap.js CHANGED
@@ -1,3 +1,4 @@
1
+ const https = require('https');
1
2
  const { create } = require("axios");
2
3
  const cheerio = require("cheerio");
3
4
 
@@ -16,6 +17,10 @@ async function getSitemap(xml) {
16
17
  return urls;
17
18
  }
18
19
 
20
+ const agent = new https.Agent({
21
+ rejectUnauthorized: false
22
+ });
23
+
19
24
  const axios = create({
20
25
  auth:
21
26
  HTTP_PASSWORD && HTTP_USERNAME
@@ -27,6 +32,25 @@ const axios = create({
27
32
  withCredentials: true,
28
33
  maxRedirects: 0,
29
34
  timeout: 20000,
35
+ httpsAgent: agent,
36
+ headers: {
37
+ 'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/111.0.0.0 Safari/537.36',
38
+ 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8',
39
+ 'Accept-Encoding': 'gzip, deflate, br',
40
+ 'Accept-Language': 'en-US,en;q=0.9,cs-CZ;q=0.8,cs;q=0.7,de;q=0.6',
41
+ 'Cache-Control': 'no-cache',
42
+ 'Connection': 'keep-alive',
43
+ 'Pragma': 'no-cache',
44
+ 'Sec-Ch-Ua': '"Google Chrome";v="111", "Not(A:Brand";v="8", "Chromium";v="111"',
45
+ 'Sec-Ch-Ua-Arch': '"x86"',
46
+ 'Sec-Ch-Ua-Mobile': '?0',
47
+ 'Sec-Ch-Ua-Platform': '"Windows"',
48
+ 'Sec-Fetch-Dest': 'document',
49
+ 'Sec-Fetch-Mode': 'navigate',
50
+ 'Sec-Fetch-Site': 'cross-site',
51
+ 'Sec-Fetch-User': '?1',
52
+ 'Sec-Fetch-User-Agent': '?1',
53
+ },
30
54
  });
31
55
 
32
56
  module.exports = {
@@ -127,14 +127,15 @@ function createCorrectLinks(incorrectLinks, webUrl) {
127
127
  */
128
128
  async function fetchUrl(url, parentUrl = undefined, ttl = 1) {
129
129
  try {
130
- Sitemap.axios.defaults.maxRedirects = parentUrl ? 1 : 0;
130
+ Sitemap.axios.defaults.maxRedirects = parentUrl ? 3 : 0;
131
+ const encodedUrl = parentUrl ? encodeURI(url) : url;
131
132
 
132
133
  const t0 = performance.now();
133
- const { status } = await Sitemap.axios.get(url);
134
+ const { status } = await Sitemap.axios.get(encodedUrl);
134
135
  const t1 = performance.now();
135
136
 
136
137
  if (status !== 200 && ttl < MAX_TTL) {
137
- return await fetchUrl(url, parentUrl, ttl + 1);
138
+ return await fetchUrl(encodedUrl, parentUrl, ttl + 1);
138
139
  }
139
140
 
140
141
  return {
@@ -346,11 +347,13 @@ async function sendSlackMessage(errorText, slackChannel) {
346
347
  }
347
348
 
348
349
  /**
350
+ *
351
+ * @param resultErrors {string}
349
352
  * @return {Promise<void>}
350
353
  */
351
354
  async function sendGoogleChatMessage(resultErrors) {
352
355
  await GoogleChat.chatPostMessage({
353
- text: "*Odkazy uvedené v sitemap.xml nejsou dostupné*\n" + resultErrors.map(r => `${r.url} ${r.status}`).join('\n')
356
+ text: resultErrors
354
357
  });
355
358
  }
356
359
 
@@ -393,7 +396,7 @@ module.exports = async function run(sitemapUrl, webUrl, slackChannel, skip, test
393
396
  const ignoredErrorText = createErrorResult(ignoredErrors);
394
397
  logErrors(ignoredErrorText, "\nIngored errors:\n");
395
398
  await sendSlackMessage(errorText, slackChannel);
396
- await sendGoogleChatMessage(errors);
399
+ await sendGoogleChatMessage(errorText);
397
400
  }
398
401
 
399
402
  if (ignoredErrors.length > 0) {