From 3914f28e19e90ae5e689b5601e380b4dc5dfb743 Mon Sep 17 00:00:00 2001 From: R0m1k3 Date: Thu, 16 Apr 2026 11:24:44 +0200 Subject: [PATCH] Corrige subscribe 500 et trending 500 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 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 --- backend/src/controllers/podcastController.ts | 27 +++++------------ backend/src/services/podcastIndexService.ts | 32 ++++++++++++-------- 2 files changed, 26 insertions(+), 33 deletions(-) diff --git a/backend/src/controllers/podcastController.ts b/backend/src/controllers/podcastController.ts index 4148220..d8f7b6f 100644 --- a/backend/src/controllers/podcastController.ts +++ b/backend/src/controllers/podcastController.ts @@ -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 }); } }; diff --git a/backend/src/services/podcastIndexService.ts b/backend/src/services/podcastIndexService.ts index 3b27029..745e033 100644 --- a/backend/src/services/podcastIndexService.ts +++ b/backend/src/services/podcastIndexService.ts @@ -78,23 +78,29 @@ export const podcastIndexService = { }, getTrendingPodcasts: async (limit: number = 20): Promise => { - // 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( 'https://itunes.apple.com/lookup', - { - params: { id: ids, entity: 'podcast' }, - timeout: 10000, - } + { params: { id: ids, entity: 'podcast' }, timeout: 10000 } ); return lookupResponse.data.results