Improve photo gallery with artist names and infinite scrolling

Refactor photo gallery to include artist names extracted from filenames, implement pagination with infinite scrolling, and optimize image loading.

Replit-Commit-Author: Agent
Replit-Commit-Session-Id: 517dfa7b-26ac-463d-a6e1-a58c6df97188
Replit-Commit-Checkpoint-Type: full_checkpoint
Replit-Commit-Event-Id: 79e0a082-1752-4a36-8483-997b7269c4f3
Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/f209e72a-0939-48fa-84fc-57854de71967/517dfa7b-26ac-463d-a6e1-a58c6df97188/nFw7xof
Replit-Helium-Checkpoint-Created: true
This commit is contained in:
sebastjanartic
2026-03-02 16:39:45 +00:00
parent 553d20d8cb
commit 4b5b3e5d97
8 changed files with 892 additions and 639 deletions
+2 -2
View File
@@ -1,7 +1,7 @@
{
"access_token": "sl.u.AGVAMk1isWjEfoERFxA5-4d0aQJgK5q3BvH4nQq7XKhUIV2q4YDpbYok3TQf7z2fF7ZBDZQJ2of2rnz4vzrfnkTrgRIirNckfsMkSfZvAXF8E2VK3fLrtXs5uy3g-A7CibB2I_TFehxQgiGJh77788vCDnGuwt-rYLSEm238-SS9OiDWUXNPvESABp2LHwJmKOnZg_Z6I9b6fy-BnppE_IOMPDkIhxy8T3a98-jgZGlR7SKEOPbAv5O9cQsmSi9hfh3pV53IV6lhfSpvPFXCxUCIUB990Cga1Cv70JlNSWpcB4pY_5mV-03ncRhxSBe-DjFAwY8DQskIsFyS5bcNloqk-nei3LxAXlk-PqTEpCMGcIjM5sVCazBPh1m3u169M5v_qV598nxc7S7uZcVT2jvT01bLIN9HqOvF3fpYeEY0v2ORQNMzr8AuZEGmpJbIkT0zpXSNatgVPzOtvmdTjoxfb0wjMjM1VEjGgX1v6UHVxLnyvSyvW7UZ2QNo4wmqOJQnq32l5sBFukHDImPDW3nKoATHJcn6dLLk0sjbl3-8UH9sZpezOxJIGmcla34DFbt2n_NymArdSA-m7ywGHqdR8Eqr-scWQi14WKcaHXnCQF_R_puhKiTdzcW4UFb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3yhqs88pAuarw2ug-uzqVdIdcYuygs_MYotBnasD2HvT6qpm0Ixrj3l9ApgYlyd9czfgGoG4eZ_LPK_0VVX_FuqHPC-pbImwrFDrjsMn_kbSynoaGXhFf2IB6vfhMTa3isuOol8oXIT_ScM3dzKMoCC6wzZEihwPhb2BCcl_jIO1YXcXuPU-dDqvSj1f6dx9os8ycH3m-dnKGLt9U-li64ybET_kXUjkdxZqrMJAQcvmSz1h1aGm7ObdELzgtifU3UD8z_R3OWg3KGY5wjBbxv1599NwqxwyD3uW77JRiiuGZ95cTRZQ9gRSaVSeir01D1_yz7CV7DpZvKmgiKAOGuNcfOXLnaJiGubK-797Qz4zblBxFeGjskN85MsxM5_oiRylNpqR0lI29XwQjRKbPl6n7kL7ibrrV9z2xnDyXxhY7wLpQKXUr7Sfja3QOUjBaenYILksKp_W1SMPtOER8hdDOsoKOXuQs4pC30zu0KmI7Aqss9X-jrA13QSy5vhBvxNlLVq2WK9VeSJZWb85qoMATFcenM0UbCa4Of34pF0fMPdGMdX98akKuUSLOy_2vPBuFHNFrARe3aDMYN_PXR1lDlcFjXXriMQT-xHF93MRav-A05TUXlxFpSeNkkc0Fu04RqLqPK9eZrjEj4ddnVRJxbGimlzeHcSNRAgN2vjWnOaIyB8swP5AimCvcQZznwNNyUv9lSED2-1qW-ueyykL8HGvg9oWjoqb9Lr6CiQvNnM0OMPS1V5LDEbRGKm3iOC4Ldcl2zxT8zJk7GBQJmW-OPz6-kKT_6et70dxeYRL71-fBL0ECOzefp1yFjNB7zDQ_n1SssAg7C7WIU7ftpZg6d3nyhOmewNGpKkCldL5B858vkiGrJQLd2mXOzrT3BLFss0rgl46w9EYGmbz0r6Nw0b7gzyYxKVE2uB5Q",
"refresh_token": "8-fiK0Io8Z8AAAAAAAAAAXn1QIGTwFTVWKF47COXY2bjqYlWyd4aRnFtQJ7usZ0y",
"expires_at": 1772403823104,
"expires_at": 1772474222442,
"app_key": "sjwprgka82p8tpv",
"app_secret": "g3vuczqo0rx3crz"
}
+12
View File
@@ -18,6 +18,17 @@ interface GalleryImage {
thumb: string;
large: string;
full: string;
artist: string;
}
function extractArtistFromFileName(fileName: string): string {
if (/^DSC\d/i.test(fileName) || /^IMG[\s_]\d/i.test(fileName)) return "";
const withoutExt = fileName.replace(/\.\w+$/, "");
const cleaned = withoutExt
.replace(/\s*\(\d+\)\s*$/, "")
.replace(/\s*\d+\s*$/, "")
.replace(/\s*\(\d+\)\s*$/, "");
return cleaned.trim();
}
function getAppKey(): string {
@@ -237,6 +248,7 @@ export async function fetchGalleryFromDropbox(): Promise<GalleryImage[]> {
thumb: link,
large: link,
full: link,
artist: extractArtistFromFileName(file.name),
});
}
}
+715 -539
View File
File diff suppressed because it is too large Load Diff
+75 -76
View File
@@ -12,6 +12,20 @@ import path from "path";
import fs from "fs";
import https from "https";
const apiCache = new Map<string, { data: any; timestamp: number }>();
function getCached<T>(key: string, ttlMs: number): T | null {
const entry = apiCache.get(key);
if (entry && Date.now() - entry.timestamp < ttlMs) return entry.data as T;
return null;
}
function setCache(key: string, data: any) {
apiCache.set(key, { data, timestamp: Date.now() });
}
function getStale<T>(key: string): T | null {
const entry = apiCache.get(key);
return entry ? (entry.data as T) : null;
}
const uploadDir = path.join(process.cwd(), "client/public/uploads");
if (!fs.existsSync(uploadDir)) {
fs.mkdirSync(uploadDir, { recursive: true });
@@ -159,6 +173,10 @@ export async function registerRoutes(
const page = parseInt(req.query.page as string) || 1;
const perPage = parseInt(req.query.perPage as string) || 20;
const search = req.query.search as string || "";
const cacheKey = `videos_${page}_${perPage}_${search}`;
const cached = getCached<any>(cacheKey, 30 * 60 * 1000);
if (cached) return res.json(cached);
let path = `/library/${LIBRARY_ID}/videos?page=${page}&itemsPerPage=${perPage}&orderBy=date`;
if (search) path += `&search=${encodeURIComponent(search)}`;
const data = await bunnyFetch(path);
@@ -177,8 +195,12 @@ export async function registerRoutes(
category: v.category || "",
};
});
res.json({ items: videos, totalItems: data.totalItems, currentPage: data.currentPage });
const result = { items: videos, totalItems: data.totalItems, currentPage: data.currentPage };
setCache(cacheKey, result);
res.json(result);
} catch (err: any) {
const stale = getStale<any>(`videos_${req.query.page || 1}_${req.query.perPage || 20}_${req.query.search || ""}`);
if (stale) return res.json(stale);
res.status(500).json({ message: err.message });
}
});
@@ -342,98 +364,75 @@ export async function registerRoutes(
}
});
// News feed - Volksmusik/Schlager news from Google News RSS
function parseRssItems(xml: string): { title: string; link: string; source: string; pubDate: string }[] {
const items: { title: string; link: string; source: string; pubDate: string }[] = [];
const itemRegex = /<item>([\s\S]*?)<\/item>/g;
let match;
while ((match = itemRegex.exec(xml)) !== 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 });
}
return items;
}
async function fetchRssFeed(rssUrl: string): Promise<string> {
const resp = await fetch(rssUrl, {
headers: { "User-Agent": "Mozilla/5.0 (compatible; FolxTV/1.0)" },
redirect: "follow",
});
if (!resp.ok) throw new Error(`RSS fetch failed: ${resp.status}`);
return await resp.text();
}
app.get("/api/news-feed", async (_req, res) => {
const cacheKey = "news-feed";
const cached = getCached<any[]>(cacheKey, 15 * 60 * 1000);
if (cached) return res.json(cached);
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 });
}
}
const xml = await fetchRssFeed(rssUrl);
const items = parseRssItems(xml);
if (items.length > 0) setCache(cacheKey, items);
res.json(items);
} catch (err: any) {
res.json([]);
console.log("[news-feed] RSS fetch error:", err.message);
const stale = getStale<any[]>(cacheKey);
res.json(stale || []);
}
});
app.get("/api/breaking-news", async (_req, res) => {
const cacheKey = "breaking-news";
const cached = getCached<any[]>(cacheKey, 15 * 60 * 1000);
if (cached) return res.json(cached);
try {
const topics = ["Nachrichten+Deutschland", "Nachrichten+Oesterreich", "Nachrichten+Europa", "Wirtschaft+aktuell", "Sport+aktuell"];
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 });
}
}
const xml = await fetchRssFeed(rssUrl);
const items = parseRssItems(xml);
if (items.length > 0) setCache(cacheKey, items);
res.json(items);
} catch (err: any) {
res.json([]);
console.log("[breaking-news] RSS fetch error:", err.message);
const stale = getStale<any[]>(cacheKey);
res.json(stale || []);
}
});