fipamo/brain/api/v1/pages.js
2019-11-23 08:40:51 -08:00

56 lines
1.5 KiB
JavaScript

import DateUtils from '../../../src/com/utils/DateUtils';
import Pages from '../../data/Pages';
import StringUtils from '../../../src/com/utils/StringUtils';
import * as DataEvent from '../../../src/com/events/DataEvent';
import sanitize from 'sanitize-html';
import RightsManager, {
TASK_CREATE,
TASK_UPDATE,
OBJECT_POST
} from '../../../src/com/utils/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.grab().then(result => {
res.json(result);
});
});
module.exports = router;