Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MIM-2094] Mim 2094 rss feeds #3041

Merged
merged 3 commits into from
Nov 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 14 additions & 10 deletions src/main/resources/lib/ssb/rss/news.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,12 @@ const dummyReq: Partial<XP.Request> = {
}

export function getRssItemsNews(): string | null {
const mainSubjects: SubjectItem[] = getMainSubjects(dummyReq as XP.Request)
const articles: Array<News> = getArticles(mainSubjects)
const statistics: Array<News> = getStatistics(mainSubjects)
const news: Array<News> = articles.concat(statistics)
const news: NewsItem[] = getNews()
const xml = `<?xml version="1.0" encoding="utf-8"?>
<rssitems count="${news.length}">
${news
.map(
(n: News) => `<rssitem>
(n: NewsItem) => `<rssitem>
<guid isPermalink="false">${n.guid}</guid>
<title>${xmlEscape(n.title)}</title>
<link>${n.link}</link>
Expand All @@ -40,13 +37,20 @@ export function getRssItemsNews(): string | null {
return xml
}

function getArticles(mainSubjects: SubjectItem[]): Array<News> {
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<News> = []
const news: Array<NewsItem> = []
mainSubjects.forEach((mainSubject) => {
const articles: Array<Content<Article>> = query({
start: 0,
Expand Down Expand Up @@ -89,12 +93,12 @@ function getArticles(mainSubjects: SubjectItem[]): Array<News> {
return news
}

function getStatistics(mainSubjects: SubjectItem[]): Array<News> {
function getStatistics(mainSubjects: SubjectItem[]): NewsItem[] {
const statregStatistics: Array<StatisticInListing> = fetchStatisticsWithReleaseToday()
const serverOffsetInMS: number = parseInt(app.config?.['serverOffsetInMs']) || 0
const timeZoneIso: string = getTimeZoneIso(serverOffsetInMS)

const statisticsNews: Array<News> = []
const statisticsNews: NewsItem[] = []
if (statregStatistics.length > 0) {
mainSubjects.forEach((mainSubject) => {
const statistics: Array<Content<Statistics & Statistic>> = query({
Expand Down Expand Up @@ -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
Expand Down
14 changes: 9 additions & 5 deletions src/main/resources/lib/ssb/rss/statkal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,7 @@ const dummyReq: Partial<XP.Request> = {
}

export function getRssItemsStatkal(): string | null {
const statisticVariants: ContentLight<ReleaseVariant>[] = 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
? `<?xml version="1.0" encoding="utf-8"?>
Expand Down Expand Up @@ -58,6 +54,14 @@ export function getRssItemsStatkal(): string | null {
return xml
}

export function getRssReleasesStatkal(): RssRelease[] {
const statisticVariants: ContentLight<ReleaseVariant>[] = 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<ReleaseVariant>[],
allMainSubjects: SubjectItem[]
Expand Down
10 changes: 10 additions & 0 deletions src/main/resources/services/rssNews/rssNews.ts
Original file line number Diff line number Diff line change
@@ -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',
}
}
5 changes: 5 additions & 0 deletions src/main/resources/services/rssNews/rssNews.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<service>
<allow>
<principal>role:system.everyone</principal>
</allow>
</service>
10 changes: 10 additions & 0 deletions src/main/resources/services/rssStatkal/rssStatkal.ts
Original file line number Diff line number Diff line change
@@ -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',
}
}
5 changes: 5 additions & 0 deletions src/main/resources/services/rssStatkal/rssStatkal.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<service>
<allow>
<principal>role:system.everyone</principal>
</allow>
</service>
Loading