mirror of
https://github.com/R0m1k3/podcastic.git
synced 2026-10-11 17:26:20 +02:00
Corrige TypeError dans subscribeFromDiscovery
result.podcast est un plain object (toJSON()), appeler .toJSON() dessus crashe. Fix: refetch le podcast depuis MongoDB après création pour avoir un vrai Document Mongoose. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
1 parent
84c5cd6363
commit
eb6821ca76
1 file changed
+5
-5
@@ -197,7 +197,7 @@ export const subscribeFromDiscovery = async (req: Request, res: Response) => {
|
|||||||
// Check if podcast already in database
|
// Check if podcast already in database
|
||||||
let podcast = await Podcast.findOne({ rssUrl });
|
let podcast = await Podcast.findOne({ rssUrl });
|
||||||
|
|
||||||
// If not in database, try to fetch and create it
|
// If not in database, create it from RSS
|
||||||
if (!podcast) {
|
if (!podcast) {
|
||||||
try {
|
try {
|
||||||
const result = await rssParserService.createPodcastFromRss(rssUrl, {
|
const result = await rssParserService.createPodcastFromRss(rssUrl, {
|
||||||
@@ -207,21 +207,21 @@ export const subscribeFromDiscovery = async (req: Request, res: Response) => {
|
|||||||
imageUrl: imageUrl,
|
imageUrl: imageUrl,
|
||||||
episodes: [],
|
episodes: [],
|
||||||
});
|
});
|
||||||
podcast = result.podcast;
|
// Refetch as a proper Mongoose document (result.podcast is a plain object)
|
||||||
|
podcast = await Podcast.findById(result.podcast._id);
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
// If podcast creation fails, create minimal entry
|
|
||||||
if (error.message.includes('already in database')) {
|
if (error.message.includes('already in database')) {
|
||||||
podcast = await Podcast.findOne({ rssUrl });
|
podcast = await Podcast.findOne({ rssUrl });
|
||||||
} else {
|
} else {
|
||||||
return res.status(400).json({
|
return res.status(400).json({
|
||||||
message: `Failed to fetch podcast: ${error.message}`,
|
message: `Impossible de récupérer le podcast : ${error.message}`,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!podcast) {
|
if (!podcast) {
|
||||||
return res.status(400).json({ message: 'Failed to add podcast' });
|
return res.status(400).json({ message: "Impossible d'ajouter le podcast" });
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if already subscribed
|
// Check if already subscribed
|
||||||
|
|||||||
Reference in new issue
Block a user