From 8b3fceb5d88d5bc509541000646168d73283662f Mon Sep 17 00:00:00 2001 From: arsam Date: Fri, 18 Sep 2026 23:12:34 +0330 Subject: [PATCH] Import source: backend/src/routes/dashboard Import the existing local project snapshot. This commit organizes existing files; it does not represent newly developed functionality. --- backend/src/routes/dashboard.ts | 55 +++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 backend/src/routes/dashboard.ts diff --git a/backend/src/routes/dashboard.ts b/backend/src/routes/dashboard.ts new file mode 100644 index 0000000..45e4ea4 --- /dev/null +++ b/backend/src/routes/dashboard.ts @@ -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 };