Files
Multi-Hoster-Upload/lib/upload-diagnostics.js
T
Sucukdeluxe a299fc204b release: v2.1.16
Add queue search and filters, safe upload diagnostics, session report exports, account check visibility, and explicit interrupted-upload recovery.\n\nSanitize diagnostic response snippets in persisted results and rotation logs, protect CSV exports against formula injection, and add regression coverage for diagnostics and reports.
2026-08-12 12:04:47 +02:00

34 lines
1.3 KiB
JavaScript

function cleanText(value, limit = 320) {
let text = String(value || '').replace(/[\r\n\t]+/g, ' ').replace(/\s+/g, ' ').trim();
if (!text) return '';
text = text.replace(/https?:\/\/[^\s"'<>]+/gi, (raw) => {
try {
const url = new URL(raw);
return `${url.host}${url.pathname}`;
} catch {
return '[URL]';
}
});
text = text.replace(/(["']?(?:api[_-]?key|token|password|cookie|authorization|session)["']?\s*[:=]\s*)[^,;\s}"']+/gi, '$1[redacted]');
if (/^(?:bearer|basic)\s+/i.test(text)) {
text = '[redacted authorization]';
}
return text.slice(0, limit);
}
function normalizeFailureDetails(diagnostic) {
if (!diagnostic || typeof diagnostic !== 'object') return null;
const httpStatus = Number.isInteger(Number(diagnostic.http)) && Number(diagnostic.http) >= 100 && Number(diagnostic.http) <= 599
? Number(diagnostic.http)
: null;
const contentType = cleanText(diagnostic.contentType, 120);
const responseSnippet = cleanText(diagnostic.payloadSnippet, 320);
const details = {};
if (httpStatus !== null) details.httpStatus = httpStatus;
if (contentType) details.contentType = contentType;
if (responseSnippet) details.responseSnippet = responseSnippet;
return Object.keys(details).length > 0 ? details : null;
}
module.exports = { normalizeFailureDetails };