mirror of
https://github.com/filecoffee/filehost.git
synced 2024-11-13 19:49:56 +01:00
Merge branch 'main' into accounts
This commit is contained in:
commit
4514db7c28
1 changed files with 26 additions and 7 deletions
33
index.js
33
index.js
|
@ -26,14 +26,33 @@ app.use(authRoutes);
|
|||
app.use(fileRoutes);
|
||||
app.use(helmet());
|
||||
|
||||
app.get("/", async (req, res) => {
|
||||
const engine =
|
||||
process.env.STORAGE_MODE === "s3"
|
||||
? require("./engines/s3.engine")
|
||||
: require("./engines/local.engine");
|
||||
const s3 = require("./engines/s3.engine");
|
||||
const local = require("./engines/local.engine");
|
||||
const storageMode = process.env.STORAGE_MODE || "local";
|
||||
|
||||
const { gatherStatistics } = engine;
|
||||
const { uploads, size } = await gatherStatistics();
|
||||
app.get("/", async (req, res) => {
|
||||
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", {
|
||||
totalUploads: uploads,
|
||||
totalSize: size.toFixed(2),
|
||||
|
|
Loading…
Reference in a new issue