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