From b62e298c8cd9d2e01415931a7e3dbf0e617873b6 Mon Sep 17 00:00:00 2001 From: Michael SCHAL Date: Sat, 3 Jan 2026 23:51:25 +0100 Subject: [PATCH] feat: Add script to test RSS feed parsing with custom User-Agent. --- routes/rss.routes.js | 37 ++++++++++++++++++++++++++++++++++++- scripts/test-rss-feed.js | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 69 insertions(+), 1 deletion(-) create mode 100644 scripts/test-rss-feed.js diff --git a/routes/rss.routes.js b/routes/rss.routes.js index 61188fc..5e46c43 100644 --- a/routes/rss.routes.js +++ b/routes/rss.routes.js @@ -51,7 +51,42 @@ router.post('/feeds', requireAdmin, async (req, res) => { // Tester le flux try { - const feed = await parser.parseURL(url); + let feed; + + // Essai 1: Parser direct + try { + feed = await parser.parseURL(url); + } catch (directError) { + logger.warn(`[RSS] Parser direct échoué pour ${url}: ${directError.message}, tentative avec axios...`); + + // Essai 2: Fetch avec axios puis parse le contenu + const axiosResponse = await axios.get(url, { + timeout: 30000, + headers: { + 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36', + 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8', + 'Accept-Language': 'fr-FR,fr;q=0.9,en-US;q=0.8,en;q=0.7', + 'Accept-Encoding': 'gzip, deflate, br', + 'Connection': 'keep-alive', + 'Upgrade-Insecure-Requests': '1', + 'Sec-Fetch-Dest': 'document', + 'Sec-Fetch-Mode': 'navigate', + 'Sec-Fetch-Site': 'none', + 'Sec-Fetch-User': '?1', + 'Cache-Control': 'max-age=0' + }, + responseType: 'text', + validateStatus: () => true + }); + + if (axiosResponse.status !== 200) { + logger.error(`[RSS] Axios fetch failed with status ${axiosResponse.status} for ${url}`); + throw new Error(`HTTP ${axiosResponse.status}`); + } + + // Parser le contenu XML récupéré + feed = await parser.parseString(axiosResponse.data); + } logger.info(`[CREATE RSS FEED] Ajout flux - url: "${url}", title: "${feed.title || url}"`); diff --git a/scripts/test-rss-feed.js b/scripts/test-rss-feed.js new file mode 100644 index 0000000..7a78d49 --- /dev/null +++ b/scripts/test-rss-feed.js @@ -0,0 +1,33 @@ +// Script pour tester le parsing RSS avec le User-Agent +const Parser = require('rss-parser'); + +const parser = new Parser({ + headers: { + 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36', + 'Accept': 'application/rss+xml, application/xml, text/xml, */*' + }, + timeout: 30000 +}); + +const testUrl = 'https://fresh.vonrodbox.eu/i/?a=rss&user=Michael&token=Lapin2509&hours=168'; + +console.log('Testing RSS feed:', testUrl); +console.log('---'); + +parser.parseURL(testUrl) + .then(feed => { + console.log('SUCCESS!'); + console.log('Title:', feed.title); + console.log('Description:', feed.description); + console.log('Items count:', feed.items?.length); + if (feed.items?.length > 0) { + console.log('\nFirst 3 items:'); + feed.items.slice(0, 3).forEach((item, i) => { + console.log(` ${i + 1}. ${item.title}`); + }); + } + }) + .catch(err => { + console.error('ERROR:', err.message); + console.error('Full error:', err); + });