Corrige subscribe 500 et trending 500

- subscribe: passe undefined à createPodcastFromRss pour qu'il parse vraiment le flux RSS (bug: on passait feedData avec episodes:[] vide)
- trending/discover: retournent [] au lieu de 500 si l'API iTunes échoue
- trending: utilise l'iTunes RSS officiel (itunes.apple.com/fr/rss/toppodcasts) au lieu de l'API Marketing Tools instable

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
MichaelandClaude Sonnet 4.6 committed 2026-04-16 11:24:44 +02:00
1 parent 59144e9ce6
commit 3914f28e19
2 files changed
+26 -33

No files matched your search

+7 -20
View File
@@ -50,14 +50,8 @@ export const subscribe = async (req: Request, res: Response) => {
if (!podcast) {
try {
const result = await rssParserService.createPodcastFromRss(rssUrl, {
title: 'Unknown Podcast',
description: '',
author: '',
imageUrl: undefined,
episodes: [],
});
podcast = result.podcast;
const result = await rssParserService.createPodcastFromRss(rssUrl);
podcast = await Podcast.findById(result.podcast._id);
} catch (error: any) {
if (error.message.includes('already in database')) {
podcast = await Podcast.findOne({ rssUrl });
@@ -70,7 +64,7 @@ export const subscribe = async (req: Request, res: Response) => {
}
if (!podcast) {
return res.status(400).json({ message: 'Impossible d\'ajouter le podcast' });
return res.status(400).json({ message: "Impossible d'ajouter le podcast" });
}
// Check if already subscribed
@@ -184,9 +178,7 @@ export const discoverPodcasts = async (req: Request, res: Response) => {
});
} catch (error: any) {
console.error('Discover podcasts error:', error.message);
res.status(error.status || 500).json({
message: error.message || 'Recherche échouée',
});
res.json({ source: 'itunes', podcasts: [], count: 0 });
}
};
@@ -263,16 +255,11 @@ export const subscribeFromDiscovery = async (req: Request, res: Response) => {
export const getTrendingPodcasts = async (req: Request, res: Response) => {
try {
const limit = Number(req.query.limit) || 20;
const trending = await podcastIndexService.getTrendingPodcasts(limit);
res.json({
source: 'itunes',
podcasts: trending,
count: trending.length,
});
res.json({ source: 'itunes', podcasts: trending, count: trending.length });
} catch (error: any) {
console.error('Trending podcasts error:', error.message);
res.status(500).json({ message: 'Impossible de récupérer les tendances' });
// Return empty rather than crashing the page
res.json({ source: 'itunes', podcasts: [], count: 0 });
}
};
+19 -13
View File
@@ -78,23 +78,29 @@ export const podcastIndexService = {
},
getTrendingPodcasts: async (limit: number = 20): Promise<SearchResult[]> => {
// Get Apple's top podcasts list
const topResponse = await axios.get<{ feed: { results: ItunesTopResult[] } }>(
`https://rss.applemarketingtools.com/api/v2/fr/podcasts/top-podcasts/${Math.min(limit, 50)}/podcasts.json`,
{ timeout: 10000 }
);
// iTunes official top podcasts RSS (France)
const cap = Math.min(limit, 50);
const rssResponse = await axios.get<{
feed: {
entry: Array<{
id: { label: string; attributes: { 'im:id': string } };
'im:name': { label: string };
'im:artist': { label: string };
'im:image': Array<{ label: string; attributes: { height: string } }>;
}>;
};
}>(`https://itunes.apple.com/fr/rss/toppodcasts/limit=${cap}/json`, {
timeout: 10000,
});
const topItems = topResponse.data.feed.results;
if (!topItems || topItems.length === 0) return [];
const entries = rssResponse.data.feed.entry;
if (!entries || entries.length === 0) return [];
// Batch lookup to get RSS URLs
const ids = topItems.map((item) => item.id).join(',');
// Batch lookup to get feedUrls
const ids = entries.map((e) => e.id.attributes['im:id']).join(',');
const lookupResponse = await axios.get<ItunesSearchResponse>(
'https://itunes.apple.com/lookup',
{
params: { id: ids, entity: 'podcast' },
timeout: 10000,
}
{ params: { id: ids, entity: 'podcast' }, timeout: 10000 }
);
return lookupResponse.data.results