blok Aktuelle Nachrichten bere news.folx.tv namesto tagesschau, n-tv, ORF in Welt: promet ostane pri nas

This commit is contained in:
2026-08-31 11:58:53 +02:00
parent 91e84e05fe
commit ccc0b6b3c5
+22 -23
View File
@@ -1060,34 +1060,33 @@ export async function registerRoutes(
});
app.get("/api/breaking-news", async (_req, res) => {
// 31. 8. 2026: blok Aktuelle Nachrichten je vodil na tagesschau, n-tv, ORF
// in Welt, torej smo obiskovalce posiljali s strani. Zdaj kaze nase novice
// z news.folx.tv, kjer imamo oglase.
const cacheKey = "breaking-news";
const cached = getCached<any[]>(cacheKey, 15 * 60 * 1000);
const cached = getCached<any[]>(cacheKey, 5 * 60 * 1000);
if (cached) return res.json(cached);
try {
const newsFeeds = [
"https://www.tagesschau.de/xml/rss2_https/",
"https://www.n-tv.de/rss",
"https://rss.orf.at/oesterreich.xml",
"https://www.welt.de/feeds/latest.rss",
];
let allItems: { title: string; link: string; source: string; pubDate: string }[] = [];
const results = await Promise.allSettled(
newsFeeds.map(async (url) => {
try {
const xml = await fetchRssFeed(url);
return parseRssItems(xml, 1);
} catch { return []; }
})
);
for (const r of results) {
if (r.status === "fulfilled") allItems.push(...r.value);
}
allItems = allItems.slice(0, 10);
if (allItems.length > 0) setCache(cacheKey, allItems);
res.json(allItems);
const r = await fetch("https://news.folx.tv/api/articles", {
headers: { "user-agent": "folx.tv-widget" },
signal: AbortSignal.timeout(10000),
});
const arts: any[] = await r.json();
const items = (Array.isArray(arts) ? arts : [])
.filter((a) => a && a.slug && a.title)
.sort((a, b) => String(b.publishedAt || "").localeCompare(String(a.publishedAt || "")))
.slice(0, 12)
.map((a) => ({
title: String(a.title),
link: `https://news.folx.tv/${a.slug}`,
source: String(a.category || "FOLX NEWS"),
pubDate: String(a.publishedAt || ""),
}));
if (items.length > 0) setCache(cacheKey, items);
res.json(items);
} catch (err: any) {
console.log("[breaking-news] RSS fetch error:", err.message);
console.log("[breaking-news] news.folx.tv error:", err.message);
const stale = getStale<any[]>(cacheKey);
res.json(stale || []);
}