Skip to content

Commit 5afc7b0

Browse files
committed
update
1 parent c1981ce commit 5afc7b0

File tree

2 files changed

+36
-37
lines changed

2 files changed

+36
-37
lines changed

Diff for: README.md

+9-2
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,16 @@ Two server implementations are available:
2222
## Run locally
2323

2424
```
25-
node server.js
25+
node server.js OR serveraxios.js
2626
or
27-
npm start
27+
// change script--start in package.json for start only for serveraxios.js
28+
npm start
29+
npm run start:axios
30+
31+
bun start
32+
bun start:axios
33+
// change script--start in package.json for using start only for serveraxios.js
34+
2835
```
2936

3037
## Request Usage

Diff for: rss.js

+27-35
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,11 @@ function fetchUrl(url, callback) {
3333
});
3434
}
3535

36+
// Modification 1: dans la fonction cleanXML
3637
function cleanXML(xml) {
37-
// On utilise le 'match' pour avoir accès au tag complet pour le debugging si nécessaire
38-
console.log('Cleaning XML...');
39-
return xml.replace(/<(\/?)itunes:([^>]+)>/g, function(match, slash, rest) {
40-
console.log('Found iTunes tag:', match);
41-
const cleaned = '<' + slash + rest + '>';
42-
console.log('Cleaned to:', cleaned);
43-
return cleaned;
44-
});
38+
let cleanedXml = xml;
39+
cleanedXml = cleanedXml.replace(/<(\/?)(dc|itunes):([^>]+)>/g, '<$1$3>');
40+
return cleanedXml;
4541
}
4642

4743
function extractImageFromDescription(description) {
@@ -113,25 +109,27 @@ module.exports = {
113109
throw new Error('Invalid RSS format');
114110
}
115111

116-
const rss = { item: [] };
112+
const feed = {};
113+
const response = { status: 'ok', feed: feed, items: [] };
117114

118115
// Gestion enrichie des images principales
119116
const mainimage = list.image?.[0]?.href?.[0] ||
120117
list.image?.[0]?.url?.[0] ||
121118
list['media:thumbnail']?.[0]?.url?.[0];
122119

123120
if (mainimage) {
124-
rss.image = { href: mainimage };
121+
feed.image = mainimage;
125122
}
126123

127124
// Informations de base du channel
128-
rss.title = list.title?.[0] || '';
129-
rss.description = list.description?.[0] || '';
130-
rss.url = list.link?.[0] || '';
131-
rss.author = list.author?.[0] || '';
132-
rss.playlistURL = list.link?.[0] || '';
133-
rss.language = list.language?.[0] || '';
134-
rss.lastBuildDate = list.lastBuildDate?.[0] || '';
125+
feed.title = list.title?.[0] || '';
126+
feed.description = list.description?.[0] || '';
127+
feed.link = list.link?.[0] || '';
128+
feed.url = feed.link; // Garder url comme alias de link
129+
feed.author = list.author?.[0] || '';
130+
feed.playlistURL = list.link?.[0] || '';
131+
feed.language = list.language?.[0] || '';
132+
feed.lastBuildDate = list.lastBuildDate?.[0] || '';
135133

136134
const parsedItems = [];
137135
if (list.item) {
@@ -145,7 +143,7 @@ module.exports = {
145143
title: val.title?.[0] || '',
146144
description: val.description?.[0] || '',
147145
group: val.category?.[0] || '',
148-
author: val.author?.[0] || list.author?.[0] || '',
146+
author: val.creator?.[0] || val.author?.[0] || list.author?.[0] || '', // Notez l'ordre : creator en premier
149147
pubDate: val.pubDate?.[0] || ''
150148
};
151149

@@ -164,7 +162,7 @@ module.exports = {
164162
}
165163

166164
// Gestion enrichie des images (comme dans votre PHP)
167-
obj.thumb_square =
165+
obj.thumbnail =
168166
val.image?.[0]?.href?.[0] || // Direct image
169167
val['media:thumbnail']?.[0]?.url?.[0] || // Media thumbnail
170168
val['media:content']?.[0]?.['media:thumbnail']?.[0]?.url?.[0] || // Nested media thumbnail
@@ -180,30 +178,24 @@ module.exports = {
180178
});
181179
}
182180

183-
return {
184-
title: rss.title,
185-
description: rss.description,
186-
url: rss.url,
187-
author: rss.author,
188-
image: rss.image,
189-
language: rss.language,
190-
lastBuildDate: rss.lastBuildDate,
191-
item: parsedItems
192-
};
181+
response.items = parsedItems;
182+
return response;
183+
193184
},
194185

195186
parseAtom: function(json) {
196187
const feed = json.feed;
197-
const rss = { item: [] };
188+
const response = { status: 'ok', feed: {}, items: [] };
198189

199190
if (feed.title) {
200-
rss.title = feed.title[0];
191+
response.feed.title = feed.title[0];
201192
}
202193
if (feed.subtitle) {
203-
rss.description = feed.subtitle[0];
194+
response.feed.description = feed.subtitle[0];
204195
}
205196
if (feed.link) {
206-
rss.url = feed.link[0].href || feed.link[0];
197+
response.feed.link = feed.link[0].href || feed.link[0];
198+
response.feed.url = response.feed.link;
207199
}
208200

209201
if (feed.entry) {
@@ -228,11 +220,11 @@ module.exports = {
228220
}
229221

230222
console.log('Parsed Atom entry:', obj);
231-
rss.item.push(obj);
223+
response.items.push(obj);
232224
});
233225
}
234226

235-
return rss;
227+
return response;
236228
},
237229

238230
read: function(url, callback) {

0 commit comments

Comments
 (0)