fix: PDF immer von Wayback-URL, nicht Original-URL

This commit is contained in:
2026-06-12 13:49:22 +02:00
parent 07c7a6935a
commit bf5e458e28

View File

@@ -55,9 +55,11 @@ router.get('/cdx', authenticate, async (req, res) => {
}); });
// ── POST /api/tools/paywallkiller/pdf ───────────────────────────────────── // ── POST /api/tools/paywallkiller/pdf ─────────────────────────────────────
// Immer Wayback-URL verwenden Originalseite hat server-seitige Paywall
router.post('/pdf', authenticate, async (req, res) => { router.post('/pdf', authenticate, async (req, res) => {
const { originalUrl, archiveUrl } = req.body; const { originalUrl, archiveUrl } = req.body;
const targetUrl = originalUrl || archiveUrl; // archiveUrl (Wayback) bevorzugen hat vollen Text ohne server-seitige Paywall
const targetUrl = archiveUrl || originalUrl;
if (!targetUrl || typeof targetUrl !== 'string') return res.status(400).json({ error: 'URL fehlt' }); if (!targetUrl || typeof targetUrl !== 'string') return res.status(400).json({ error: 'URL fehlt' });
const tmpFile = path.join('/tmp', `pwk_${crypto.randomBytes(8).toString('hex')}.pdf`); const tmpFile = path.join('/tmp', `pwk_${crypto.randomBytes(8).toString('hex')}.pdf`);
@@ -86,68 +88,36 @@ router.post('/pdf', authenticate, async (req, res) => {
await page.setViewport({ width: 1280, height: 900 }); await page.setViewport({ width: 1280, height: 900 });
await page.goto(targetUrl, { waitUntil: 'networkidle0', timeout: 30000 }); await page.goto(targetUrl, { waitUntil: 'networkidle0', timeout: 30000 });
// Paywall-Elemente per JavaScript entfernen (effektiver als reines CSS) // UI-Störelemente entfernen (Wayback-Toolbar, Cookie-Banner, Werbung)
// Der Artikel-Text ist im Wayback-Snapshot vollständig vorhanden
await page.evaluate(() => { await page.evaluate(() => {
// Selektoren für Paywall/Overlay-Elemente const remove = [
const selectors = [ // Wayback Machine Toolbar
// Generisch '#wm-ipp-base', '#wm-ipp', '#donato', '#wm-ipp-print',
'[class*="paywall"]', '[class*="Paywall"]', '[id*="paywall"]', // Cookie/Consent Banner
'[class*="piano"]', '[class*="Piano"]', '[id*="piano"]', '#usercentrics-root', '.uc-banner', '#usercentrics-cmp-ui',
'[class*="subscription-wall"]', '[class*="subscriptionWall"]',
'[class*="overlay"]', '[class*="modal-backdrop"]',
// Cookie/Consent
'[class*="cookie-banner"]', '[class*="cookieBanner"]',
'[class*="consent"]', '[id*="consent"]',
'#usercentrics-root', '.uc-banner',
'#onetrust-consent-sdk', '.onetrust-pc-dark-filter', '#onetrust-consent-sdk', '.onetrust-pc-dark-filter',
// Piano/TP '[id*="cookie"]', '[class*="cookie-banner"]', '[class*="cookieBanner"]',
'.tp-modal', '.tp-backdrop', '#tp-container', '.tp-active', '[class*="consent-banner"]', '[id*="consent-banner"]',
// Funke/WAZ spezifisch // Sticky Header/Footer
'.funke-piano', '.piano-checkout', '.article__paywall', 'header[class*="sticky"]', '[class*="sticky-header"]',
'[data-piano-inline]', '[data-tp-content]', '[class*="stickyHeader"]', '[class*="fixed-header"]',
// Werbung // Werbung
'[id^="ad-"]', '[class*="advertisement"]', '[class*="advertisement"]', '[class*="adslot"]', '[id^="div-gpt-ad"]',
// Wayback toolbar // Newsletter-Popup, Abo-Hinweise (nicht die Paywall selbst)
'#wm-ipp-base', '#wm-ipp', '#donato', '[class*="newsletter"]', '[class*="teaser-abo"]',
]; ];
remove.forEach(sel => {
// Elemente entfernen try { document.querySelectorAll(sel).forEach(el => el.remove()); } catch {}
selectors.forEach(sel => {
try {
document.querySelectorAll(sel).forEach(el => el.remove());
} catch {}
}); });
// body/html overflow und blur zurücksetzen // body overflow freigeben
document.body.style.overflow = 'visible'; document.body.style.overflow = 'visible';
document.documentElement.style.overflow = 'visible'; document.documentElement.style.overflow = 'visible';
document.body.style.height = 'auto';
// Alle blur-Filter entfernen
document.querySelectorAll('*').forEach(el => {
const style = window.getComputedStyle(el);
if (style.filter && style.filter !== 'none') {
el.style.filter = 'none';
}
// Versteckte Artikel-Inhalte aufdecken
if (el.getAttribute('aria-hidden') === 'true') {
const tag = el.tagName.toLowerCase();
if (['p','div','section','article'].includes(tag)) {
el.removeAttribute('aria-hidden');
}
}
}); });
// max-height Limits auf Artikel entfernen await new Promise(r => setTimeout(r, 300));
document.querySelectorAll('article, [class*="article"], [class*="content"]').forEach(el => {
el.style.maxHeight = 'none';
el.style.overflow = 'visible';
el.style.webkitMaskImage = 'none';
el.style.maskImage = 'none';
});
});
// Kurz warten damit DOM-Änderungen rendern
await new Promise(r => setTimeout(r, 500));
await page.pdf({ await page.pdf({
path: tmpFile, format: 'A4', printBackground: true, path: tmpFile, format: 'A4', printBackground: true,