Restored to '84d7de2da64f8f2fd1e2d64959817c64c8fb7c04'

Replit-Restored-To: 84d7de2da6
This commit is contained in:
sebastjanartic
2026-02-28 20:36:50 +00:00
parent 802282187e
commit c441cc1594
76 changed files with 4644 additions and 212 deletions
+103
View File
@@ -3,6 +3,7 @@ import { createServer, type Server } from "http";
import { storage } from "./storage";
import { insertArticleSchema } from "@shared/schema";
import { seedDatabase } from "./seed";
import { generateDailyHoroscopes, getHoroscopesForToday, getOrGenerateHoroscope } from "./horoscope-generator";
import multer from "multer";
import path from "path";
import fs from "fs";
@@ -37,6 +38,10 @@ export async function registerRoutes(
): Promise<Server> {
await seedDatabase();
generateDailyHoroscopes().catch((err) =>
console.error("Background horoscope generation failed:", err.message)
);
app.get("/api/articles", async (_req, res) => {
const articles = await storage.getArticles();
res.json(articles);
@@ -172,5 +177,103 @@ export async function registerRoutes(
}
});
// Gallery API - serves shuffled photos from Dropbox
app.get("/api/gallery", (_req, res) => {
try {
const galleryPath = path.join(process.cwd(), "server/gallery-data.json");
const data = JSON.parse(fs.readFileSync(galleryPath, "utf-8"));
// Shuffle using Fisher-Yates
const shuffled = [...data];
for (let i = shuffled.length - 1; i > 0; i--) {
const j = Math.floor(Math.random() * (i + 1));
[shuffled[i], shuffled[j]] = [shuffled[j], shuffled[i]];
}
res.json(shuffled);
} catch (err: any) {
res.json([]);
}
});
// Horoscope API
app.get("/api/horoscopes/today", async (_req, res) => {
try {
const horoscopes = await getHoroscopesForToday();
res.json(horoscopes);
} catch (err: any) {
res.status(500).json({ message: err.message });
}
});
app.get("/api/horoscopes/sign/:index", async (req, res) => {
try {
const signIndex = parseInt(req.params.index);
if (isNaN(signIndex) || signIndex < 0 || signIndex > 11) {
return res.status(400).json({ message: "Invalid sign index" });
}
const horoscope = await getOrGenerateHoroscope(signIndex);
res.json(horoscope);
} catch (err: any) {
res.status(500).json({ message: err.message });
}
});
app.post("/api/horoscopes/generate", async (_req, res) => {
try {
await generateDailyHoroscopes();
const horoscopes = await getHoroscopesForToday();
res.json({ generated: horoscopes.length, horoscopes });
} catch (err: any) {
res.status(500).json({ message: err.message });
}
});
// News feed - Volksmusik/Schlager news from Google News RSS
app.get("/api/news-feed", async (_req, res) => {
try {
const topics = ["Volksmusik", "Schlager+Musik", "Oberkrainer"];
const topic = topics[Math.floor(Date.now() / 3600000) % topics.length];
const rssUrl = `https://news.google.com/rss/search?q=${topic}&hl=de&gl=DE&ceid=DE:de`;
const response = await new Promise<string>((resolve, reject) => {
https.get(rssUrl, (resp) => {
let data = "";
resp.on("data", (chunk: Buffer) => (data += chunk.toString()));
resp.on("end", () => resolve(data));
resp.on("error", reject);
}).on("error", reject);
});
const items: { title: string; link: string; source: string; pubDate: string }[] = [];
const itemRegex = /<item>([\s\S]*?)<\/item>/g;
let match;
while ((match = itemRegex.exec(response)) !== null && items.length < 10) {
const block = match[1];
const title = block.match(/<title>(.*?)<\/title>/)?.[1]?.replace(/<!\[CDATA\[|\]\]>/g, "") || "";
const link = block.match(/<link>(.*?)<\/link>/)?.[1] || "";
const source = block.match(/<source[^>]*>(.*?)<\/source>/)?.[1]?.replace(/<!\[CDATA\[|\]\]>/g, "") || "";
const pubDateRaw = block.match(/<pubDate>(.*?)<\/pubDate>/)?.[1] || "";
let pubDate = "";
try {
const d = new Date(pubDateRaw);
const diffH = Math.floor((Date.now() - d.getTime()) / 3600000);
if (diffH < 1) pubDate = "Gerade eben";
else if (diffH < 24) pubDate = `vor ${diffH} Std.`;
else pubDate = `vor ${Math.floor(diffH / 24)} T.`;
} catch {
pubDate = "";
}
if (title && link) {
items.push({ title, link, source, pubDate });
}
}
res.json(items);
} catch (err: any) {
res.json([]);
}
});
return httpServer;
}