|
|
|
@ -1,23 +1,13 @@
|
|
|
|
|
import Book from '../../data/Book';
|
|
|
|
|
import StringUtils from '../../../src/com/utils/StringUtils';
|
|
|
|
|
import * as DataEvent from '../../../src/com/events/DataEvent';
|
|
|
|
|
import sanitize from 'sanitize-html';
|
|
|
|
|
import RightsManager, {
|
|
|
|
|
TASK_CREATE,
|
|
|
|
|
TASK_UPDATE,
|
|
|
|
|
OBJECT_POST
|
|
|
|
|
} from '../../../src/com/utils/RightsManager';
|
|
|
|
|
const express = require('express');
|
|
|
|
|
const router = express.Router();
|
|
|
|
|
const multer = require('multer');
|
|
|
|
|
const md = require('markdown-it')('commonmark');
|
|
|
|
|
const fs = require('fs-extra');
|
|
|
|
|
const moment = require('moment');
|
|
|
|
|
const rightsManager = new RightsManager();
|
|
|
|
|
const book = new Book();
|
|
|
|
|
const uploadPath =
|
|
|
|
|
'./public/assets/images/blog/' + moment().format('YYYY') + '/' + moment().format('MM');
|
|
|
|
|
const _ = require('lodash');
|
|
|
|
|
fs.ensureDir(uploadPath, () => {
|
|
|
|
|
// dir has now been created, including the directory it is to be placed in
|
|
|
|
|
});
|
|
|
|
@ -50,12 +40,16 @@ router.get('/', (req, res) => {
|
|
|
|
|
/***
|
|
|
|
|
Update Page
|
|
|
|
|
*/
|
|
|
|
|
router.post('/write', feature_upload, (req, res) => {
|
|
|
|
|
router.post('/write/:task?', feature_upload, (req, res) => {
|
|
|
|
|
var feature = '';
|
|
|
|
|
if (req.files.lengh > 0) {
|
|
|
|
|
if (req.files.length > 0) {
|
|
|
|
|
var path = req.files[0].path;
|
|
|
|
|
feature = '/' + path.substring(7, path.length);
|
|
|
|
|
} else {
|
|
|
|
|
var url = req.body.feature_image;
|
|
|
|
|
feature = url.substring(21, url.length);
|
|
|
|
|
url != null || url != undefined || url != ''
|
|
|
|
|
? (feature = url.substring(21, url.length))
|
|
|
|
|
: (feature = '');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var pageWrite =
|
|
|
|
@ -82,11 +76,14 @@ router.post('/write', feature_upload, (req, res) => {
|
|
|
|
|
req.session.user.handle +
|
|
|
|
|
'\n' +
|
|
|
|
|
'created: ' +
|
|
|
|
|
req.body.created +
|
|
|
|
|
moment(req.body.created).format() +
|
|
|
|
|
'\n' +
|
|
|
|
|
'updated: ' +
|
|
|
|
|
moment(Date.now()).format() +
|
|
|
|
|
'\n' +
|
|
|
|
|
'menu: ' +
|
|
|
|
|
req.body.pinToMenu +
|
|
|
|
|
'\n' +
|
|
|
|
|
'featured: ' +
|
|
|
|
|
req.body.featureStatus +
|
|
|
|
|
'\n' +
|
|
|
|
@ -98,12 +95,20 @@ router.post('/write', feature_upload, (req, res) => {
|
|
|
|
|
'\n' +
|
|
|
|
|
'---\n\n' +
|
|
|
|
|
req.body.content;
|
|
|
|
|
fs.writeFile('content/pages/test.md', pageWrite, err => {
|
|
|
|
|
fs.writeFile('content/pages/' + req.body.slug + '.md', pageWrite, err => {
|
|
|
|
|
// throws an error, you could also catch it here
|
|
|
|
|
if (err) res.json({ type: DataEvent.PAGE_ERROR, message: err });
|
|
|
|
|
|
|
|
|
|
// success case, the file was saved
|
|
|
|
|
res.json({ type: DataEvent.PAGE_UPDATED, message: 'Page Has been saved' });
|
|
|
|
|
if (req.params.task === 'new') {
|
|
|
|
|
res.json({
|
|
|
|
|
type: DataEvent.PAGE_ADDED,
|
|
|
|
|
message: 'New Page Created',
|
|
|
|
|
id: req.body.page_uuid
|
|
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
res.json({ type: DataEvent.PAGE_UPDATED, message: 'Page Has been saved' });
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|