sitecheckultra 2.0.2 → 2.1.0
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/README.md +21 -6
- package/bin/sitecheckultra.js +82 -12
- package/lib/analyzer.js +162 -11
- package/lib/crawl-error.js +171 -0
- package/lib/crawler.js +297 -186
- package/lib/exporter.js +126 -110
- package/lib/page-preview.js +311 -0
- package/lib/scorer.js +50 -17
- package/package.json +7 -7
- package/public/app.js +490 -58
- package/public/index.html +27 -9
- package/public/styles.css +138 -1
- package/server.js +66 -2
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Normalizes crawl/network failures into concrete German UI messages.
|
|
3
|
+
* Used by analyzer/crawler at the boundary where errors are set; UI can also
|
|
4
|
+
* re-humanize legacy English undici strings from older crawl JSON.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
const HTTP_REASON_PHRASES = {
|
|
8
|
+
400: 'Bad Request',
|
|
9
|
+
401: 'Unauthorized',
|
|
10
|
+
403: 'Forbidden',
|
|
11
|
+
404: 'Not Found',
|
|
12
|
+
405: 'Method Not Allowed',
|
|
13
|
+
407: 'Proxy Authentication Required',
|
|
14
|
+
408: 'Request Timeout',
|
|
15
|
+
410: 'Gone',
|
|
16
|
+
429: 'Too Many Requests',
|
|
17
|
+
500: 'Internal Server Error',
|
|
18
|
+
502: 'Bad Gateway',
|
|
19
|
+
503: 'Service Unavailable',
|
|
20
|
+
504: 'Gateway Timeout'
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
/** True for timeout messages we emit (and legacy "Timeout"). */
|
|
24
|
+
export function isTimeoutErrorMessage(msg) {
|
|
25
|
+
return typeof msg === 'string' && /^Timeout\b/i.test(msg.trim());
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function formatHttpStatusError(status) {
|
|
29
|
+
const code = Number(status) || 0;
|
|
30
|
+
if (!code) return 'HTTP-Fehler';
|
|
31
|
+
const phrase = HTTP_REASON_PHRASES[code];
|
|
32
|
+
return phrase ? `HTTP ${code} ${phrase}` : `HTTP ${code}`;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export function formatNonHtmlError(contentType) {
|
|
36
|
+
const ct = (contentType || '').trim() || 'unbekannt';
|
|
37
|
+
return `Kein HTML (content-type: ${ct})`;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export function formatRobotsBlockedError(rule) {
|
|
41
|
+
if (rule) return `Durch robots.txt blockiert: Disallow ${rule}`;
|
|
42
|
+
return 'Durch robots.txt blockiert';
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export function formatRedirectLoopError(hops = 0) {
|
|
46
|
+
if (hops > 0) return `Zu viele Redirects (${hops}+)`;
|
|
47
|
+
return 'Zu viele Redirects';
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Map Node/undici/Abort errors (or raw strings) to a German reason.
|
|
52
|
+
* @param {Error|string|null|undefined} err
|
|
53
|
+
* @param {{ timeoutMs?: number }} [opts]
|
|
54
|
+
*/
|
|
55
|
+
export function formatNetworkError(err, opts = {}) {
|
|
56
|
+
if (err == null || err === '') return null;
|
|
57
|
+
|
|
58
|
+
const name = typeof err === 'object' ? (err.name || '') : '';
|
|
59
|
+
const code = typeof err === 'object'
|
|
60
|
+
? (err.code || err.cause?.code || err.cause?.cause?.code || '')
|
|
61
|
+
: '';
|
|
62
|
+
const raw = typeof err === 'string'
|
|
63
|
+
? err
|
|
64
|
+
: String(err.message || err.cause?.message || 'Netzwerkfehler');
|
|
65
|
+
|
|
66
|
+
if (name === 'TimeoutError' || name === 'AbortError' || isTimeoutErrorMessage(raw)) {
|
|
67
|
+
const sec = opts.timeoutMs ? Math.max(1, Math.round(opts.timeoutMs / 1000)) : null;
|
|
68
|
+
return sec ? `Timeout nach ${sec}s` : 'Timeout';
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
return humanizeCrawlErrorMessage(raw, { code });
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Re-humanize a stored error string (new DE messages pass through; EN/codes map to DE).
|
|
76
|
+
* @param {string|null|undefined} raw
|
|
77
|
+
* @param {{ code?: string, timeoutMs?: number, contentType?: string, robotsDisallowRule?: string }} [ctx]
|
|
78
|
+
*/
|
|
79
|
+
export function humanizeCrawlErrorMessage(raw, ctx = {}) {
|
|
80
|
+
if (raw == null || raw === '') return null;
|
|
81
|
+
const msg = String(raw).trim();
|
|
82
|
+
if (!msg) return null;
|
|
83
|
+
|
|
84
|
+
// Already German / already formatted — keep concrete messages
|
|
85
|
+
if (/^(Timeout nach \d+s|DNS nicht auflösbar|SSL-Zertifikat ungültig|Verbindung abgelehnt|Zu viele Redirects|Kein HTML|Durch robots\.txt|HTTP \d{3}\b)/i.test(msg)) {
|
|
86
|
+
return msg;
|
|
87
|
+
}
|
|
88
|
+
if (msg === 'Timeout' || /^The operation was aborted/i.test(msg) || /^This operation was aborted/i.test(msg)) {
|
|
89
|
+
const sec = ctx.timeoutMs ? Math.max(1, Math.round(ctx.timeoutMs / 1000)) : null;
|
|
90
|
+
return sec ? `Timeout nach ${sec}s` : 'Timeout';
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
const blob = `${ctx.code || ''} ${msg}`;
|
|
94
|
+
|
|
95
|
+
if (/ENOTFOUND|getaddrinfo|ERR_NAME_NOT_RESOLVED|DNS/i.test(blob)) {
|
|
96
|
+
return 'DNS nicht auflösbar';
|
|
97
|
+
}
|
|
98
|
+
if (/ECONNREFUSED|ERR_CONNECTION_REFUSED/i.test(blob)) {
|
|
99
|
+
return 'Verbindung abgelehnt';
|
|
100
|
+
}
|
|
101
|
+
if (/ECONNRESET|ERR_CONNECTION_RESET|socket hang up/i.test(blob)) {
|
|
102
|
+
return 'Verbindung zurückgesetzt';
|
|
103
|
+
}
|
|
104
|
+
if (/ETIMEDOUT|ESOCKETTIMEDOUT|ERR_CONNECTION_TIMED_OUT|Connect Timeout/i.test(blob)) {
|
|
105
|
+
const sec = ctx.timeoutMs ? Math.max(1, Math.round(ctx.timeoutMs / 1000)) : null;
|
|
106
|
+
return sec ? `Timeout nach ${sec}s` : 'Verbindungs-Timeout';
|
|
107
|
+
}
|
|
108
|
+
if (/ENETUNREACH|EHOSTUNREACH|ERR_ADDRESS_UNREACHABLE/i.test(blob)) {
|
|
109
|
+
return 'Host nicht erreichbar';
|
|
110
|
+
}
|
|
111
|
+
if (/CERT|SSL|TLS|UNABLE_TO_VERIFY|ERR_TLS|ERR_SSL|certificate/i.test(blob)) {
|
|
112
|
+
return 'SSL-Zertifikat ungültig';
|
|
113
|
+
}
|
|
114
|
+
if (/redirect|ERR_TOO_MANY_REDIRECTS/i.test(blob) && /many|zu viele|loop/i.test(blob)) {
|
|
115
|
+
return 'Zu viele Redirects';
|
|
116
|
+
}
|
|
117
|
+
if (/EAI_AGAIN/i.test(blob)) {
|
|
118
|
+
return 'DNS vorübergehend nicht verfügbar';
|
|
119
|
+
}
|
|
120
|
+
if (/EPROTO|protocol/i.test(blob) && /SSL|TLS|HTTPS/i.test(blob)) {
|
|
121
|
+
return 'SSL/TLS-Protokollfehler';
|
|
122
|
+
}
|
|
123
|
+
if (/fetch failed/i.test(msg) && ctx.code) {
|
|
124
|
+
return humanizeCrawlErrorMessage(ctx.code, ctx) || 'Netzwerkfehler';
|
|
125
|
+
}
|
|
126
|
+
if (/^Netzwerkfehler$/i.test(msg) || /^network error$/i.test(msg) || /^fetch failed$/i.test(msg)) {
|
|
127
|
+
return 'Netzwerkfehler';
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
// Strip noisy undici prefixes but keep short technical detail if unknown
|
|
131
|
+
const cleaned = msg
|
|
132
|
+
.replace(/^Error:\s*/i, '')
|
|
133
|
+
.replace(/^fetch failed:\s*/i, '')
|
|
134
|
+
.trim();
|
|
135
|
+
if (cleaned.length > 120) return `${cleaned.slice(0, 117)}…`;
|
|
136
|
+
return cleaned || 'Netzwerkfehler';
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* Best human-readable crawl-failure reason for a page object (UI + exports).
|
|
141
|
+
* Returns null when the page was successfully fetched as HTML.
|
|
142
|
+
*/
|
|
143
|
+
export function describePageCrawlFailure(page) {
|
|
144
|
+
if (!page) return null;
|
|
145
|
+
|
|
146
|
+
if (page.error) {
|
|
147
|
+
return humanizeCrawlErrorMessage(page.error, {
|
|
148
|
+
contentType: page.contentType,
|
|
149
|
+
robotsDisallowRule: page.robotsDisallowRule
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
const status = Number(page.status || page.finalStatus || 0);
|
|
154
|
+
if (status === 0) return 'Verbindungsfehler';
|
|
155
|
+
|
|
156
|
+
const ct = (page.contentType || '').toLowerCase();
|
|
157
|
+
const hasHtmlHint = !ct || ct.includes('html') || ct.includes('xhtml');
|
|
158
|
+
if (!hasHtmlHint && !(page.title || page.h1Text || (page.headings || []).length)) {
|
|
159
|
+
return formatNonHtmlError(page.contentType);
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
if (status === 401 || status === 403) {
|
|
163
|
+
return formatHttpStatusError(status);
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
if (page.blockedByRobotsTxt) {
|
|
167
|
+
return formatRobotsBlockedError(page.robotsDisallowRule);
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
return null;
|
|
171
|
+
}
|