|
|
@ -1,7 +1,8 @@
|
|
|
|
import Book from '../../data/Book';
|
|
|
|
import Book from '../../data/Book';
|
|
|
|
import Auth from '../../data/Auth';
|
|
|
|
import Auth from '../../data/Auth';
|
|
|
|
import Settings from '../../data/Settings';
|
|
|
|
import Settings, { SETTINGS_FILE } from '../../data/Settings';
|
|
|
|
import * as DataEvent from '../../../src/com/events/DataEvent';
|
|
|
|
import * as DataEvent from '../../../src/com/events/DataEvent';
|
|
|
|
|
|
|
|
import Render from '../../data/Render';
|
|
|
|
const express = require('express');
|
|
|
|
const express = require('express');
|
|
|
|
const router = express.Router();
|
|
|
|
const router = express.Router();
|
|
|
|
const multer = require('multer');
|
|
|
|
const multer = require('multer');
|
|
|
@ -10,6 +11,7 @@ const moment = require('moment');
|
|
|
|
const book = new Book();
|
|
|
|
const book = new Book();
|
|
|
|
const auth = new Auth();
|
|
|
|
const auth = new Auth();
|
|
|
|
const settings = new Settings();
|
|
|
|
const settings = new Settings();
|
|
|
|
|
|
|
|
const render = new Render();
|
|
|
|
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');
|
|
|
@ -91,6 +93,36 @@ router.post('/write/:task?', feature_upload, (req, res) => {
|
|
|
|
if (result.type === DataEvent.PAGE_ADDED) {
|
|
|
|
if (result.type === DataEvent.PAGE_ADDED) {
|
|
|
|
settings.updatePageIndex();
|
|
|
|
settings.updatePageIndex();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//load all page data and render if render on save flag is set in settings file
|
|
|
|
|
|
|
|
getBookData()
|
|
|
|
|
|
|
|
.then(result => {
|
|
|
|
|
|
|
|
if (result.settings.global.renderOnSave === 'true') {
|
|
|
|
|
|
|
|
render
|
|
|
|
|
|
|
|
.publishAll(
|
|
|
|
|
|
|
|
result.pages,
|
|
|
|
|
|
|
|
result.settings.global.theme,
|
|
|
|
|
|
|
|
req.session.user.handle
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
.then(response => {
|
|
|
|
|
|
|
|
res.json({
|
|
|
|
|
|
|
|
type: response.type,
|
|
|
|
|
|
|
|
message: response.message
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
.catch(err => {
|
|
|
|
|
|
|
|
res.json({
|
|
|
|
|
|
|
|
type: DataEvent.PAGES_NOT_RENDERED,
|
|
|
|
|
|
|
|
message: 'Uh oh. Pages not rendered, sport',
|
|
|
|
|
|
|
|
error: err
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
//console.log('DONT RENDER PAGES');
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
.catch(() => {
|
|
|
|
|
|
|
|
console.log();
|
|
|
|
|
|
|
|
});
|
|
|
|
res.json(result);
|
|
|
|
res.json(result);
|
|
|
|
})
|
|
|
|
})
|
|
|
|
.catch(err => {
|
|
|
|
.catch(err => {
|
|
|
@ -138,3 +170,19 @@ router.post('/add-post-image', post_upload, function (req, res) {
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
module.exports = router;
|
|
|
|
module.exports = router;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function getBookData() {
|
|
|
|
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
|
|
|
|
let getSettings = settings.load(SETTINGS_FILE);
|
|
|
|
|
|
|
|
let getBook = book.getPage();
|
|
|
|
|
|
|
|
Promise.all([getSettings, getBook])
|
|
|
|
|
|
|
|
.then(result => {
|
|
|
|
|
|
|
|
const [settings, pages] = result;
|
|
|
|
|
|
|
|
let data = { settings: settings, pages: pages };
|
|
|
|
|
|
|
|
resolve(data);
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
.catch(err => {
|
|
|
|
|
|
|
|
reject(err);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|