Import source: backend/src/routes/dashboard

Import the existing local project snapshot. This commit organizes existing files; it does not represent newly developed functionality.
This commit is contained in:
arsam
2026-09-18 23:12:34 +03:30
parent c352140d8f
commit 8b3fceb5d8
+55
View File
@@ -0,0 +1,55 @@
import express from 'express';
import { store } from '../services/store.js';
import { getSessionId } from '../middleware/session.js';
import { getActivityFeed, getStorageBreakdown, getMonthlyUploadVolume } from '../services/analytics.js';
const router = express.Router();
router.get('/stats', async (req, res) => {
const sid = getSessionId(req);
const db = await store.read();
const myFiles = db.files.filter((f) => f.status === 'uploaded' && f.sessionId === sid);
const totalViews = myFiles.reduce((sum, f) => sum + f.views, 0);
const totalDownloads = myFiles.reduce((sum, f) => sum + f.downloads, 0);
const storageUsed = myFiles.reduce((sum, f) => sum + f.sizeBytes, 0);
const now = new Date();
const fortyEightHoursFromNow = new Date(now.getTime() + 48 * 60 * 60 * 1000);
const activeLinks = myFiles.filter((f) => new Date(f.expiresAt) > now).length;
const expiringSoonCount = myFiles.filter((f) => {
const exp = new Date(f.expiresAt);
return exp > now && exp <= fortyEightHoursFromNow;
}).length;
res.json({
data: {
totalFiles: myFiles.length,
totalViews,
totalDownloads,
storageUsed,
activeLinks,
expiringSoonCount,
},
});
});
router.get('/activity', async (req, res) => {
const sid = getSessionId(req);
const feed = await getActivityFeed(sid);
res.json({ data: feed });
});
router.get('/storage', async (req, res) => {
const sid = getSessionId(req);
const breakdown = await getStorageBreakdown(sid);
const monthlyVolume = await getMonthlyUploadVolume(sid);
res.json({
data: {
breakdown,
monthlyVolume,
},
});
});
export { router as dashboardRouter };