mirror-filecoffee-filehost/index.js

41 lines
1.3 KiB
JavaScript
Raw Normal View History

2024-06-02 17:32:54 +02:00
require("dotenv").config();
const express = require("express");
2024-06-04 18:48:52 +02:00
const fileRoutes = require("./routes/file.routes");
2024-06-09 13:25:46 +02:00
const helmet = require("helmet");
2024-06-09 14:55:39 +02:00
const initializeLocalStorage = require("./engines/local.engine");
const initializeS3Storage = require("./engines/s3.engine");
2024-06-02 17:32:54 +02:00
const app = express();
2024-06-09 14:21:40 +02:00
const port = process.env.PORT;
2024-06-02 17:32:54 +02:00
const hosterEmail = process.env.HOSTER_EMAIL;
2024-06-09 14:55:39 +02:00
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,
});
2024-06-02 17:32:54 +02:00
app.set("view engine", "ejs");
2024-06-04 18:45:19 +02:00
app.use(fileRoutes);
2024-06-09 13:25:46 +02:00
app.use(helmet());
2024-06-02 17:32:54 +02:00
2024-06-09 14:55:39 +02:00
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
2024-06-04 18:45:19 +02:00
res.render("index", {
totalUploads: totalUploads,
2024-06-09 14:55:39 +02:00
totalSize: totalSize.toFixed(2),
2024-06-04 18:45:19 +02:00
hosterEmail: hosterEmail,
2024-06-02 17:32:54 +02:00
});
2024-06-04 18:45:19 +02:00
});
2024-06-02 17:32:54 +02:00
2024-06-04 18:45:19 +02:00
app.listen(port, () => {
console.log(`Server is running on port ${port}`);
});