New Gallery: create directory if doesn't exist!#120

This commit is contained in:
Paolo Arena
2019-12-28 14:30:30 +01:00
parent 523edf557b
commit 0c91e6ce0b
3 changed files with 101 additions and 52 deletions

View File

@@ -68,6 +68,16 @@ if (process.env.NODE_ENV === 'production') {
portapp: '0', portapp: '0',
dir: '', 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') { } else if (process.env.NODE_ENV === 'test') {
MYAPPS = [ MYAPPS = [
@@ -117,7 +127,16 @@ if (process.env.NODE_ENV === 'production') {
host: 'http://test.mandalaperlanima.eu', host: 'http://test.mandalaperlanima.eu',
portapp: '0', portapp: '0',
dir: '', dir: '',
} },
{
idapp: '7',
name: 'Notevole',
adminemail: '',
manageremail: '',
host: 'https://notevole.freeplanet.app',
portapp: '0',
dir: '/var/www/notevole.freeplanet.app',
},
]; ];
} else { } else {
MYAPPS = [ MYAPPS = [
@@ -168,6 +187,15 @@ if (process.env.NODE_ENV === 'production') {
portapp: '8083', portapp: '8083',
dir: '', dir: '',
}, },
{
idapp: '7',
name: 'Notevole',
adminemail: 'paolo.arena77@gmail.com',
manageremail: '',
host: 'http://localhost',
portapp: '8085',
dir: '',
},
]; ];
} }

View File

@@ -527,6 +527,8 @@ router.post('/upload/:dir', authenticate, (req, res) => {
const dir = req.params.dir; const dir = req.params.dir;
const idapp = req.user.idapp; const idapp = req.user.idapp;
// console.log('/upload dir:' + dir);
const form = new formidable.IncomingForm(); const form = new formidable.IncomingForm();
form.parse(req); form.parse(req);
@@ -541,14 +543,20 @@ router.post('/upload/:dir', authenticate, (req, res) => {
form.on('file', async function (name, file) { form.on('file', async function (name, file) {
try { try {
console.log('Uploaded ' + file.name); console.log('Uploaded ' + file.name);
// ++ Move in the folder application ! const mydir = tools.getdirByIdApp(idapp) + '/statics/upload/' + dir;
newname = tools.getdirByIdApp(idapp) + '/statics/upload/' + dir + '/' + file.name;
// 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... // For local: ... resolve this... sending through the static folder...
// res.sendFile(path.resolve(file.name)); // res.sendFile(path.resolve(file.name));
// Move in the folder application !
tools.move(file.path, newname, (err) => { tools.move(file.path, newname, (err) => {
console.log('err', err); console.log('err:', err);
res.end(); res.end();
}); });

View File

@@ -571,6 +571,19 @@ module.exports = {
} }
callback(); 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);
}
}
},
}; };