|
|
@ -2,6 +2,7 @@ var express = require('express');
|
|
|
|
import DateUtils from '../../tools/utilities/DateUtils';
|
|
|
|
import DateUtils from '../../tools/utilities/DateUtils';
|
|
|
|
import StringUtils from '../../tools/utilities/StringUtils';
|
|
|
|
import StringUtils from '../../tools/utilities/StringUtils';
|
|
|
|
import * as DataEvent from '../../tools/events/DataEvent';
|
|
|
|
import * as DataEvent from '../../tools/events/DataEvent';
|
|
|
|
|
|
|
|
import sanitize from 'sanitize-html';
|
|
|
|
import RightsManager,
|
|
|
|
import RightsManager,
|
|
|
|
{
|
|
|
|
{
|
|
|
|
TASK_CREATE,
|
|
|
|
TASK_CREATE,
|
|
|
@ -16,16 +17,17 @@ import RightsManager,
|
|
|
|
OBJECT_POST
|
|
|
|
OBJECT_POST
|
|
|
|
}
|
|
|
|
}
|
|
|
|
from '../../tools/utilities/RightsManager';
|
|
|
|
from '../../tools/utilities/RightsManager';
|
|
|
|
var router = express.Router();
|
|
|
|
const router = express.Router();
|
|
|
|
var multer = require('multer');
|
|
|
|
const multer = require('multer');
|
|
|
|
var fs = require('fs-extra');
|
|
|
|
const md = require('markdown-it')('commonmark');
|
|
|
|
var Models = require('../../models');
|
|
|
|
const fs = require('fs-extra');
|
|
|
|
|
|
|
|
const Models = require('../../models');
|
|
|
|
const dateUtils = new DateUtils();
|
|
|
|
const dateUtils = new DateUtils();
|
|
|
|
const rightsManager = new RightsManager();
|
|
|
|
const rightsManager = new RightsManager();
|
|
|
|
var uploadPath = "./content/blog-images/" + dateUtils.getDate('year', new Date()) + "/" + dateUtils.getDate('month', new Date());
|
|
|
|
const uploadPath = "./content/blog-images/" + dateUtils.getDate('year', new Date()) + "/" + dateUtils.getDate('month', new Date());
|
|
|
|
var Sequelize = require('sequelize');
|
|
|
|
const Sequelize = require('sequelize');
|
|
|
|
const Op = Sequelize.Op;
|
|
|
|
const Op = Sequelize.Op;
|
|
|
|
var _ = require('lodash');
|
|
|
|
const _ = require('lodash');
|
|
|
|
fs.ensureDir(uploadPath, function(err)
|
|
|
|
fs.ensureDir(uploadPath, function(err)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
//console.log(err) // => null
|
|
|
|
//console.log(err) // => null
|
|
|
@ -76,6 +78,23 @@ router.post("/sync", (req, res, next) =>
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}).then(found =>
|
|
|
|
}).then(found =>
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
let buffed = sanitize(item.post.plaintext,
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
allowedTags: ['del', 'a', 'iframe', 'img', ],
|
|
|
|
|
|
|
|
allowedAttributes:
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
a: ['href', 'name', 'target'],
|
|
|
|
|
|
|
|
img: ['src'],
|
|
|
|
|
|
|
|
iframe: ['height', 'width', 'src', 'frameborder', 'allow', 'allowfullscreen']
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
buffed = new StringUtils().decodeHTML(buffed);
|
|
|
|
|
|
|
|
item.post.plaintext = buffed;
|
|
|
|
|
|
|
|
item.post.html = md.render(buffed,
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
html: true,
|
|
|
|
|
|
|
|
xhtmlOut: true,
|
|
|
|
|
|
|
|
})
|
|
|
|
if (!_.isEqual(item.post, found.post))
|
|
|
|
if (!_.isEqual(item.post, found.post))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
found.update(item).then(updated =>
|
|
|
|
found.update(item).then(updated =>
|
|
|
@ -122,16 +141,17 @@ router.get('/json', function(req, res, next)
|
|
|
|
}).then(function(posts)
|
|
|
|
}).then(function(posts)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
let newlist = [];
|
|
|
|
let newlist = [];
|
|
|
|
|
|
|
|
for (let index = 0; index < posts.length; index++)
|
|
|
|
for (let index = 0; index < posts.length; index++) {
|
|
|
|
{
|
|
|
|
let item = posts[index].post;
|
|
|
|
let item = posts[index].post;
|
|
|
|
if(typeof item.deleted == 'undefined' || item.deleted == false)
|
|
|
|
if (typeof item.deleted == 'undefined' || item.deleted == false)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
newlist.push(posts[index])
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
{
|
|
|
|
{
|
|
|
|
newlist.push(posts[index])
|
|
|
|
|
|
|
|
}else{
|
|
|
|
|
|
|
|
continue
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
res.json(newlist)
|
|
|
|
res.json(newlist)
|
|
|
|
}).catch(function(err)
|
|
|
|
}).catch(function(err)
|
|
|
@ -184,7 +204,6 @@ router.post('/add-post-image', function(req, res, next)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
router.post('/add-feature-image', function(req, res, next)
|
|
|
|
router.post('/add-feature-image', function(req, res, next)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
//console.log(req.body);
|
|
|
|
//console.log(req.body);
|
|
|
|