mirror of
https://github.com/R0m1k3/noteflow.git
synced 2026-10-23 15:18:16 +02:00
Merge pull request #165 from R0m1k3/antigravity
feat: Add script to test RSS feed parsing with custom User-Agent.
This commit is contained in:
2 files changed
+69
-1
No files matched your search
+36
-1
@@ -51,7 +51,42 @@ router.post('/feeds', requireAdmin, async (req, res) => {
|
|||||||
|
|
||||||
// Tester le flux
|
// Tester le flux
|
||||||
try {
|
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}"`);
|
logger.info(`[CREATE RSS FEED] Ajout flux - url: "${url}", title: "${feed.title || url}"`);
|
||||||
|
|
||||||
|
|||||||
@@ -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);
|
||||||
|
});
|
||||||
Reference in new issue
Block a user