forked from projects/fipamo
fixed upload dirs creation when not present, added error pages for routes
This commit is contained in:
parent
af72b343eb
commit
1aea87faf0
6 changed files with 65 additions and 62 deletions
|
@ -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) {
|
||||
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(':');
|
||||
|
|
|
@ -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) {
|
||||
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(':');
|
||||
|
|
|
@ -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 });
|
||||
}
|
||||
});
|
||||
});
|
||||
|
|
|
@ -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');
|
||||
|
|
|
@ -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,10 +92,7 @@ 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')
|
||||
fs.readJSON('site/settings.jso')
|
||||
.then(config => {
|
||||
res.render('page-edit', {
|
||||
id: config.library_stats.current_index,
|
||||
|
@ -110,9 +107,9 @@ router.get('/add/new', function (req, res) {
|
|||
edit: false
|
||||
});
|
||||
})
|
||||
.catch(err => {}); //render error page
|
||||
}
|
||||
);
|
||||
.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');
|
||||
|
|
|
@ -15,9 +15,10 @@ router.get('/', function (req, res) {
|
|||
config = obj;
|
||||
})
|
||||
.catch(err => {
|
||||
console.log('SETTINGS ERROR', err);
|
||||
res.render('error', { error: err });
|
||||
});
|
||||
loadThemes().then(themes => {
|
||||
loadThemes()
|
||||
.then(themes => {
|
||||
if (req.session.user) {
|
||||
let memberInfo = [];
|
||||
let user = req.session.user;
|
||||
|
@ -43,6 +44,9 @@ router.get('/', function (req, res) {
|
|||
} else {
|
||||
res.redirect('/@/dashboard');
|
||||
}
|
||||
})
|
||||
.catch(err => {
|
||||
res.render('error', { error: err });
|
||||
});
|
||||
});
|
||||
module.exports = router;
|
||||
|
|
Loading…
Reference in a new issue