started new api for retrieving markdown pages, dashboard displaying files for editing

This commit is contained in:
Ro 2019-11-19 17:17:39 -08:00
parent c549e5ba7c
commit 19cb97b9c4
9 changed files with 124 additions and 28 deletions

View file

@ -15,7 +15,7 @@ const fs = require('fs-extra');
const dateUtils = new DateUtils();
const rightsManager = new RightsManager();
const uploadPath =
'./content/blog-images/' +
'./public/assets/images/blog/' +
dateUtils.getDate('year', new Date()) +
'/' +
dateUtils.getDate('month', new Date());

View file

@ -13,7 +13,7 @@ const fs = require('fs-extra');
const dateUtils = new DateUtils();
const rightsManager = new RightsManager();
const uploadPath =
'./content/user-images/' +
'./public/assets/images/user/' +
dateUtils.getDate('year', new Date()) +
'/' +
dateUtils.getDate('month', new Date());

View file

@ -16,7 +16,6 @@ router.get('/', function(req, res) {
jwt.verify(token, 'super-secret-string', function(err, decoded) {
if (err)
return res.status(500).send({ auth: false, message: 'Failed to authenticate token.' });
res.status(200).send(decoded);
});
});
@ -24,7 +23,6 @@ router.get('/', function(req, res) {
* Login Member and return token
*/
router.post('/login', function(req, res) {
let form = req.body;
fs.readJson('config/folks.json').then(folks => {
let found = _.find(folks, { handle: req.body.handle });
if (found) {
@ -42,7 +40,6 @@ router.post('/login', function(req, res) {
let session = req.session;
session.user = found;
session.token = token;
res.json({ type: DataEvent.REQUEST_GOOD, message: 'Yes', token: session.token });
} else {
res.json({

55
brain/api/v1/pages.js Normal file
View file

@ -0,0 +1,55 @@
import DateUtils from '../../utils/tools/DateUtils';
import Pages from '../../utils/content/Pages';
import StringUtils from '../../utils/tools/StringUtils';
import * as DataEvent from '../../utils/events/DataEvent';
import sanitize from 'sanitize-html';
import RightsManager, {
TASK_CREATE,
TASK_UPDATE,
OBJECT_POST
} from '../../utils/tools/RightsManager';
const express = require('express');
const router = express.Router();
const multer = require('multer');
const md = require('markdown-it')('commonmark');
const fs = require('fs-extra');
const dateUtils = new DateUtils();
const rightsManager = new RightsManager();
const pagesUtil = new Pages();
const uploadPath =
'./public/assets/images/blog/' +
dateUtils.getDate('year', new Date()) +
'/' +
dateUtils.getDate('month', new Date());
const _ = require('lodash');
fs.ensureDir(uploadPath, () => {
//console.log(err) // => null
// dir has now been created, including the directory it is to be placed in
});
var storage = multer.diskStorage({
destination: function(req, file, cb) {
cb(null, uploadPath);
},
filename: function(req, file, cb) {
var splice = file.originalname.split(':');
cb(null, splice[0]);
}
});
var feature_upload = multer({
storage: storage
}).array('feature_image');
var post_upload = multer({
storage: storage
}).array('post_image');
/***
Retrieve Pages
*/
router.get('/', (req, res) => {
pagesUtil.retrieve().then(result => {
res.json(result);
});
});
module.exports = router;

View file

@ -44,25 +44,25 @@ app.use(flash());
//var front = require('./routes/front/index')(session);
var dash = require('./routes/dash/index');
var postDashboard = require('./routes/dash/posts');
var settingsDashboard = require('./routes/dash/settings');
var navDashboard = require('./routes/dash/nav');
//var settingsDashboard = require('./routes/dash/settings');
//var navDashboard = require('./routes/dash/nav');
//api
var postLibrary = require('./api/content/posts');
var settings = require('./api/content/settings');
var mailer = require('./api/mail/mailer');
var pages = require('./api/v1/pages');
//var settings = require('./api/content/settings');
//var mailer = require('./api/mail/mailer');
var auth = require('./api/v1/auth');
// API PATHS
//app.use('/api/post', postLibrary);
app.use('/api/v1/page', pages);
//app.use('/api/settings', settings);
app.use('/api/mail', mailer);
//app.use('/api/mail', mailer);
app.use('/api/v1/auth', auth);
// PAGES
//app.use('/', front);
app.use('/@/dashboard', dash);
app.use('/@/dashboard/posts', postDashboard);
app.use('/@/dashboard/settings', settingsDashboard);
app.use('/@/dashboard/navigation', navDashboard);
//app.use('/@/dashboard/settings', settingsDashboard);
//app.use('/@/dashboard/navigation', navDashboard);
//app.use('/mailer', mailer);
// catch 404 and forward to error handler
app.use(function(req, res, next) {

View file

@ -1,17 +1,23 @@
import Pages from '../../utils/content/Pages';
const express = require('express');
const router = express.Router();
const settings = require('../../../config/site-settings.json');
//--------------------------
// Index
//--------------------------
router.get('/', function(req, res) {
let loggedIn = false;
let pages = new Pages();
pages.retrieve().then(result => {
let pageData = [];
if (req.session.user) {
pageData = { title: settings.title, status: true, pages: result };
} else {
pageData = { title: settings.title, status: false, pages: result };
}
if (req.session.user) loggedIn = true;
res.render(settings.admin_theme + '/index', {
title: settings.title,
auth_status: loggedIn
res.render(settings.admin_theme + '/index', pageData);
});
});

View file

@ -12,7 +12,6 @@ const dateUtils = new DateUtils();
router.get('/list/:filter?/:page?', function(req, res) {
var pageNum = req.params.page;
var filter = req.params.filter;
if (pageNum == '' || pageNum == null) pageNum = 1;
if (filter == '' || filter == null) filter = 'all';
/*

52
package-lock.json generated
View file

@ -4216,14 +4216,22 @@
}
},
"https-proxy-agent": {
"version": "2.2.1",
"resolved": "https://registry.npmjs.org/https-proxy-agent/-/https-proxy-agent-2.2.1.tgz",
"integrity": "sha512-HPCTS1LW51bcyMYbxUIOO4HEOlQ1/1qRaFWcyxvwaqUS9TY88aoEuHUY33kuAh1YhVVaDQhLZsnPd+XNARWZlQ==",
"version": "2.2.4",
"resolved": "https://registry.npmjs.org/https-proxy-agent/-/https-proxy-agent-2.2.4.tgz",
"integrity": "sha512-OmvfoQ53WLjtA9HeYP9RNrWMJzzAz1JGaSFr1nijg0PVR1JaD/xbJq1mdEIIlxGpXp9eSe/O2LgU9DJmTPd0Eg==",
"requires": {
"agent-base": "^4.1.0",
"agent-base": "^4.3.0",
"debug": "^3.1.0"
},
"dependencies": {
"agent-base": {
"version": "4.3.0",
"resolved": "https://registry.npmjs.org/agent-base/-/agent-base-4.3.0.tgz",
"integrity": "sha512-salcGninV0nPrwpGNn4VTXBb1SOuXQBiqbrNXoeizJsHrsL6ERFM2Ne3JUSBWRE6aeNJI2ROP/WEEIDUiDe3cg==",
"requires": {
"es6-promisify": "^5.0.0"
}
},
"debug": {
"version": "3.2.6",
"resolved": "https://registry.npmjs.org/debug/-/debug-3.2.6.tgz",
@ -4233,9 +4241,9 @@
}
},
"ms": {
"version": "2.1.1",
"resolved": "https://registry.npmjs.org/ms/-/ms-2.1.1.tgz",
"integrity": "sha512-tgp+dl5cGk28utYktBsrFqA7HKgrhgPsg6Z/EfhWI4gl1Hwq8B/GmY/0oXZ6nF8hDVesS/FpnYaD/kOWhYQvyg=="
"version": "2.1.2",
"resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz",
"integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w=="
}
}
},
@ -4517,6 +4525,22 @@
"integrity": "sha512-RdJUflcE3cUzKiMqQgsCu06FPu9UdIJO0beYbPhHN4k6apgJtifcoCtT9bcxOpYBtpD2kCM6Sbzg4CausW/PKQ==",
"dev": true
},
"js-yaml": {
"version": "3.13.1",
"resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-3.13.1.tgz",
"integrity": "sha512-YfbcO7jXDdyj0DGxYVSlSeQNHbD7XPWvrVWeVUujrQEoZzWJIRrCPoyk6kL6IAjAG2IolMK4T0hNUe0HOUs5Jw==",
"requires": {
"argparse": "^1.0.7",
"esprima": "^4.0.0"
},
"dependencies": {
"esprima": {
"version": "4.0.1",
"resolved": "https://registry.npmjs.org/esprima/-/esprima-4.0.1.tgz",
"integrity": "sha512-eGuFFw7Upda+g4p+QHvnW0RyTX/SVeJBDM/gCtMARO0cLuT2HcEKnTPvhjV6aGeqrCB/sbNop0Kszm0jsaWU4A=="
}
}
},
"jsbn": {
"version": "0.1.1",
"resolved": "https://registry.npmjs.org/jsbn/-/jsbn-0.1.1.tgz",
@ -4874,6 +4898,15 @@
"uc.micro": "^1.0.5"
}
},
"markdown-yaml-metadata-parser": {
"version": "2.0.3",
"resolved": "https://registry.npmjs.org/markdown-yaml-metadata-parser/-/markdown-yaml-metadata-parser-2.0.3.tgz",
"integrity": "sha512-0VKi80rjcMTq3zBUwAzzYGa4Lp4pp+DE4hQW21cbhLVTLXygSxl9euAA6k+xiRvNubWIOjUEnoSiNgPcCuD27Q==",
"requires": {
"js-yaml": "^3.13.1",
"ramda": "^0.26.1"
}
},
"mdurl": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/mdurl/-/mdurl-1.0.1.tgz",
@ -5816,6 +5849,11 @@
"resolved": "https://registry.npmjs.org/qs/-/qs-6.5.2.tgz",
"integrity": "sha512-N5ZAX4/LxJmF+7wN74pUD6qAh9/wnvdQcjq9TZjevvXzSUo7bfmw91saqMjzGS2xq91/odN2dW/WOl7qQHNDGA=="
},
"ramda": {
"version": "0.26.1",
"resolved": "https://registry.npmjs.org/ramda/-/ramda-0.26.1.tgz",
"integrity": "sha512-hLWjpy7EnsDBb0p+Z3B7rPi3GDeRG5ZtiI33kJhTt+ORCd38AbAIjB/9zRIUoeTbE/AVX5ZkU7m6bznsvrf8eQ=="
},
"random-bytes": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/random-bytes/-/random-bytes-1.0.0.tgz",

View file

@ -38,6 +38,7 @@
"lodash": "^4.17.15",
"mailgun-js": "^0.18.0",
"markdown-it": "^8.4.1",
"markdown-yaml-metadata-parser": "^2.0.3",
"memorystore": "^1.6.1",
"morgan": "latest",
"multer": "latest",