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) {
cb(null, uploadPath); fs.ensureDir(uploadPath, () => {
// dir has now been created, including the directory it is to be placed in
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) {
cb(null, uploadPath); fs.ensureDir(uploadPath, () => {
// dir has now been created, including the directory it is to be placed in
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,27 +92,24 @@ 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'), .then(config => {
() => { res.render('page-edit', {
fs.readJSON('site/settings.json') id: config.library_stats.current_index,
.then(config => { uuid: uuidv4(),
res.render('page-edit', { title: 'Add New Page',
id: config.library_stats.current_index, user_status: true,
uuid: uuidv4(), welcome: 'Add New Page',
title: 'Add New Page', date: moment(Date.now()).format('YYYY MMM DD'),
user_status: true, page: [],
welcome: 'Add New Page', rawDate: moment(Date.now()).format(),
date: moment(Date.now()).format('YYYY MMM DD'), status: ['false', 'false', 'false'],
page: [], edit: false
rawDate: moment(Date.now()).format(), });
status: ['false', 'false', 'false'], })
edit: false .catch(err => {
}); res.render('error', { error: err });
}) });
.catch(err => {}); //render error page
}
);
} 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,35 +15,39 @@ 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()
if (req.session.user) { .then(themes => {
let memberInfo = []; if (req.session.user) {
let user = req.session.user; let memberInfo = [];
memberInfo.push({ let user = req.session.user;
handle: user.handle, memberInfo.push({
email: user.email, handle: user.handle,
avi: user.avi email: user.email,
}); avi: user.avi
themes.sort(function (a, b) { });
var textA = a.theme.name.toUpperCase(); themes.sort(function (a, b) {
var textB = b.theme.name.toUpperCase(); var textA = a.theme.name.toUpperCase();
return textA < textB ? -1 : textA > textB ? 1 : 0; var textB = b.theme.name.toUpperCase();
}); return textA < textB ? -1 : textA > textB ? 1 : 0;
});
res.render('settings', { res.render('settings', {
title: 'Dashboard | Settings', title: 'Dashboard | Settings',
welcome: 'Your Settings', welcome: 'Your Settings',
status: true, status: true,
themes: themes, themes: themes,
settings: config, settings: config,
member: memberInfo[0] member: memberInfo[0]
}); });
} else { } else {
res.redirect('/@/dashboard'); res.redirect('/@/dashboard');
} }
}); })
.catch(err => {
res.render('error', { error: err });
});
}); });
module.exports = router; module.exports = router;

Loading…
Cancel
Save