|
|
|
@ -9,6 +9,7 @@ const fs = require('fs-extra');
|
|
|
|
|
const moment = require('moment');
|
|
|
|
|
const book = new Book();
|
|
|
|
|
const nav = new Navigation();
|
|
|
|
|
const auth = new Auth();
|
|
|
|
|
const _ = require('lodash');
|
|
|
|
|
const uploadPath =
|
|
|
|
|
'./public/assets/images/blog/' + moment().format('YYYY') + '/' + moment().format('MM');
|
|
|
|
@ -46,41 +47,39 @@ router.get('/', (req, res) => {
|
|
|
|
|
* Add/Update Page
|
|
|
|
|
*/
|
|
|
|
|
router.post('/write/:task?', feature_upload, (req, res) => {
|
|
|
|
|
if (req.session.user) {
|
|
|
|
|
Auth.authCheck(req)
|
|
|
|
|
.then(() => {
|
|
|
|
|
let body = _.mapValues(req.body);
|
|
|
|
|
let feature = '';
|
|
|
|
|
let task = '';
|
|
|
|
|
req.params.task === 'new'
|
|
|
|
|
? (task = DataEvent.API_PAGE_CREATE)
|
|
|
|
|
: (task = DataEvent.API_PAGE_WRITE);
|
|
|
|
|
if (req.files.length > 0) {
|
|
|
|
|
var path = req.files[0].path;
|
|
|
|
|
feature = '/' + path.substring(7, path.length);
|
|
|
|
|
} else {
|
|
|
|
|
var url = body.feature_image;
|
|
|
|
|
url != null || url != undefined || url != ''
|
|
|
|
|
? (feature = url.substring(21, url.length))
|
|
|
|
|
: (feature = '');
|
|
|
|
|
}
|
|
|
|
|
body.feature = feature;
|
|
|
|
|
body.deleted = false;
|
|
|
|
|
book.editPage(body, body.page_uuid, task, req.session.user)
|
|
|
|
|
.then(result => {
|
|
|
|
|
if (result.type === DataEvent.PAGE_CREATE) {
|
|
|
|
|
nav.updatePageStats();
|
|
|
|
|
}
|
|
|
|
|
res.json(result);
|
|
|
|
|
})
|
|
|
|
|
.catch(err => {
|
|
|
|
|
res.json(err);
|
|
|
|
|
});
|
|
|
|
|
})
|
|
|
|
|
.catch(err => {
|
|
|
|
|
res.json(err);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
auth.authCheck(req)
|
|
|
|
|
.then(() => {
|
|
|
|
|
let body = _.mapValues(req.body);
|
|
|
|
|
let feature = '';
|
|
|
|
|
let task = '';
|
|
|
|
|
req.params.task === 'new'
|
|
|
|
|
? (task = DataEvent.API_PAGE_CREATE)
|
|
|
|
|
: (task = DataEvent.API_PAGE_WRITE);
|
|
|
|
|
if (req.files.length > 0) {
|
|
|
|
|
var path = req.files[0].path;
|
|
|
|
|
feature = '/' + path.substring(7, path.length);
|
|
|
|
|
} else {
|
|
|
|
|
var url = body.feature_image;
|
|
|
|
|
url != null || url != undefined || url != ''
|
|
|
|
|
? (feature = url.substring(21, url.length))
|
|
|
|
|
: (feature = '');
|
|
|
|
|
}
|
|
|
|
|
body.feature = feature;
|
|
|
|
|
body.deleted = false;
|
|
|
|
|
book.editPage(body, body.page_uuid, task, req.session.user)
|
|
|
|
|
.then(result => {
|
|
|
|
|
if (result.type === DataEvent.PAGE_CREATE) {
|
|
|
|
|
nav.updatePageStats();
|
|
|
|
|
}
|
|
|
|
|
res.json(result);
|
|
|
|
|
})
|
|
|
|
|
.catch(err => {
|
|
|
|
|
res.json(err);
|
|
|
|
|
});
|
|
|
|
|
})
|
|
|
|
|
.catch(err => {
|
|
|
|
|
res.json(err);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@ -88,22 +87,20 @@ router.post('/write/:task?', feature_upload, (req, res) => {
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
router.post('/delete', (req, res) => {
|
|
|
|
|
if (req.session.user) {
|
|
|
|
|
Auth.authCheck(req)
|
|
|
|
|
.then(() => {
|
|
|
|
|
book.editPage([], req.body.id, DataEvent.API_PAGE_DELETE, req.session.user)
|
|
|
|
|
.then(result => {
|
|
|
|
|
//remove item from menu in settings
|
|
|
|
|
res.json(result);
|
|
|
|
|
})
|
|
|
|
|
.catch(err => {
|
|
|
|
|
res.json(err);
|
|
|
|
|
});
|
|
|
|
|
})
|
|
|
|
|
.catch(err => {
|
|
|
|
|
res.json(err);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
auth.authCheck(req)
|
|
|
|
|
.then(() => {
|
|
|
|
|
book.editPage([], req.body.id, DataEvent.API_PAGE_DELETE, req.session.user)
|
|
|
|
|
.then(result => {
|
|
|
|
|
//remove item from menu in settings
|
|
|
|
|
res.json(result);
|
|
|
|
|
})
|
|
|
|
|
.catch(err => {
|
|
|
|
|
res.json(err);
|
|
|
|
|
});
|
|
|
|
|
})
|
|
|
|
|
.catch(err => {
|
|
|
|
|
res.json(err);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|