This commit is contained in:
Daniël 2024-06-09 15:34:01 +02:00
parent 3dd000116e
commit ffcee4e802

View file

@ -11,14 +11,32 @@ app.set("view engine", "ejs");
app.use(fileRoutes); app.use(fileRoutes);
app.use(helmet()); app.use(helmet());
app.get("/", async (req, res) => { const s3 = require("./engines/s3.engine");
const engine = const local = require("./engines/local.engine");
process.env.STORAGE_MODE === "s3"
? require("./engines/s3.engine")
: require("./engines/local.engine");
const { gatherStatistics } = engine; app.get("/", async (req, res) => {
const { uploads, size } = await gatherStatistics(); let storageEngine;
if (storageMode === "local") {
storageEngine = local(
multerOptions,
fileNameLength,
process.env.LOCAL_UPLOAD_PATH,
);
} else if (storageMode === "s3") {
const s3Config = {
accessKeyId: process.env.AWS_ACCESS_KEY_ID,
secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY,
region: process.env.AWS_REGION,
bucketName: process.env.S3_BUCKET_NAME,
endpoint: process.env.S3_ENDPOINT,
};
storageEngine = s3(multerOptions, fileNameLength, s3Config);
} else {
throw new Error("Invalid STORAGE_MODE");
}
const { uploads, size } = await storageEngine.gatherStatistics();
res.render("index", { res.render("index", {
totalUploads: uploads, totalUploads: uploads,
totalSize: size.toFixed(2), totalSize: size.toFixed(2),