From 9e1bde7475da3f521bf98fa6e6aa3f651c70655f 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:59:16 +0200 Subject: [PATCH] code cleanup --- index.js | 24 +++++++----------------- 1 file changed, 7 insertions(+), 17 deletions(-) diff --git a/index.js b/index.js index 3c64c72..a88c779 100644 --- a/index.js +++ b/index.js @@ -2,35 +2,25 @@ require("dotenv").config(); const express = require("express"); const fileRoutes = require("./routes/file.routes"); const helmet = require("helmet"); -const initializeLocalStorage = require("./engines/local.engine"); -const initializeS3Storage = require("./engines/s3.engine"); const app = express(); const port = process.env.PORT; const hosterEmail = process.env.HOSTER_EMAIL; -const localStorage = initializeLocalStorage({}, 10, "./uploads"); -const s3Storage = initializeS3Storage({}, 10, { - accessKeyId: process.env.AWS_ACCESS_KEY_ID, - secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY, - endpoint: process.env.AWS_S3_ENDPOINT, - bucketName: process.env.AWS_S3_BUCKET_NAME, -}); - app.set("view engine", "ejs"); app.use(fileRoutes); app.use(helmet()); app.get("/", async (req, res) => { - const localStats = localStorage.gatherStatistics(); - const s3Stats = await s3Storage.gatherStatistics(); - - const totalUploads = localStats.totalUploads + s3Stats.totalUploads; - const totalSize = (localStats.totalSize + s3Stats.totalSize) / (1024 * 1024); // Convert to MB + const engine = + process.env.STORAGE_MODE === "s3" + ? require("./engines/s3.engine") + : require("./engines/local.engine"); + const { uploads, size } = await engine.gatherStatistics(); res.render("index", { - totalUploads: totalUploads, - totalSize: totalSize.toFixed(2), + totalUploads: uploads, + totalSize: size.toFixed(2), hosterEmail: hosterEmail, }); });