2019-11-23 19:30:34 +01:00
|
|
|
import Book from '../../data/Book';
|
2020-06-21 03:13:23 +02:00
|
|
|
import Settings, { SETTINGS_FILE } from '../../data/Settings';
|
2018-12-08 19:21:48 +01:00
|
|
|
const express = require('express');
|
2020-06-05 04:50:08 +02:00
|
|
|
const moment = require('moment');
|
2018-12-08 19:21:48 +01:00
|
|
|
const router = express.Router();
|
2020-05-21 03:14:19 +02:00
|
|
|
const book = new Book();
|
2020-06-21 03:13:23 +02:00
|
|
|
const settings = new Settings();
|
2020-05-29 01:13:52 +02:00
|
|
|
const indexLimit = 5;
|
2019-11-20 02:17:39 +01:00
|
|
|
|
2018-10-31 17:00:31 +01:00
|
|
|
//--------------------------
|
|
|
|
// Index
|
|
|
|
//--------------------------
|
2020-05-21 03:14:19 +02:00
|
|
|
router.get('/', function (req, res) {
|
2020-06-21 03:13:23 +02:00
|
|
|
settings
|
|
|
|
.load(SETTINGS_FILE)
|
|
|
|
.then(config => {
|
|
|
|
book.getPage().then(result => {
|
|
|
|
result.sort((a, b) => parseFloat(b.metadata.id) - parseFloat(a.metadata.id));
|
|
|
|
let indexPages = [];
|
|
|
|
let indexCount = 0;
|
|
|
|
result.forEach(page => {
|
|
|
|
if (
|
|
|
|
typeof page.metadata.deleted === 'undefined' ||
|
|
|
|
page.metadata.deleted === false
|
|
|
|
) {
|
|
|
|
if (indexCount === indexLimit) return;
|
|
|
|
indexPages.push({
|
|
|
|
page: page,
|
|
|
|
date: moment(page.metadata.created).fromNow()
|
|
|
|
});
|
|
|
|
++indexCount;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
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);
|
|
|
|
});
|
|
|
|
})
|
|
|
|
.catch(err => {
|
|
|
|
if (err.code === 'ENOENT') {
|
|
|
|
let setupData = { title: 'Fipamo Set up' };
|
|
|
|
res.render('init', setupData);
|
|
|
|
} else {
|
2020-06-21 05:53:45 +02:00
|
|
|
res.render('error', { error: err });
|
2020-03-01 22:13:18 +01:00
|
|
|
}
|
|
|
|
});
|
2019-11-16 20:05:48 +01:00
|
|
|
});
|
2019-10-12 01:10:55 +02:00
|
|
|
|
2018-10-31 17:00:31 +01:00
|
|
|
//--------------------------
|
2018-12-08 19:21:48 +01:00
|
|
|
// Logout
|
2018-10-31 17:00:31 +01:00
|
|
|
//--------------------------
|
2020-09-04 22:33:32 +02:00
|
|
|
router.get('/logout', (req, res) => {
|
|
|
|
//req.logout();
|
|
|
|
req.session.destroy();
|
|
|
|
res.redirect('/@/dashboard');
|
2018-10-31 17:00:31 +01:00
|
|
|
});
|
2018-12-08 19:21:48 +01:00
|
|
|
module.exports = router;
|