From a6a99c465d4af6c40900a3faf54b77624b6d5e4c Mon Sep 17 00:00:00 2001 From: Anna Murphy Date: Fri, 12 Apr 2024 17:12:47 -0400 Subject: [PATCH] fix the rss feeds --- .../src/api/routes/capesInTheWestMarch.ts | 1 + functions/src/utils/firestore.ts | 12 ++++++------ functions/src/utils/makeRss.ts | 18 ++++++++++++------ 3 files changed, 19 insertions(+), 12 deletions(-) diff --git a/functions/src/api/routes/capesInTheWestMarch.ts b/functions/src/api/routes/capesInTheWestMarch.ts index d4ab8a0..92de2a9 100644 --- a/functions/src/api/routes/capesInTheWestMarch.ts +++ b/functions/src/api/routes/capesInTheWestMarch.ts @@ -8,6 +8,7 @@ export const citwmFeed: Route = { handler: async function (_req: Request, res: Response) { try { const rssFeed = await getMostRecentRss("Capes in the West March"); + res.setHeader("content-type", "application/rss+xml "); res.status(200).send(rssFeed.rss); } catch (ex) { res.sendStatus(404); diff --git a/functions/src/utils/firestore.ts b/functions/src/utils/firestore.ts index 7398780..e5eefcd 100644 --- a/functions/src/utils/firestore.ts +++ b/functions/src/utils/firestore.ts @@ -1,9 +1,10 @@ import { initializeApp } from "firebase-admin"; -import { DocumentSnapshot, Timestamp, getFirestore } from "firebase-admin/firestore"; import { - Change, - FirestoreEvent, -} from "firebase-functions/v2/firestore"; + DocumentSnapshot, + Timestamp, + getFirestore, +} from "firebase-admin/firestore"; +import { Change, FirestoreEvent } from "firebase-functions/v2/firestore"; import { PodcastChannel, PodcastEpisode, RssDocument } from "./types"; initializeApp(); @@ -71,10 +72,9 @@ export function getDataFromEvent( event: FirestoreEvent | undefined>, ) { if (event === undefined) return null; - const eventData = event.data;//event.data.after.data(); + const eventData = event.data; //event.data.after.data(); if (eventData === undefined) return null; const afterData = eventData.after.data(); if (afterData === undefined) return null; return afterData as T; } - diff --git a/functions/src/utils/makeRss.ts b/functions/src/utils/makeRss.ts index 7d2dc86..56d09ac 100644 --- a/functions/src/utils/makeRss.ts +++ b/functions/src/utils/makeRss.ts @@ -1,8 +1,11 @@ import { Timestamp } from "firebase-admin/firestore"; import { PodcastChannel, PodcastEpisode } from "./types"; +//import { JSDOM } from "jsdom"; +//import { logger } from "firebase-functions/v1"; export function makeRss(feed: PodcastChannel, episodes: PodcastEpisode[]) { - return ` + // xmlns:googleplay="http://www.google.com/schemas/play-podcasts/1.0" + const rssString = ` ${makeChannel(feed, episodes.map((episode) => makeItem(episode)).join(""))} `; + //const a = new JSDOM(rssString, { contentType: "text/xml" }); + //return a.serialize(); + //logger.info(a.serialize); + return rssString; } function makeChannel(channel: PodcastChannel, items: string) { @@ -38,9 +44,9 @@ function makeChannel(channel: PodcastChannel, items: string) { ${channel.contact.site} ${channel.metadata.locked} - ${channel.metadata.complete} ${items} - `; + `; + // ${channel.metadata.complete} } function formatCategories( @@ -62,7 +68,7 @@ function formatCategories( function makeItem(episodeData: PodcastEpisode) { return ` ${episodeData.title} - ${episodeData.fileData.url} + ${new Timestamp(episodeData.publishDate.seconds, episodeData.publishDate.nanoseconds).toDate().toUTCString()} @@ -71,7 +77,7 @@ function makeItem(episodeData: PodcastEpisode) { ${episodeData.metadata.season} ${episodeData.metadata.episode} ${episodeData.metadata.type || "full"} - + `; } /*