fix Analyse

This commit is contained in:
nadja
2026-08-26 15:18:50 +02:00
parent eab8e82674
commit 146dad6f79
4 changed files with 17 additions and 15 deletions

View File

@@ -13,7 +13,11 @@ function loadDB() {
} }
function saveDB(data) { function saveDB(data) {
writeFileSync(DB_FILE, JSON.stringify(data, null, 2)); try {
writeFileSync(DB_FILE, JSON.stringify(data, null, 2));
} catch (e) {
console.error('Analytics DB Schreibfehler:', e.message);
}
} }
let db = loadDB(); let db = loadDB();

View File

@@ -20,17 +20,19 @@ app.use((req, res, next) => {
if (req.method === 'OPTIONS' || !req.path.startsWith('/api/')) return next(); if (req.method === 'OPTIONS' || !req.path.startsWith('/api/')) return next();
if (req.path.startsWith('/api/analytics')) return next(); if (req.path.startsWith('/api/analytics')) return next();
let userId = null; try {
const authHeader = req.headers.authorization; let userId = null;
if (authHeader && authHeader.startsWith('Bearer ')) { const authHeader = req.headers.authorization;
try { if (authHeader && authHeader.startsWith('Bearer ')) {
const decoded = jwt.verify(authHeader.split(' ')[1], JWT_SECRET); try {
const user = getUserByUsername(decoded.username); const decoded = jwt.verify(authHeader.split(' ')[1], JWT_SECRET);
if (user) userId = user.id; const user = getUserByUsername(decoded.username);
} catch {} if (user) userId = user.id;
} } catch {}
}
trackEvent('page_view', userId, { path: req.path, method: req.method });
} catch {}
trackEvent('page_view', userId, { path: req.path, method: req.method });
next(); next();
}); });

View File

@@ -1,5 +1,3 @@
import fetch from 'node-fetch';
const INSTAGRAM_TOKEN = process.env.INSTAGRAM_TOKEN; const INSTAGRAM_TOKEN = process.env.INSTAGRAM_TOKEN;
export async function getInstagramData(url) { export async function getInstagramData(url) {

View File

@@ -1,5 +1,3 @@
import fetch from 'node-fetch';
export async function getTikTokData(url) { export async function getTikTokData(url) {
const oembedUrl = `https://www.tiktok.com/oembed?url=${encodeURIComponent(url)}`; const oembedUrl = `https://www.tiktok.com/oembed?url=${encodeURIComponent(url)}`;
const response = await fetch(oembedUrl); const response = await fetch(oembedUrl);