fix: PDF nur Wayback Machine, archive.ph nur Browser-Link

This commit is contained in:
2026-06-12 11:19:16 +02:00
parent 589cb18f8c
commit 45ac6dd8c0
2 changed files with 84 additions and 97 deletions

View File

@@ -166,8 +166,8 @@ router.post('/check', authenticate, async (req, res) => {
router.post('/pdf', authenticate, async (req, res) => {
const { archiveUrl } = req.body;
if (!archiveUrl || typeof archiveUrl !== 'string') return res.status(400).json({ error: 'archiveUrl fehlt' });
if (!/^https?:\/\/(archive\.(is|ph|today|fo|li|vn|md|gg)|web\.archive\.org)\//.test(archiveUrl)) {
return res.status(400).json({ error: 'Ungültige Archiv-URL' });
if (!archiveUrl.startsWith('https://web.archive.org/')) {
return res.status(400).json({ error: 'PDF nur für Wayback Machine URLs (web.archive.org) verfügbar' });
}
let browser;

View File

@@ -13,14 +13,12 @@ function getDomain(url) {
catch { return url; }
}
// ── Wayback Machine CDX API direkt im Browser (CORS: *) ─────────────────
// Wayback CDX API direkt im Browser (CORS: *)
async function checkWayback(targetUrl) {
// Neuesten Snapshot suchen (limit=1, sortiert newest-first via fl+limit)
const cdxUrl = `https://web.archive.org/cdx/search/cdx?url=${encodeURIComponent(targetUrl)}&output=json&limit=1&fl=timestamp&filter=statuscode:200&fastLatest=true`;
const res = await fetch(cdxUrl, { signal: AbortSignal.timeout(10000) });
if (!res.ok) return null;
const res = await fetch(cdxUrl, { signal: AbortSignal.timeout(12000) });
if (!res.ok) throw new Error(`CDX API Fehler: ${res.status}`);
const data = await res.json();
// data = [["timestamp"],["20260608201434"]] oder [] wenn nichts gefunden
if (!Array.isArray(data) || data.length < 2) return null;
const timestamp = data[1]?.[0];
if (!timestamp) return null;
@@ -31,48 +29,32 @@ export default function PaywallKiller() {
const [inputUrl, setInputUrl] = useState('');
const [status, setStatus] = useState('idle');
const [waybackUrl, setWaybackUrl] = useState('');
const [archiveUrl, setArchiveUrl] = useState('');
const [errMsg, setErrMsg] = useState('');
const [pdfLoading, setPdfLoading] = useState(false);
const [pdfTarget, setPdfTarget] = useState('');
const inputRef = useRef(null);
async function handleCheck() {
const url = inputUrl.trim();
if (!url) return;
let targetUrl = url.startsWith('http') ? url : 'https://' + url;
const targetUrl = url.startsWith('http') ? url : 'https://' + url;
setStatus('checking');
setErrMsg('');
setWaybackUrl('');
setArchiveUrl('');
try {
// archive.ph URL immer konstruieren (ohne Prüfung direkt nutzbar)
const archivePh = `https://archive.ph/newest/${targetUrl}`;
// Wayback CDX parallel prüfen
let wb = null;
try { wb = await checkWayback(targetUrl); } catch { /* ignorieren */ }
const wb = await checkWayback(targetUrl);
setWaybackUrl(wb || '');
setArchiveUrl(archivePh);
if (wb) {
setStatus('found_both');
} else {
// Auch ohne Wayback-Treffer archive.ph anbieten
setStatus('found_archive');
}
// Immer "found" zeigen Wayback-Treffer oder nicht, archive.ph Link immer anbieten
setStatus('done');
} catch (err) {
setErrMsg(err.message || 'Fehler beim Suchen');
setStatus('error');
}
}
async function handlePdf(url) {
setPdfTarget(url);
async function handlePdf() {
if (!waybackUrl) return;
setPdfLoading(true);
setErrMsg('');
try {
const token = localStorage.getItem('sk_token');
const res = await fetch('/api/tools/paywallkiller/pdf', {
@@ -81,7 +63,7 @@ export default function PaywallKiller() {
'Content-Type': 'application/json',
...(token ? { Authorization: `Bearer ${token}` } : {}),
},
body: JSON.stringify({ archiveUrl: url }),
body: JSON.stringify({ archiveUrl: waybackUrl }),
});
if (!res.ok) {
const data = await res.json().catch(() => ({}));
@@ -100,7 +82,6 @@ export default function PaywallKiller() {
setErrMsg(err.message || 'PDF konnte nicht erstellt werden');
} finally {
setPdfLoading(false);
setPdfTarget('');
}
}
@@ -108,7 +89,6 @@ export default function PaywallKiller() {
setInputUrl('');
setStatus('idle');
setWaybackUrl('');
setArchiveUrl('');
setErrMsg('');
setPdfLoading(false);
setTimeout(() => inputRef.current?.focus(), 50);
@@ -122,24 +102,16 @@ export default function PaywallKiller() {
}
const isChecking = status === 'checking';
const hasResult = status.startsWith('found') || status === 'error';
const hasWayback = status === 'found_both' && waybackUrl;
const hasArchive = (status === 'found_both' || status === 'found_archive') && archiveUrl;
// PDF-Button für eine bestimmte URL
function PdfBtn({ url }) {
const loading = pdfLoading && pdfTarget === url;
return (
<button onClick={() => handlePdf(url)} disabled={pdfLoading}
style={{ ...S.btn(C.accent), opacity: pdfLoading ? 0.5 : 1, cursor: pdfLoading ? 'default' : 'pointer', fontSize: 12 }}>
{loading ? '⏳ PDF...' : '⬇ PDF'}
</button>
);
}
const isDone = status === 'done';
const hasWayback = isDone && !!waybackUrl;
const archivePhUrl = isDone
? `https://archive.ph/newest/${(inputUrl.startsWith('http') ? inputUrl : 'https://' + inputUrl).trim()}`
: '';
return (
<div style={{ padding: '20px 16px', maxWidth: 640, margin: '0 auto' }}>
{/* Header */}
<div style={{ marginBottom: 24 }}>
<div style={{ display: 'flex', alignItems: 'center', gap: 10, marginBottom: 4 }}>
<span style={{ fontSize: 20 }}>🔓</span>
@@ -172,7 +144,7 @@ export default function PaywallKiller() {
style={{ ...S.btn(C.accent), flex: 1, opacity: (isChecking || !inputUrl.trim()) ? 0.45 : 1, cursor: (isChecking || !inputUrl.trim()) ? 'default' : 'pointer' }}>
{isChecking ? '⏳ Suche Archiv...' : '🔍 Archiv suchen'}
</button>
{hasResult && (
{(isDone || status === 'error') && (
<button onClick={handleReset}
style={{ background: 'rgba(255,255,255,0.06)', border: '1px solid rgba(255,255,255,0.14)', borderRadius: 6, padding: '8px 14px', color: 'rgba(255,255,255,0.6)', cursor: 'pointer', fontFamily: 'monospace', fontSize: 12, whiteSpace: 'nowrap' }}>
Reset
@@ -181,60 +153,74 @@ export default function PaywallKiller() {
</div>
</div>
{/* Wayback Machine Treffer */}
{hasWayback && (
<div style={{ ...S.card, borderColor: `${C.success}55`, marginBottom: 12 }}>
<div style={{ display: 'flex', alignItems: 'center', gap: 8, marginBottom: 10 }}>
{/* Ergebnisse */}
{isDone && (
<>
{/* Wayback Machine */}
<div style={{ ...S.card, borderColor: hasWayback ? `${C.success}55` : 'rgba(255,255,255,0.1)', marginBottom: 12 }}>
<div style={{ display: 'flex', alignItems: 'center', gap: 8, marginBottom: hasWayback ? 10 : 0 }}>
<span>🏛</span>
<span style={{ color: C.success, fontFamily: 'monospace', fontSize: 12 }}>Wayback Machine</span>
<span style={{ background: `${C.success}20`, border: `1px solid ${C.success}44`, borderRadius: 4, padding: '1px 6px', fontSize: 10, color: C.success, fontFamily: 'monospace' }}>gefunden</span>
<span style={{ color: hasWayback ? C.success : C.muted, fontFamily: 'monospace', fontSize: 12 }}>
Wayback Machine
</span>
<span style={{
background: hasWayback ? `${C.success}20` : 'rgba(255,255,255,0.06)',
border: `1px solid ${hasWayback ? C.success + '44' : 'rgba(255,255,255,0.12)'}`,
borderRadius: 4, padding: '1px 6px', fontSize: 10,
color: hasWayback ? C.success : C.muted, fontFamily: 'monospace',
}}>
{hasWayback ? 'Snapshot gefunden' : 'kein Snapshot'}
</span>
</div>
{hasWayback && (
<>
<div style={{ background: 'rgba(255,255,255,0.03)', border: '1px solid rgba(255,255,255,0.08)', borderRadius: 6, padding: '7px 10px', marginBottom: 10, wordBreak: 'break-all' }}>
<a href={waybackUrl} target="_blank" rel="noreferrer" style={{ color: C.accent, fontSize: 11, fontFamily: 'monospace' }}>{waybackUrl}</a>
<a href={waybackUrl} target="_blank" rel="noreferrer"
style={{ color: C.accent, fontSize: 11, fontFamily: 'monospace' }}>{waybackUrl}</a>
</div>
<div style={{ display: 'flex', gap: 8 }}>
<a href={waybackUrl} target="_blank" rel="noreferrer" style={{ ...S.btn(C.success), textDecoration: 'none', fontSize: 12 }}>🌐 Öffnen</a>
<PdfBtn url={waybackUrl} />
<div style={{ display: 'flex', gap: 8, flexWrap: 'wrap' }}>
<a href={waybackUrl} target="_blank" rel="noreferrer"
style={{ ...S.btn(C.success), textDecoration: 'none', fontSize: 12 }}>
🌐 Öffnen
</a>
<button onClick={handlePdf} disabled={pdfLoading}
style={{ ...S.btn(C.accent), opacity: pdfLoading ? 0.5 : 1, cursor: pdfLoading ? 'default' : 'pointer', fontSize: 12 }}>
{pdfLoading ? '⏳ Erstelle PDF...' : '⬇ Als PDF'}
</button>
</div>
{pdfLoading && (
<div style={{ color: C.muted, fontSize: 11, fontFamily: 'monospace', marginTop: 8 }}>
Seite wird serverseitig gerendert (1530s)...
</div>
)}
</>
)}
</div>
{/* archive.ph Link */}
{hasArchive && (
<div style={{ ...S.card, borderColor: hasWayback ? 'rgba(255,255,255,0.1)' : `${C.success}55`, marginBottom: 12 }}>
{/* archive.ph nur Öffnen, kein PDF (CAPTCHA-Schutz) */}
<div style={{ ...S.card, borderColor: 'rgba(255,255,255,0.1)', marginBottom: 12 }}>
<div style={{ display: 'flex', alignItems: 'center', gap: 8, marginBottom: 10 }}>
<span>📦</span>
<span style={{ color: hasWayback ? 'rgba(255,255,255,0.6)' : C.success, fontFamily: 'monospace', fontSize: 12 }}>archive.ph</span>
{!hasWayback && <span style={{ background: `${C.success}20`, border: `1px solid ${C.success}44`, borderRadius: 4, padding: '1px 6px', fontSize: 10, color: C.success, fontFamily: 'monospace' }}>neuester Snapshot</span>}
<span style={{ color: 'rgba(255,255,255,0.55)', fontFamily: 'monospace', fontSize: 12 }}>archive.ph</span>
</div>
<div style={{ background: 'rgba(255,255,255,0.03)', border: '1px solid rgba(255,255,255,0.08)', borderRadius: 6, padding: '7px 10px', marginBottom: 10, wordBreak: 'break-all' }}>
<a href={archiveUrl} target="_blank" rel="noreferrer" style={{ color: C.accent, fontSize: 11, fontFamily: 'monospace' }}>{archiveUrl}</a>
</div>
<div style={{ display: 'flex', gap: 8 }}>
<a href={archiveUrl} target="_blank" rel="noreferrer" style={{ ...S.btn(C.success), textDecoration: 'none', fontSize: 12 }}>🌐 Öffnen</a>
<PdfBtn url={archiveUrl} />
</div>
{!hasWayback && (
<div style={{ color: C.muted, fontSize: 10, fontFamily: 'monospace', marginTop: 8 }}>
Kein Wayback-Snapshot gefunden. archive.ph-Link öffnet direkt den neuesten Snapshot (falls vorhanden).
</div>
)}
</div>
)}
{/* PDF-Ladehinweis */}
{pdfLoading && (
<div style={{ ...S.card, borderColor: `${C.accent}44`, marginBottom: 12 }}>
<div style={{ color: C.muted, fontSize: 11, fontFamily: 'monospace' }}>
Seite wird serverseitig gerendert, bitte warten (1530s)...
<div style={{ display: 'flex', gap: 8, alignItems: 'center' }}>
<a href={archivePhUrl} target="_blank" rel="noreferrer"
style={{ ...S.btn(C.muted), textDecoration: 'none', fontSize: 12 }}>
🌐 Öffnen
</a>
<span style={{ color: C.muted, fontSize: 10, fontFamily: 'monospace' }}>
Kein PDF CAPTCHA-geschützt
</span>
</div>
</div>
</>
)}
{/* Fehler */}
{errMsg && (
<div style={{ ...S.card, borderColor: `${C.error}44`, marginBottom: 12 }}>
<div style={{ display: 'flex', alignItems: 'center', gap: 8 }}>
<div style={{ ...S.card, borderColor: `${C.error}44`, marginTop: 8 }}>
<div style={{ display: 'flex', alignItems: 'flex-start', gap: 8 }}>
<span></span>
<span style={{ color: C.error, fontFamily: 'monospace', fontSize: 12 }}>{errMsg}</span>
</div>
@@ -247,8 +233,9 @@ export default function PaywallKiller() {
<div style={{ ...S.head, marginBottom: 10 }}>SO FUNKTIONIERT ES</div>
{[
['1', 'URL des gesperrten Artikels einfügen'],
['2', 'Wayback Machine + archive.ph werden geprüft'],
['3', 'Im Browser öffnen oder als PDF speichern'],
['2', 'Wayback Machine wird durchsucht (web.archive.org)'],
['3', 'Snapshot öffnen oder als PDF speichern'],
['4', 'Alternativ: archive.ph im Browser öffnen'],
].map(([num, text]) => (
<div key={num} style={{ display: 'flex', gap: 10, alignItems: 'center', marginBottom: 8 }}>
<span style={{ background: `${C.accent}20`, border: `1px solid ${C.accent}44`, borderRadius: '50%', width: 20, height: 20, flexShrink: 0, display: 'flex', alignItems: 'center', justifyContent: 'center', fontSize: 10, color: C.accent, fontFamily: 'monospace' }}>{num}</span>