INNER CODE UNIT · TypeScript
getPodcasts
freeCodeCamp/mobile · mobile-api/src/routes.ts:14
async function getPodcasts(req: Request, res: Response) {
const podcasts = await Podcast.find({});
if (feedUrls.length !== podcasts.length) {
console.log('Fetching missing podcasts');
for (const url of feedUrls) {
const feed = await parser.parseURL(url);
if (feed.title) {
console.log(`${feed.title} ${feed.items.length}`);
} else {
console.error(`title of ${url} missing ${feed.items.length}`);
}
await Podcast.findOneAndUpdate(
{ feedUrl: url },
{
title: feed.title,
description: feed.description,
feedUrl: url,