fixed upload dirs creation when not present, added error pages for routes

pull/20/head
Ro 4 years ago
parent af72b343eb
commit 1aea87faf0

@ -13,9 +13,13 @@ const settings = new Settings();
const _ = require('lodash'); const _ = require('lodash');
const uploadPath = const uploadPath =
'./public/assets/images/blog/' + moment().format('YYYY') + '/' + moment().format('MM'); './public/assets/images/blog/' + moment().format('YYYY') + '/' + moment().format('MM');
var storage = multer.diskStorage({ var storage = multer.diskStorage({
destination: function (req, file, cb) { destination: function (req, file, cb) {
fs.ensureDir(uploadPath, () => {
// dir has now been created, including the directory it is to be placed in
cb(null, uploadPath); cb(null, uploadPath);
});
}, },
filename: function (req, file, cb) { filename: function (req, file, cb) {
var splice = file.originalname.split(':'); var splice = file.originalname.split(':');

@ -10,7 +10,6 @@ const multer = require('multer');
const fs = require('fs-extra'); const fs = require('fs-extra');
const moment = require('moment'); const moment = require('moment');
const _ = require('lodash'); const _ = require('lodash');
//const folks = require('../../../site/folks.json');
const auth = new Auth(); const auth = new Auth();
const render = new Render(); const render = new Render();
const book = new Book(); const book = new Book();
@ -18,12 +17,13 @@ const settings = new Settings();
const nav = new Navigation(); const nav = new Navigation();
const uploadPath = const uploadPath =
'./public/assets/images/user/' + moment().format('YYYY') + '/' + moment().format('MM'); './public/assets/images/user/' + moment().format('YYYY') + '/' + moment().format('MM');
fs.ensureDir(uploadPath, () => {
// dir has now been created, including the directory it is to be placed in
});
var storage = multer.diskStorage({ var storage = multer.diskStorage({
destination: function (req, file, cb) { destination: function (req, file, cb) {
fs.ensureDir(uploadPath, () => {
// dir has now been created, including the directory it is to be placed in
cb(null, uploadPath); cb(null, uploadPath);
});
}, },
filename: function (req, file, cb) { filename: function (req, file, cb) {
var splice = file.originalname.split(':'); var splice = file.originalname.split(':');

@ -3,7 +3,6 @@ import Settings, { SETTINGS_FILE } from '../../data/Settings';
const express = require('express'); const express = require('express');
const moment = require('moment'); const moment = require('moment');
const router = express.Router(); const router = express.Router();
//const config = require('../../../site/settings.json');
const book = new Book(); const book = new Book();
const settings = new Settings(); const settings = new Settings();
const indexLimit = 5; const indexLimit = 5;
@ -47,7 +46,7 @@ router.get('/', function (req, res) {
let setupData = { title: 'Fipamo Set up' }; let setupData = { title: 'Fipamo Set up' };
res.render('init', setupData); res.render('init', setupData);
} else { } else {
//render error page res.render('error', { error: err });
} }
}); });
}); });

@ -66,12 +66,11 @@ router.get('/', function (req, res) {
}); });
}) })
.catch(err => { .catch(err => {
//console.log('ERROR', err); res.render('error', { error: err });
//render error pages
}); });
}) })
.catch(err => { .catch(err => {
console.log('ERROR', err); res.render('error', { error: err });
}); });
} else { } else {
res.redirect('/@/dashboard'); res.redirect('/@/dashboard');

@ -78,8 +78,8 @@ router.get('/list/:filter?/:page?', function (req, res) {
.then(() => { .then(() => {
//console.log(value); //console.log(value);
}) })
.catch(() => { .catch(err => {
//next(err); res.render('error', { error: err });
}); });
} else { } else {
res.redirect('/@/dashboard'); res.redirect('/@/dashboard');
@ -92,10 +92,7 @@ router.get('/list/:filter?/:page?', function (req, res) {
router.get('/add/new', function (req, res) { router.get('/add/new', function (req, res) {
if (req.session.user) { if (req.session.user) {
//need to grab a few copy of settings for the lastest index //need to grab a few copy of settings for the lastest index
fs.ensureDir( fs.readJSON('site/settings.jso')
'./public/assets/images/blog/' + moment().format('YYYY') + '/' + moment().format('MM'),
() => {
fs.readJSON('site/settings.json')
.then(config => { .then(config => {
res.render('page-edit', { res.render('page-edit', {
id: config.library_stats.current_index, id: config.library_stats.current_index,
@ -110,9 +107,9 @@ router.get('/add/new', function (req, res) {
edit: false edit: false
}); });
}) })
.catch(err => {}); //render error page .catch(err => {
} res.render('error', { error: err });
); });
} else { } else {
res.redirect('/@/dashboard'); res.redirect('/@/dashboard');
} }
@ -145,7 +142,7 @@ router.get('/edit/:id', function (req, res) {
}); });
}) })
.catch(err => { .catch(err => {
res.json({ type: err }); res.render('error', { error: err });
}); });
} else { } else {
res.redirect('/@/dashboard'); res.redirect('/@/dashboard');

@ -15,9 +15,10 @@ router.get('/', function (req, res) {
config = obj; config = obj;
}) })
.catch(err => { .catch(err => {
console.log('SETTINGS ERROR', err); res.render('error', { error: err });
}); });
loadThemes().then(themes => { loadThemes()
.then(themes => {
if (req.session.user) { if (req.session.user) {
let memberInfo = []; let memberInfo = [];
let user = req.session.user; let user = req.session.user;
@ -43,6 +44,9 @@ router.get('/', function (req, res) {
} else { } else {
res.redirect('/@/dashboard'); res.redirect('/@/dashboard');
} }
})
.catch(err => {
res.render('error', { error: err });
}); });
}); });
module.exports = router; module.exports = router;

Loading…
Cancel
Save