From 8e29ad8e41bea50457959249962b3cc36cbd14bd Mon Sep 17 00:00:00 2001 From: sebastjan Date: Sun, 30 Aug 2026 09:13:40 +0200 Subject: [PATCH] folx.tv: stari slugi izbrisanih rubrik se 301 preusmerijo na news.folx.tv (seznam slugov se bere z news API, predpomnjen 10 min) --- server/static.ts | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/server/static.ts b/server/static.ts index cf007bb..b65ab3e 100644 --- a/server/static.ts +++ b/server/static.ts @@ -103,6 +103,31 @@ const PUBLISHER = (base: string) => ({ const ONE_RUBRIKEN = new Set(["Politik", "Promis", "Sport", "Musik & Film", "Wetter", "Finanzen", "Aktuelles"]); +// 30. 8. 2026: rubrike so izbrisane iz baze folx.tv in zivijo samo se na +// news.folx.tv. Stare povezave s Facebooka in Googla morajo se vedno delati, +// zato ob neznanem slugu vprasamo news.folx.tv, ali ga pozna, in preusmerimo. +let NEWS_SLUGS: Set = new Set(); +let NEWS_SLUGS_AT = 0; +async function newsHasSlug(slug: string): Promise { + if (Date.now() - NEWS_SLUGS_AT > 600000) { + try { + const r = await fetch("https://news.folx.tv/api/articles", { + headers: { "user-agent": "folx.tv-redirect" }, + signal: AbortSignal.timeout(10000), + }); + const j: any = await r.json(); + if (Array.isArray(j) && j.length) { + NEWS_SLUGS = new Set(j.map((a: any) => String(a.slug))); + NEWS_SLUGS_AT = Date.now(); + } + } catch (e) { + NEWS_SLUGS_AT = Date.now() - 540000; // ob napaki poskusi cez minuto + } + } + return NEWS_SLUGS.has(slug); +} + + function setRobots(html: string, content: string): string { const tag = ``; if (/]*>/i.test(html)) { @@ -420,6 +445,10 @@ export function serveStatic(app: Express) { res.redirect(301, `${NEWS_HOST}/${article.slug}`); return; } + if (!article && (await newsHasSlug(slug))) { + res.redirect(301, `${NEWS_HOST}/${slug}`); + return; + } if (article && (article as any).targetUrl) { res.redirect(302, (article as any).targetUrl); return;