New Gallery: create directory if doesn't exist!#120
This commit is contained in:
@@ -462,62 +462,62 @@ router.post('/upload_from_other_server/:dir', authenticate, (req, res) => {
|
||||
const dir = req.params.dir;
|
||||
const idapp = req.user.idapp;
|
||||
|
||||
/*
|
||||
const form = new formidable.IncomingForm();
|
||||
/*
|
||||
const form = new formidable.IncomingForm();
|
||||
|
||||
form.parse(req);
|
||||
form.parse(req);
|
||||
|
||||
const client = new ftp(process.env.FTPSERVER_HOST, process.env.FTPSERVER_PORT, process.env.FTPSERVER_USER + idapp + '@associazioneshen.it', process.env.FTPSERVER_PWD + idapp, false, 134217728);
|
||||
const client = new ftp(process.env.FTPSERVER_HOST, process.env.FTPSERVER_PORT, process.env.FTPSERVER_USER + idapp + '@associazioneshen.it', process.env.FTPSERVER_PWD + idapp, false, 134217728);
|
||||
|
||||
// SSL_OP_NO_TLSv1_2 = 134217728
|
||||
// SSL_OP_NO_TLSv1_2 = 134217728
|
||||
|
||||
// console.log('client', client);
|
||||
// console.log('client', client);
|
||||
|
||||
form.uploadDir = folder + '/' + dir;
|
||||
try {
|
||||
form.uploadDir = folder + '/' + dir;
|
||||
try {
|
||||
|
||||
form.on('fileBegin', async function (name, file){
|
||||
file.path = folder + '/' + file.name;
|
||||
});
|
||||
form.on('fileBegin', async function (name, file){
|
||||
file.path = folder + '/' + file.name;
|
||||
});
|
||||
|
||||
form.on('file', async function (name, file){
|
||||
try {
|
||||
// Create directory remote
|
||||
form.on('file', async function (name, file){
|
||||
try {
|
||||
// Create directory remote
|
||||
|
||||
if (!!dir)
|
||||
await client.createDir(dir);
|
||||
if (!!dir)
|
||||
await client.createDir(dir);
|
||||
|
||||
const miofile = (dir) ? dir + `/` + file.name : file.name;
|
||||
console.log('Upload...');
|
||||
const ret = await client.upload(file.path, miofile, 755);
|
||||
console.log('Uploaded ' + file.name, 'status:', ret);
|
||||
if (!ret)
|
||||
const miofile = (dir) ? dir + `/` + file.name : file.name;
|
||||
console.log('Upload...');
|
||||
const ret = await client.upload(file.path, miofile, 755);
|
||||
console.log('Uploaded ' + file.name, 'status:', ret);
|
||||
if (!ret)
|
||||
res.status(400).send();
|
||||
else {
|
||||
// Delete file from local directory
|
||||
fs.unlinkSync(file.path);
|
||||
res.end();
|
||||
}
|
||||
}catch (e) {
|
||||
console.log('error', e);
|
||||
res.status(400).send();
|
||||
else {
|
||||
// Delete file from local directory
|
||||
fs.unlinkSync(file.path);
|
||||
res.end();
|
||||
}
|
||||
}catch (e) {
|
||||
console.log('error', e);
|
||||
});
|
||||
|
||||
form.on('aborted', () => {
|
||||
console.error('Request aborted by the user');
|
||||
res.status(400).send();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
form.on('aborted', () => {
|
||||
console.error('Request aborted by the user');
|
||||
res.status(400).send();
|
||||
});
|
||||
form.on('error', (err) => {
|
||||
console.error('Error Uploading', err);
|
||||
res.status(400).send();
|
||||
});
|
||||
|
||||
form.on('error', (err) => {
|
||||
console.error('Error Uploading', err);
|
||||
res.status(400).send();
|
||||
});
|
||||
|
||||
} catch (e) {
|
||||
console.log('Error', e)
|
||||
}
|
||||
*/
|
||||
} catch (e) {
|
||||
console.log('Error', e)
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
});
|
||||
@@ -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);
|
||||
@@ -534,25 +536,31 @@ router.post('/upload/:dir', authenticate, (req, res) => {
|
||||
form.uploadDir = folder + '/' + dir;
|
||||
try {
|
||||
|
||||
form.on('fileBegin', async function (name, file){
|
||||
form.on('fileBegin', async function (name, file) {
|
||||
file.path = folder + '/' + file.name;
|
||||
});
|
||||
|
||||
form.on('file', async function (name, file){
|
||||
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();
|
||||
});
|
||||
|
||||
}catch (e) {
|
||||
} catch (e) {
|
||||
console.log('error', e);
|
||||
res.status(400).send();
|
||||
}
|
||||
@@ -592,7 +600,7 @@ router.delete('/delfile', authenticate, (req, res) => {
|
||||
res.send({ code: server_constants.RIS_CODE_OK, msg: '' });
|
||||
});
|
||||
|
||||
}catch (e) {
|
||||
} catch (e) {
|
||||
console.log('error', e);
|
||||
res.status(400).send();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user