diff --git a/src/inc/locales/de.json b/src/inc/locales/de.json index 65ee9f0..43ebda6 100644 --- a/src/inc/locales/de.json +++ b/src/inc/locales/de.json @@ -445,6 +445,7 @@ "stat_deleted": "Gelöscht", "stat_comments": "Gesamt Kommentare", "stat_favs": "Gesamt Favoriten", + "stat_disk_usage": "Dateigröße Gesamt", "most_favorited": "Meiste Favs", "favs": "Favs", "top_xd": "Top xD-Score" diff --git a/src/inc/locales/en.json b/src/inc/locales/en.json index 2680433..e0109d1 100644 --- a/src/inc/locales/en.json +++ b/src/inc/locales/en.json @@ -449,6 +449,7 @@ "stat_deleted": "Deleted", "stat_comments": "Total Comments", "stat_favs": "Total Favorites", + "stat_disk_usage": "Total File Size", "most_favorited": "Most Favorited", "favs": "favs", "top_xd": "Top xD Scores" diff --git a/src/inc/locales/nl.json b/src/inc/locales/nl.json index 8234ca4..c378c2c 100644 --- a/src/inc/locales/nl.json +++ b/src/inc/locales/nl.json @@ -445,6 +445,7 @@ "stat_deleted": "Verwijderd", "stat_comments": "Totaal aantal reacties", "stat_favs": "Totaal aantal favorieten", + "stat_disk_usage": "Totale Bestandsgrootte", "most_favorited": "Meest Gefavoriet", "favs": "favorieten", "top_xd": "Top xD-scores" diff --git a/src/inc/locales/zange.json b/src/inc/locales/zange.json index 90107e6..0e2cb93 100644 --- a/src/inc/locales/zange.json +++ b/src/inc/locales/zange.json @@ -448,6 +448,7 @@ "stat_deleted": "Gelöscht", "stat_comments": "Gesamtanzahl Kommentare", "stat_favs": "Gesamtanzahl Favoriten", + "stat_disk_usage": "Dateigröße Gesamt", "most_favorited": "Am häufigsten favorisiert", "favs": "Favoriten", "top_xd": "Beste xD-Punktestände" diff --git a/src/inc/routes/ranking.mjs b/src/inc/routes/ranking.mjs index b42afad..9576589 100644 --- a/src/inc/routes/ranking.mjs +++ b/src/inc/routes/ranking.mjs @@ -3,6 +3,32 @@ import lib from "../lib.mjs"; import config from "../config.mjs"; import f0cklib from "../routeinc/f0cklib.mjs"; import fetch from "flumm-fetch"; +import { exec } from "child_process"; + +let cachedDiskSize = "Calculating..."; + +function updateDiskSize() { + exec("du -sb f0ckm-data/b f0ckm-data/t f0ckm-data/c", (error, stdout, stderr) => { + if (error) { + console.error(`Error calculating disk size: ${error.message}`); + return; + } + const lines = stdout.trim().split('\n'); + let totalBytes = 0; + for (const line of lines) { + const match = line.match(/^(\d+)\s+/); + if (match) { + totalBytes += parseInt(match[1], 10); + } + } + cachedDiskSize = lib.formatSize(totalBytes); + }); +} + +// Update every 30 minutes +setInterval(updateDiskSize, 1000 * 60 * 30); +updateDiskSize(); // Run once at start + export default (router, tpl) => { router.get(/^\/ranking$/, lib.loggedin, async (req, res) => { @@ -94,6 +120,7 @@ export default (router, tpl) => { totalComments, totalFavs, enable_nsfl: config.enable_nsfl, + diskSize: cachedDiskSize, tmp: null, session: (req.session && req.session.user) ? { ...req.session } : false, page_meta: { diff --git a/views/ranking.html b/views/ranking.html index 47698b4..e436f6a 100644 --- a/views/ranking.html +++ b/views/ranking.html @@ -82,6 +82,7 @@ {{ t('ranking.stat_nsfl') }}{{ stats.nsfl }} @endif {{ t('ranking.stat_deleted') }}{{ stats.deleted }} + {{ t('ranking.stat_disk_usage') }}{{ diskSize }}