From bffa3a18145aa0ee245eb1518d546ac4224cf0b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dani=C3=ABl?= <15849319+abcdan@users.noreply.github.com> Date: Sun, 9 Jun 2024 14:54:28 +0200 Subject: [PATCH] local gather statistics --- engines/local.engine.js | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/engines/local.engine.js b/engines/local.engine.js index 815aa6e..c945b2e 100644 --- a/engines/local.engine.js +++ b/engines/local.engine.js @@ -38,7 +38,22 @@ const initializeLocalStorage = (multerOptions, fileNameLength, uploadPath) => { }); }; - return { writeFile, findFile }; + const gatherStatistics = () => { + let totalUploads = 0; + let totalSize = 0; + + const files = fs.readdirSync(uploadPath); + files.forEach((file) => { + const filePath = path.join(uploadPath, file); + const stats = fs.statSync(filePath); + totalUploads++; + totalSize += stats.size; + }); + + return { totalUploads, totalSize }; + }; + + return { writeFile, findFile, gatherStatistics }; }; module.exports = initializeLocalStorage;