mirror of
https://github.com/filecoffee/filehost.git
synced 2024-11-13 19:49:56 +01:00
engine for statistics
This commit is contained in:
parent
f1a636d018
commit
b56ed41244
1 changed files with 17 additions and 7 deletions
24
index.js
24
index.js
|
@ -1,26 +1,36 @@
|
||||||
require("dotenv").config();
|
require("dotenv").config();
|
||||||
const express = require("express");
|
const express = require("express");
|
||||||
const ejs = require("ejs");
|
|
||||||
const fileRoutes = require("./routes/file.routes");
|
const fileRoutes = require("./routes/file.routes");
|
||||||
const helmet = require("helmet");
|
const helmet = require("helmet");
|
||||||
|
const initializeLocalStorage = require("./engines/local.engine");
|
||||||
|
const initializeS3Storage = require("./engines/s3.engine");
|
||||||
|
|
||||||
const app = express();
|
const app = express();
|
||||||
const port = process.env.PORT;
|
const port = process.env.PORT;
|
||||||
const apiKeys = process.env.API_KEYS.split(",");
|
|
||||||
const allowPublicUploads = process.env.ALLOW_PUBLIC_UPLOADS === "true";
|
|
||||||
const hosterEmail = process.env.HOSTER_EMAIL;
|
const hosterEmail = process.env.HOSTER_EMAIL;
|
||||||
|
|
||||||
let totalUploads = 0;
|
const localStorage = initializeLocalStorage({}, 10, "./uploads");
|
||||||
let totalSize = 0;
|
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.set("view engine", "ejs");
|
||||||
app.use(fileRoutes);
|
app.use(fileRoutes);
|
||||||
app.use(helmet());
|
app.use(helmet());
|
||||||
|
|
||||||
app.get("/", (req, res) => {
|
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
|
||||||
|
|
||||||
res.render("index", {
|
res.render("index", {
|
||||||
totalUploads: totalUploads,
|
totalUploads: totalUploads,
|
||||||
totalSize: totalSize.toFixed(2), // Format to 2 decimal places
|
totalSize: totalSize.toFixed(2),
|
||||||
hosterEmail: hosterEmail,
|
hosterEmail: hosterEmail,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue