removed all sequelize declarations... whew...
This commit is contained in:
parent
006c01f39e
commit
dac1193a78
7 changed files with 130 additions and 226 deletions
|
@ -1,18 +1,17 @@
|
|||
import DateUtils from '../../tools/utilities/DateUtils';
|
||||
import StringUtils from '../../tools/utilities/StringUtils';
|
||||
import * as DataEvent from '../../tools/events/DataEvent';
|
||||
import DateUtils from '../../utils/tools/DateUtils';
|
||||
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 '../../tools/utilities/RightsManager';
|
||||
} 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 Models = require('../../models');
|
||||
const dateUtils = new DateUtils();
|
||||
const rightsManager = new RightsManager();
|
||||
const uploadPath =
|
||||
|
@ -36,6 +35,7 @@ var storage = multer.diskStorage({
|
|||
cb(null, splice[0]);
|
||||
}
|
||||
});
|
||||
|
||||
var feature_upload = multer({
|
||||
storage: storage
|
||||
}).array('feature_image');
|
||||
|
@ -45,99 +45,9 @@ var post_upload = multer({
|
|||
//** SYNC POSTS */
|
||||
router.post('/sync', (req, res) => {
|
||||
let payload = req.body;
|
||||
Models.User.findById(req.session.user.id).then(user => {
|
||||
if (rightsManager.check(user.role, OBJECT_POST, TASK_UPDATE)) {
|
||||
for (let index = 0; index < payload.length; index++) {
|
||||
const item = payload[index];
|
||||
Models.FreshPost.findOne({
|
||||
where: {
|
||||
post: {
|
||||
[Op.contains]: {
|
||||
uuid: item.post.uuid
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
.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)) {
|
||||
found
|
||||
.update(item)
|
||||
.then(() => {
|
||||
//console.log('UPDATED', updated);
|
||||
})
|
||||
.catch(() => {
|
||||
//console.log("***ERROR***", err);
|
||||
});
|
||||
} else {
|
||||
//chilld
|
||||
}
|
||||
})
|
||||
.catch(() => {
|
||||
//console.log("***ERRRORZ****", err);
|
||||
Models.FreshPost.create(item).then(() => {
|
||||
//console.log(fresh)
|
||||
});
|
||||
});
|
||||
}
|
||||
res.json({
|
||||
message: 'postsSynced'
|
||||
});
|
||||
} else {
|
||||
res.json({
|
||||
message: "Nah. You can't do that. Talk to the admin, sport."
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
router.get('/json/:filter?', function(req, res) {
|
||||
var filter = req.params.filter;
|
||||
Models.FreshPost.findAll({
|
||||
order: [['id', 'DESC']]
|
||||
})
|
||||
.then(function(posts) {
|
||||
let newlist = [];
|
||||
for (let index = 0; index < posts.length; index++) {
|
||||
let item = posts[index].post;
|
||||
switch (filter) {
|
||||
case 'not-deleted':
|
||||
if (typeof item.deleted == 'undefined' || item.deleted == false) {
|
||||
newlist.push(posts[index]);
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
newlist.push(posts[index]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
res.json(newlist);
|
||||
})
|
||||
.catch(() => {
|
||||
//next(err);
|
||||
});
|
||||
});
|
||||
/***
|
||||
POST IMAGE
|
||||
|
|
|
@ -1,16 +1,15 @@
|
|||
import DateUtils from '../../tools/utilities/DateUtils';
|
||||
import * as DataEvent from '../../tools/events/DataEvent';
|
||||
import DateUtils from '../../utils/tools/DateUtils';
|
||||
import * as DataEvent from '../../utils/events/DataEvent';
|
||||
import RightsManager, {
|
||||
TASK_CREATE,
|
||||
TASK_UPDATE,
|
||||
OBJECT_POST,
|
||||
OBJECT_SETTINGS
|
||||
} from '../../tools/utilities/RightsManager';
|
||||
} from '../../utils/tools/RightsManager';
|
||||
const express = require('express');
|
||||
const router = express.Router();
|
||||
const multer = require('multer');
|
||||
const fs = require('fs-extra');
|
||||
const Models = require('../../models');
|
||||
const dateUtils = new DateUtils();
|
||||
const rightsManager = new RightsManager();
|
||||
const uploadPath =
|
||||
|
@ -40,7 +39,6 @@ var background_upload = multer({
|
|||
//** SYNC POSTS */
|
||||
router.post('/sync', (req, res) => {
|
||||
let payload = req.body;
|
||||
Models.User.findById(req.session.user.id).then(user => {
|
||||
if (rightsManager.check(user.role, OBJECT_SETTINGS, TASK_UPDATE)) {
|
||||
fs.readJson('config/site-settings.json')
|
||||
.then(obj => {
|
||||
|
@ -90,7 +88,6 @@ router.post('/sync', (req, res) => {
|
|||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
router.get('/nav', function(req, res) {
|
||||
fs.readJson('config/site-settings.json')
|
||||
|
@ -110,7 +107,6 @@ router.get('/nav', function(req, res) {
|
|||
|
||||
router.post('/nav-sync', (req, res) => {
|
||||
let payload = req.body;
|
||||
Models.User.findById(req.session.user.id).then(user => {
|
||||
if (rightsManager.check(user.role, OBJECT_SETTINGS, TASK_UPDATE)) {
|
||||
fs.readJson('config/site-settings.json')
|
||||
.then(obj => {
|
||||
|
@ -134,7 +130,6 @@ router.post('/nav-sync', (req, res) => {
|
|||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
/***
|
||||
UPLOAD AVATAR
|
||||
|
@ -145,7 +140,6 @@ router.post('/add-avatar', function(req, res) {
|
|||
return res.json({
|
||||
message: 'You need to be logged in, champ.'
|
||||
});
|
||||
Models.User.findById(req.session.user.id).then(user => {
|
||||
if (rightsManager.check(user.role, OBJECT_POST, TASK_CREATE)) {
|
||||
avatar_upload(req, res, function(err) {
|
||||
if (err) {
|
||||
|
@ -176,7 +170,6 @@ router.post('/add-avatar', function(req, res) {
|
|||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
/***
|
||||
UPLOAD FEATURE BACKGROUND
|
||||
*/
|
||||
|
@ -186,7 +179,6 @@ router.post('/add-feature-background', function(req, res) {
|
|||
return res.json({
|
||||
message: 'You need to be logged in, champ.'
|
||||
});
|
||||
Models.User.findById(req.session.user.id).then(user => {
|
||||
if (rightsManager.check(user.role, OBJECT_POST, TASK_CREATE)) {
|
||||
background_upload(req, res, function(err) {
|
||||
if (err) {
|
||||
|
@ -208,5 +200,4 @@ router.post('/add-feature-background', function(req, res) {
|
|||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
module.exports = router;
|
||||
|
|
14
brain/app.js
14
brain/app.js
|
@ -41,11 +41,11 @@ app.use(
|
|||
);
|
||||
app.use(flash());
|
||||
//sections
|
||||
var front = require('./routes/front/index')(session);
|
||||
var back = require('./routes/back/index');
|
||||
var postDashboard = require('./routes/back/dash_posts');
|
||||
var settingsDashboard = require('./routes/back/dash_settings');
|
||||
var navDashboard = require('./routes/back/dash_nav');
|
||||
//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');
|
||||
//api
|
||||
var postLibrary = require('./api/content/posts');
|
||||
var settings = require('./api/content/settings');
|
||||
|
@ -58,8 +58,8 @@ var auth = require('./api/v1/auth');
|
|||
app.use('/api/mail', mailer);
|
||||
app.use('/api/v1/auth', auth);
|
||||
// PAGES
|
||||
app.use('/', front);
|
||||
app.use('/@/dashboard', back);
|
||||
//app.use('/', front);
|
||||
app.use('/@/dashboard', dash);
|
||||
app.use('/@/dashboard/posts', postDashboard);
|
||||
app.use('/@/dashboard/settings', settingsDashboard);
|
||||
app.use('/@/dashboard/navigation', navDashboard);
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import DateUtils from '../../tools/utilities/DateUtils';
|
||||
import DateUtils from '../../utils/tools/DateUtils';
|
||||
var express = require('express');
|
||||
var router = express.Router();
|
||||
var hljs = require('highlight.js/lib/highlight');
|
||||
|
@ -12,8 +12,10 @@ 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';
|
||||
/*
|
||||
if (req.session.user) {
|
||||
|
||||
.then(() => {
|
||||
|
@ -25,6 +27,7 @@ router.get('/list/:filter?/:page?', function(req, res) {
|
|||
} else {
|
||||
res.redirect('/@/dashboard');
|
||||
}
|
||||
*/
|
||||
});
|
||||
//--------------------------
|
||||
// BLOG POST ADD DISPLAY
|
Loading…
Reference in a new issue