fix: Wayback-Suche via Backend-Proxy, Clipboard-Button entfernt
This commit is contained in:
@@ -229,4 +229,35 @@ router.post('/pdf', authenticate, async (req, res) => {
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
// ── GET /api/tools/paywallkiller/wayback?url=... ──────────────────────────
|
||||
// Proxyt die Wayback CDX API – umgeht CORS/CSP Probleme im Browser
|
||||
router.get('/wayback', authenticate, async (req, res) => {
|
||||
const { url } = req.query;
|
||||
if (!url || typeof url !== 'string') return res.status(400).json({ error: 'url Parameter fehlt' });
|
||||
|
||||
let targetUrl = url.trim();
|
||||
if (!targetUrl.startsWith('http')) targetUrl = 'https://' + targetUrl;
|
||||
|
||||
const cdxUrl = `https://web.archive.org/cdx/search/cdx?url=${encodeURIComponent(targetUrl)}&output=json&limit=1&fl=timestamp&filter=statuscode:200&fastLatest=true`;
|
||||
|
||||
try {
|
||||
const result = await fetchPage(cdxUrl);
|
||||
if (result.statusCode !== 200) {
|
||||
return res.status(502).json({ error: `Wayback API Fehler: ${result.statusCode}` });
|
||||
}
|
||||
let data;
|
||||
try { data = JSON.parse(result.body); } catch { return res.status(502).json({ error: 'Ungültige Wayback-Antwort' }); }
|
||||
|
||||
// data = [["timestamp"],["20260608201434"]] oder [] wenn nichts gefunden
|
||||
if (!Array.isArray(data) || data.length < 2 || !data[1]?.[0]) {
|
||||
return res.json({ found: false });
|
||||
}
|
||||
const timestamp = data[1][0];
|
||||
return res.json({ found: true, waybackUrl: `https://web.archive.org/web/${timestamp}/${targetUrl}` });
|
||||
} catch (err) {
|
||||
return res.status(500).json({ error: 'Fehler: ' + err.message });
|
||||
}
|
||||
});
|
||||
|
||||
module.exports = router;
|
||||
|
||||
Reference in New Issue
Block a user