|
|
|
@ -37,15 +37,89 @@ var post_upload = multer({
|
|
|
|
|
}).array('post_image');
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Retrieves list of Pages
|
|
|
|
|
* Retrieves a page of a published entries
|
|
|
|
|
* @public
|
|
|
|
|
*/
|
|
|
|
|
router.get('/', (req, res) => {
|
|
|
|
|
router.get('/published/:pageNum?', (req, res) => {
|
|
|
|
|
//console.log('PAGE NUM', req.params.pageNum);
|
|
|
|
|
let pageNum = req.params.pageNum;
|
|
|
|
|
if (pageNum === null || pageNum === '' || !pageNum) pageNum = 1;
|
|
|
|
|
let pages = [];
|
|
|
|
|
book.getPage().then(result => {
|
|
|
|
|
res.json(result);
|
|
|
|
|
result.sort((a, b) => parseFloat(b.metadata.id) - parseFloat(a.metadata.id));
|
|
|
|
|
let displayed = _.filter(result, page => {
|
|
|
|
|
return (
|
|
|
|
|
page.metadata.deleted === false &&
|
|
|
|
|
page.metadata.published === true &&
|
|
|
|
|
page.metadata.layout != 'index'
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
var pageLimit = 6;
|
|
|
|
|
var count = Math.ceil(displayed.length / pageLimit);
|
|
|
|
|
if (pageNum > count || isNaN(pageNum))
|
|
|
|
|
res.json({ type: DataEvent.REQUEST_LAME, message: "That page doesn't exist, champ." });
|
|
|
|
|
var rangeIndex = pageNum * pageLimit - pageLimit;
|
|
|
|
|
|
|
|
|
|
let meta = [];
|
|
|
|
|
|
|
|
|
|
for (let index = 0; index < pageLimit; index++) {
|
|
|
|
|
const page = displayed[index + rangeIndex];
|
|
|
|
|
try {
|
|
|
|
|
if (
|
|
|
|
|
page.metadata.id != null &&
|
|
|
|
|
page.metadata.deleted === false &&
|
|
|
|
|
page.metadata.published === true
|
|
|
|
|
) {
|
|
|
|
|
let entry = page.metadata;
|
|
|
|
|
entry.content = page.content;
|
|
|
|
|
//console.log('ENTRY', entry);
|
|
|
|
|
pages.push({
|
|
|
|
|
page: entry,
|
|
|
|
|
displayDate: moment(page.metadata.created).fromNow()
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
} catch (e) {
|
|
|
|
|
//console.log("NO POST", e)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
meta.push({ currentPage: pageNum, totalPages: count });
|
|
|
|
|
let data = { pages: pages, meta: meta };
|
|
|
|
|
res.json({
|
|
|
|
|
type: DataEvent.REQUEST_GOOD,
|
|
|
|
|
message: 'This is Page ' + pageNum + ' of ' + count,
|
|
|
|
|
data: data
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Retrieves single entry
|
|
|
|
|
* @public
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
router.get('/single/:id', (req, res) => {
|
|
|
|
|
let id = req.params.id;
|
|
|
|
|
if (id === null || id === '')
|
|
|
|
|
res.json({ type: DataEvent.REQUEST_LAME, message: " Nah, this isn't here." });
|
|
|
|
|
book.getPage(id)
|
|
|
|
|
.then(page => {
|
|
|
|
|
let entry = page.metadata;
|
|
|
|
|
entry.content = page.content;
|
|
|
|
|
res.json({
|
|
|
|
|
type: DataEvent.REQUEST_GOOD,
|
|
|
|
|
message: 'Found it. Here you go.',
|
|
|
|
|
data: entry
|
|
|
|
|
});
|
|
|
|
|
})
|
|
|
|
|
.catch(err => {
|
|
|
|
|
res.json({
|
|
|
|
|
type: DataEvent.REQUEST_LAME,
|
|
|
|
|
message: "This doesn't seem to be here, homie.",
|
|
|
|
|
err: err.message
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Add/Update Page
|
|
|
|
|
*/
|
|
|
|
@ -121,7 +195,7 @@ router.post('/write/:task?', feature_upload, (req, res) => {
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
.catch(() => {
|
|
|
|
|
console.log();
|
|
|
|
|
//console.log();
|
|
|
|
|
});
|
|
|
|
|
res.json(result);
|
|
|
|
|
})
|
|
|
|
|