|
|
|
import Book from '../../data/Book';
|
|
|
|
const express = require('express');
|
|
|
|
const router = express.Router();
|
|
|
|
const config = require('../../../site/settings.json');
|
|
|
|
const book = new Book();
|
|
|
|
|
|
|
|
//--------------------------
|
|
|
|
// Index
|
|
|
|
//--------------------------
|
|
|
|
router.get('/', function (req, res) {
|
|
|
|
book.getPage().then(result => {
|
|
|
|
result.sort((a, b) => parseFloat(b.metadata.id) - parseFloat(a.metadata.id));
|
|
|
|
let indexPages = [];
|
|
|
|
result.forEach(page => {
|
|
|
|
if (typeof page.metadata.deleted === 'undefined' || page.metadata.deleted === false) {
|
|
|
|
indexPages.push(page);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
let pageData = [];
|
|
|
|
if (req.session.user) {
|
|
|
|
pageData = { title: config.global.title, status: true, pages: indexPages };
|
|
|
|
} else {
|
|
|
|
pageData = { title: config.global.title, status: false, pages: indexPages };
|
|
|
|
}
|
|
|
|
|
|
|
|
res.render('index', pageData);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
//--------------------------
|
|
|
|
// Logout
|
|
|
|
//--------------------------
|
|
|
|
router.post('/logout', function (req, res) {
|
|
|
|
req.logout();
|
|
|
|
return res.json({
|
|
|
|
message: 'LOGGED OUT'
|
|
|
|
});
|
|
|
|
});
|
|
|
|
module.exports = router;
|