Setup KHUFU_UPLOAD_PATH
This commit is contained in:
parent
7c5a6dd326
commit
2cf99f5577
5 changed files with 21 additions and 9 deletions
11
dist/predeploy-vanilla.sh
vendored
11
dist/predeploy-vanilla.sh
vendored
|
@ -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
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -40,7 +40,8 @@
|
|||
"ext": "js,json",
|
||||
"signal": "SIGINT",
|
||||
"env": {
|
||||
"CAIRO_URL": "http://localhost:52000"
|
||||
"CAIRO_URL": "http://localhost:52000",
|
||||
"KHUFU_UPLOAD_PATH": "uploads/"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
{
|
||||
"Storage": {
|
||||
"UploadPath": "src/uploads/",
|
||||
"UserStorageSize": 25,
|
||||
"UserStorageUnit": 1048576,
|
||||
"UploadMaxSize": ""
|
||||
|
|
Reference in a new issue