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',
|
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: '',
|
||||||
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -462,7 +462,7 @@ router.post('/upload_from_other_server/:dir', authenticate, (req, res) => {
|
|||||||
const dir = req.params.dir;
|
const dir = req.params.dir;
|
||||||
const idapp = req.user.idapp;
|
const idapp = req.user.idapp;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
const form = new formidable.IncomingForm();
|
const form = new formidable.IncomingForm();
|
||||||
|
|
||||||
form.parse(req);
|
form.parse(req);
|
||||||
@@ -517,7 +517,7 @@ router.post('/upload_from_other_server/:dir', authenticate, (req, res) => {
|
|||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.log('Error', e)
|
console.log('Error', e)
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
});
|
});
|
||||||
@@ -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);
|
||||||
@@ -534,25 +536,31 @@ router.post('/upload/:dir', authenticate, (req, res) => {
|
|||||||
form.uploadDir = folder + '/' + dir;
|
form.uploadDir = folder + '/' + dir;
|
||||||
try {
|
try {
|
||||||
|
|
||||||
form.on('fileBegin', async function (name, file){
|
form.on('fileBegin', async function (name, file) {
|
||||||
file.path = folder + '/' + file.name;
|
file.path = folder + '/' + file.name;
|
||||||
});
|
});
|
||||||
|
|
||||||
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();
|
||||||
});
|
});
|
||||||
|
|
||||||
}catch (e) {
|
} catch (e) {
|
||||||
console.log('error', e);
|
console.log('error', e);
|
||||||
res.status(400).send();
|
res.status(400).send();
|
||||||
}
|
}
|
||||||
@@ -592,7 +600,7 @@ router.delete('/delfile', authenticate, (req, res) => {
|
|||||||
res.send({ code: server_constants.RIS_CODE_OK, msg: '' });
|
res.send({ code: server_constants.RIS_CODE_OK, msg: '' });
|
||||||
});
|
});
|
||||||
|
|
||||||
}catch (e) {
|
} catch (e) {
|
||||||
console.log('error', e);
|
console.log('error', e);
|
||||||
res.status(400).send();
|
res.status(400).send();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user