Setup KHUFU_UPLOAD_PATH

This commit is contained in:
Dunemask 2021-08-23 21:02:12 -06:00
parent 7c5a6dd326
commit 2cf99f5577
5 changed files with 21 additions and 9 deletions

View file

@ -4,8 +4,15 @@ echo "Creating vanilla predeploy!"
if [[ $PWD == *"dist" ]];
then cd ..
fi
# If .env exists, ignore it
if [[ ! -f ".env" ]];then
echo "Building vanilla env file!"
echo "KHUFU_UPLOAD_PATH=/srv/uploads">> .env
fi
# Install node dependencies
echo "Installing node depencencies!"
npm i
echo "Building Docker Image!"
npm run build:all
echo "Building JS Bundle!"
npm run build:react
echo "Building docker image"
docker-compose build

View file

@ -9,6 +9,8 @@ services:
- ALEXANDRIA_INTERNAL_URL=${ALEXANDRIA_INTERNAL_URL}
- ALEXANDRIA_DATABASE_PASSWORD=${ALEXANDRIA_DATABASE_PASSWORD}
- CAIRO_PUBLIC_URL=${CAIRO_PUBLIC_URL}
env_file:
- .env
networks:
- dunestorm_dev
networks:

View file

@ -40,7 +40,8 @@
"ext": "js,json",
"signal": "SIGINT",
"env": {
"CAIRO_URL": "http://localhost:52000"
"CAIRO_URL": "http://localhost:52000",
"KHUFU_UPLOAD_PATH": "uploads/"
}
}
}

View file

@ -6,12 +6,15 @@ const multer = require("multer");
const config = require("../config.json");
//Multer Configs
const userUploadStorage = multer.diskStorage({
destination: (req, file, cb) => cb(null, userUploadDestination(req.user.cairoId)),
destination: (req, file, cb) =>
cb(null, userUploadDestination(req.user.cairoId)),
filename: (req, file, cb) => {
const n = file.originalname.replaceAll(" ", "_");
const fileName = `${Date.now()}-${n}`;
req.on("aborted", () =>
cancelUpload(resolvePath(userUploadDestination(req.user.cairoId), fileName))
cancelUpload(
resolvePath(userUploadDestination(req.user.cairoId), fileName)
)
);
cb(null, fileName);
},
@ -22,9 +25,9 @@ const userUpload = multer({
//Helper Methods
function userUploadDestination(user_id) {
if (!fs.existsSync(resolvePath(config.Storage.UploadPath)))
fs.mkdirSync(resolvePath(config.Storage.UploadPath));
const destination = resolvePath(config.Storage.UploadPath, `${user_id}`);
if (!fs.existsSync(resolvePath(process.env.KHUFU_UPLOAD_PATH)))
fs.mkdirSync(resolvePath(process.env.KHUFU_UPLOAD_PATH));
const destination = resolvePath(process.env.KHUFU_UPLOAD_PATH, `${user_id}`);
if (!fs.existsSync(destination)) fs.mkdirSync(destination);
return destination;
}

View file

@ -1,6 +1,5 @@
{
"Storage": {
"UploadPath": "src/uploads/",
"UserStorageSize": 25,
"UserStorageUnit": 1048576,
"UploadMaxSize": ""