diff --git a/src/main/resources/lib/ssb/rss/news.ts b/src/main/resources/lib/ssb/rss/news.ts index 05a77646c..f221cb130 100644 --- a/src/main/resources/lib/ssb/rss/news.ts +++ b/src/main/resources/lib/ssb/rss/news.ts @@ -15,15 +15,12 @@ const dummyReq: Partial = { } export function getRssItemsNews(): string | null { - const mainSubjects: SubjectItem[] = getMainSubjects(dummyReq as XP.Request) - const articles: Array = getArticles(mainSubjects) - const statistics: Array = getStatistics(mainSubjects) - const news: Array = articles.concat(statistics) + const news: NewsItem[] = getNews() const xml = ` ${news .map( - (n: News) => ` + (n: NewsItem) => ` ${n.guid} ${xmlEscape(n.title)} ${n.link} @@ -40,13 +37,20 @@ export function getRssItemsNews(): string | null { return xml } -function getArticles(mainSubjects: SubjectItem[]): Array { +export function getNews(): NewsItem[] { + const mainSubjects: SubjectItem[] = getMainSubjects(dummyReq as XP.Request) + const articles: NewsItem[] = getArticles(mainSubjects) + const statistics: NewsItem[] = getStatistics(mainSubjects) + return articles.concat(statistics) +} + +function getArticles(mainSubjects: SubjectItem[]): NewsItem[] { const from: string = subDays(new Date(), 1).toISOString() const to: string = new Date().toISOString() const serverOffsetInMilliSeconds: number = parseInt(app.config?.['serverOffsetInMs']) || 0 const timeZoneIso: string = getTimeZoneIso(serverOffsetInMilliSeconds) - const news: Array = [] + const news: Array = [] mainSubjects.forEach((mainSubject) => { const articles: Array> = query({ start: 0, @@ -89,12 +93,12 @@ function getArticles(mainSubjects: SubjectItem[]): Array { return news } -function getStatistics(mainSubjects: SubjectItem[]): Array { +function getStatistics(mainSubjects: SubjectItem[]): NewsItem[] { const statregStatistics: Array = fetchStatisticsWithReleaseToday() const serverOffsetInMS: number = parseInt(app.config?.['serverOffsetInMs']) || 0 const timeZoneIso: string = getTimeZoneIso(serverOffsetInMS) - const statisticsNews: Array = [] + const statisticsNews: NewsItem[] = [] if (statregStatistics.length > 0) { mainSubjects.forEach((mainSubject) => { const statistics: Array> = query({ @@ -163,7 +167,7 @@ function getLinkByPath(path: string) { return baseUrl + path.substring(site.length) } -interface News { +interface NewsItem { guid: string // _id title: string // displayName link: string // url diff --git a/src/main/resources/lib/ssb/rss/statkal.ts b/src/main/resources/lib/ssb/rss/statkal.ts index 670ff2213..52d1409b7 100644 --- a/src/main/resources/lib/ssb/rss/statkal.ts +++ b/src/main/resources/lib/ssb/rss/statkal.ts @@ -20,11 +20,7 @@ const dummyReq: Partial = { } export function getRssItemsStatkal(): string | null { - const statisticVariants: ContentLight[] = getUpcompingStatisticVariantsFromRepo() - const allMainSubjects: SubjectItem[] = getMainSubjects(dummyReq as XP.Request) - const upcomingVariants: StatkalVariant[] = getUpcomingVariants(statisticVariants, allMainSubjects) - const upcomingReleases: StatkalRelease[] = getUpcomingReleases(statisticVariants) - const rssReleases: RssRelease[] = getRssReleases(upcomingVariants, upcomingReleases) + const rssReleases: RssRelease[] = getRssReleasesStatkal() const xml = rssReleases ? ` @@ -58,6 +54,14 @@ export function getRssItemsStatkal(): string | null { return xml } +export function getRssReleasesStatkal(): RssRelease[] { + const statisticVariants: ContentLight[] = getUpcompingStatisticVariantsFromRepo() + const allMainSubjects: SubjectItem[] = getMainSubjects(dummyReq as XP.Request) + const upcomingVariants: StatkalVariant[] = getUpcomingVariants(statisticVariants, allMainSubjects) + const upcomingReleases: StatkalRelease[] = getUpcomingReleases(statisticVariants) + return getRssReleases(upcomingVariants, upcomingReleases) +} + function getUpcomingVariants( statisticVariants: ContentLight[], allMainSubjects: SubjectItem[] diff --git a/src/main/resources/services/rssNews/rssNews.ts b/src/main/resources/services/rssNews/rssNews.ts new file mode 100644 index 000000000..91498ed99 --- /dev/null +++ b/src/main/resources/services/rssNews/rssNews.ts @@ -0,0 +1,10 @@ +import { getNews, getRssItemsNews } from '/lib/ssb/rss/news' + +export function get(req: XP.Request): XP.Response { + const format: string = req.params.format ?? 'json' + const isXml = format === 'xml' + return { + body: isXml ? getRssItemsNews() : getNews(), + contentType: isXml ? 'text/xml' : 'application/json', + } +} diff --git a/src/main/resources/services/rssNews/rssNews.xml b/src/main/resources/services/rssNews/rssNews.xml new file mode 100644 index 000000000..d18703052 --- /dev/null +++ b/src/main/resources/services/rssNews/rssNews.xml @@ -0,0 +1,5 @@ + + + role:system.everyone + + diff --git a/src/main/resources/services/rssStatkal/rssStatkal.ts b/src/main/resources/services/rssStatkal/rssStatkal.ts new file mode 100644 index 000000000..1c8c01fc4 --- /dev/null +++ b/src/main/resources/services/rssStatkal/rssStatkal.ts @@ -0,0 +1,10 @@ +import { getRssReleasesStatkal, getRssItemsStatkal } from '/lib/ssb/rss/statkal' + +export function get(req: XP.Request): XP.Response { + const format: string = req.params.format ?? 'json' + const isXml = format === 'xml' + return { + body: isXml ? getRssItemsStatkal() : getRssReleasesStatkal(), + contentType: isXml ? 'text/xml' : 'application/json', + } +} diff --git a/src/main/resources/services/rssStatkal/rssStatkal.xml b/src/main/resources/services/rssStatkal/rssStatkal.xml new file mode 100644 index 000000000..d18703052 --- /dev/null +++ b/src/main/resources/services/rssStatkal/rssStatkal.xml @@ -0,0 +1,5 @@ + + + role:system.everyone + +