New Gallery: create directory if doesn't exist!#120
This commit is contained in:
@@ -68,6 +68,16 @@ if (process.env.NODE_ENV === 'production') {
|
||||
portapp: '0',
|
||||
dir: '',
|
||||
},
|
||||
{
|
||||
idapp: '7',
|
||||
name: 'Notevole',
|
||||
adminemail: 'pao.loarena77@gmail.com',
|
||||
manageremail: '',
|
||||
replyTo: '',
|
||||
host: 'https://notevole.freeplanet.app',
|
||||
portapp: '0',
|
||||
dir: '/var/www/notevole.freeplanet.app',
|
||||
},
|
||||
];
|
||||
} else if (process.env.NODE_ENV === 'test') {
|
||||
MYAPPS = [
|
||||
@@ -117,7 +127,16 @@ if (process.env.NODE_ENV === 'production') {
|
||||
host: 'http://test.mandalaperlanima.eu',
|
||||
portapp: '0',
|
||||
dir: '',
|
||||
}
|
||||
},
|
||||
{
|
||||
idapp: '7',
|
||||
name: 'Notevole',
|
||||
adminemail: '',
|
||||
manageremail: '',
|
||||
host: 'https://notevole.freeplanet.app',
|
||||
portapp: '0',
|
||||
dir: '/var/www/notevole.freeplanet.app',
|
||||
},
|
||||
];
|
||||
} else {
|
||||
MYAPPS = [
|
||||
@@ -168,6 +187,15 @@ if (process.env.NODE_ENV === 'production') {
|
||||
portapp: '8083',
|
||||
dir: '',
|
||||
},
|
||||
{
|
||||
idapp: '7',
|
||||
name: 'Notevole',
|
||||
adminemail: 'paolo.arena77@gmail.com',
|
||||
manageremail: '',
|
||||
host: 'http://localhost',
|
||||
portapp: '8085',
|
||||
dir: '',
|
||||
},
|
||||
];
|
||||
|
||||
}
|
||||
|
||||
@@ -527,6 +527,8 @@ router.post('/upload/:dir', authenticate, (req, res) => {
|
||||
const dir = req.params.dir;
|
||||
const idapp = req.user.idapp;
|
||||
|
||||
// console.log('/upload dir:' + dir);
|
||||
|
||||
const form = new formidable.IncomingForm();
|
||||
|
||||
form.parse(req);
|
||||
@@ -541,14 +543,20 @@ router.post('/upload/:dir', authenticate, (req, res) => {
|
||||
form.on('file', async function (name, file) {
|
||||
try {
|
||||
console.log('Uploaded ' + file.name);
|
||||
// ++ Move in the folder application !
|
||||
newname = tools.getdirByIdApp(idapp) + '/statics/upload/' + dir + '/' + file.name;
|
||||
const mydir = tools.getdirByIdApp(idapp) + '/statics/upload/' + dir;
|
||||
|
||||
// Create Dir if doesn't exist:
|
||||
tools.mkdirpath(mydir);
|
||||
newname = mydir + '/' + file.name;
|
||||
|
||||
console.log('move from ', file.path, 'to :', newname);
|
||||
|
||||
// For local: ... resolve this... sending through the static folder...
|
||||
// res.sendFile(path.resolve(file.name));
|
||||
|
||||
// Move in the folder application !
|
||||
tools.move(file.path, newname, (err) => {
|
||||
console.log('err', err);
|
||||
console.log('err:', err);
|
||||
res.end();
|
||||
});
|
||||
|
||||
|
||||
@@ -571,6 +571,19 @@ module.exports = {
|
||||
}
|
||||
callback();
|
||||
});
|
||||
},
|
||||
|
||||
mkdirpath(dirPath) {
|
||||
// if (!fs.accessSync(dirPath, fs.constants.R_OK | fs.constants.W_OK)) {
|
||||
if (!fs.existsSync(dirPath)){
|
||||
try {
|
||||
fs.mkdirSync(dirPath, { recursive: true });
|
||||
}
|
||||
catch (e) {
|
||||
mkdirpath(path.dirname(dirPath));
|
||||
mkdirpath(dirPath);
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user