blok Aktuelle Nachrichten bere news.folx.tv namesto tagesschau, n-tv, ORF in Welt: promet ostane pri nas
This commit is contained in:
+22
-23
@@ -1060,34 +1060,33 @@ export async function registerRoutes(
|
|||||||
});
|
});
|
||||||
|
|
||||||
app.get("/api/breaking-news", async (_req, res) => {
|
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 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);
|
if (cached) return res.json(cached);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const newsFeeds = [
|
const r = await fetch("https://news.folx.tv/api/articles", {
|
||||||
"https://www.tagesschau.de/xml/rss2_https/",
|
headers: { "user-agent": "folx.tv-widget" },
|
||||||
"https://www.n-tv.de/rss",
|
signal: AbortSignal.timeout(10000),
|
||||||
"https://rss.orf.at/oesterreich.xml",
|
});
|
||||||
"https://www.welt.de/feeds/latest.rss",
|
const arts: any[] = await r.json();
|
||||||
];
|
const items = (Array.isArray(arts) ? arts : [])
|
||||||
let allItems: { title: string; link: string; source: string; pubDate: string }[] = [];
|
.filter((a) => a && a.slug && a.title)
|
||||||
const results = await Promise.allSettled(
|
.sort((a, b) => String(b.publishedAt || "").localeCompare(String(a.publishedAt || "")))
|
||||||
newsFeeds.map(async (url) => {
|
.slice(0, 12)
|
||||||
try {
|
.map((a) => ({
|
||||||
const xml = await fetchRssFeed(url);
|
title: String(a.title),
|
||||||
return parseRssItems(xml, 1);
|
link: `https://news.folx.tv/${a.slug}`,
|
||||||
} catch { return []; }
|
source: String(a.category || "FOLX NEWS"),
|
||||||
})
|
pubDate: String(a.publishedAt || ""),
|
||||||
);
|
}));
|
||||||
for (const r of results) {
|
if (items.length > 0) setCache(cacheKey, items);
|
||||||
if (r.status === "fulfilled") allItems.push(...r.value);
|
res.json(items);
|
||||||
}
|
|
||||||
allItems = allItems.slice(0, 10);
|
|
||||||
if (allItems.length > 0) setCache(cacheKey, allItems);
|
|
||||||
res.json(allItems);
|
|
||||||
} catch (err: any) {
|
} 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);
|
const stale = getStale<any[]>(cacheKey);
|
||||||
res.json(stale || []);
|
res.json(stale || []);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user