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

This commit is contained in:
Ro 2020-06-20 20:53:45 -07:00
parent af72b343eb
commit 1aea87faf0
6 changed files with 65 additions and 62 deletions

View file

@ -13,9 +13,13 @@ const settings = new Settings();
const _ = require('lodash');
const uploadPath =
'./public/assets/images/blog/' + moment().format('YYYY') + '/' + moment().format('MM');
var storage = multer.diskStorage({
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) {
var splice = file.originalname.split(':');

View file

@ -10,7 +10,6 @@ const multer = require('multer');
const fs = require('fs-extra');
const moment = require('moment');
const _ = require('lodash');
//const folks = require('../../../site/folks.json');
const auth = new Auth();
const render = new Render();
const book = new Book();
@ -18,12 +17,13 @@ const settings = new Settings();
const nav = new Navigation();
const uploadPath =
'./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({
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) {
var splice = file.originalname.split(':');

View file

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

View file

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

View file

@ -78,8 +78,8 @@ router.get('/list/:filter?/:page?', function (req, res) {
.then(() => {
//console.log(value);
})
.catch(() => {
//next(err);
.catch(err => {
res.render('error', { error: err });
});
} else {
res.redirect('/@/dashboard');
@ -92,27 +92,24 @@ router.get('/list/:filter?/:page?', function (req, res) {
router.get('/add/new', function (req, res) {
if (req.session.user) {
//need to grab a few copy of settings for the lastest index
fs.ensureDir(
'./public/assets/images/blog/' + moment().format('YYYY') + '/' + moment().format('MM'),
() => {
fs.readJSON('site/settings.json')
.then(config => {
res.render('page-edit', {
id: config.library_stats.current_index,
uuid: uuidv4(),
title: 'Add New Page',
user_status: true,
welcome: 'Add New Page',
date: moment(Date.now()).format('YYYY MMM DD'),
page: [],
rawDate: moment(Date.now()).format(),
status: ['false', 'false', 'false'],
edit: false
});
})
.catch(err => {}); //render error page
}
);
fs.readJSON('site/settings.jso')
.then(config => {
res.render('page-edit', {
id: config.library_stats.current_index,
uuid: uuidv4(),
title: 'Add New Page',
user_status: true,
welcome: 'Add New Page',
date: moment(Date.now()).format('YYYY MMM DD'),
page: [],
rawDate: moment(Date.now()).format(),
status: ['false', 'false', 'false'],
edit: false
});
})
.catch(err => {
res.render('error', { error: err });
});
} else {
res.redirect('/@/dashboard');
}
@ -145,7 +142,7 @@ router.get('/edit/:id', function (req, res) {
});
})
.catch(err => {
res.json({ type: err });
res.render('error', { error: err });
});
} else {
res.redirect('/@/dashboard');

View file

@ -15,35 +15,39 @@ router.get('/', function (req, res) {
config = obj;
})
.catch(err => {
console.log('SETTINGS ERROR', err);
res.render('error', { error: err });
});
loadThemes().then(themes => {
if (req.session.user) {
let memberInfo = [];
let user = req.session.user;
memberInfo.push({
handle: user.handle,
email: user.email,
avi: user.avi
});
themes.sort(function (a, b) {
var textA = a.theme.name.toUpperCase();
var textB = b.theme.name.toUpperCase();
return textA < textB ? -1 : textA > textB ? 1 : 0;
});
loadThemes()
.then(themes => {
if (req.session.user) {
let memberInfo = [];
let user = req.session.user;
memberInfo.push({
handle: user.handle,
email: user.email,
avi: user.avi
});
themes.sort(function (a, b) {
var textA = a.theme.name.toUpperCase();
var textB = b.theme.name.toUpperCase();
return textA < textB ? -1 : textA > textB ? 1 : 0;
});
res.render('settings', {
title: 'Dashboard | Settings',
welcome: 'Your Settings',
status: true,
themes: themes,
settings: config,
member: memberInfo[0]
});
} else {
res.redirect('/@/dashboard');
}
});
res.render('settings', {
title: 'Dashboard | Settings',
welcome: 'Your Settings',
status: true,
themes: themes,
settings: config,
member: memberInfo[0]
});
} else {
res.redirect('/@/dashboard');
}
})
.catch(err => {
res.render('error', { error: err });
});
});
module.exports = router;