removed all sequelize declarations... whew...

This commit is contained in:
Ro 2019-11-16 09:10:05 -08:00
parent 006c01f39e
commit dac1193a78
7 changed files with 130 additions and 226 deletions

View file

@ -1,18 +1,17 @@
import DateUtils from '../../tools/utilities/DateUtils'; import DateUtils from '../../utils/tools/DateUtils';
import StringUtils from '../../tools/utilities/StringUtils'; import StringUtils from '../../utils/tools/StringUtils';
import * as DataEvent from '../../tools/events/DataEvent'; import * as DataEvent from '../../utils/events/DataEvent';
import sanitize from 'sanitize-html'; import sanitize from 'sanitize-html';
import RightsManager, { import RightsManager, {
TASK_CREATE, TASK_CREATE,
TASK_UPDATE, TASK_UPDATE,
OBJECT_POST OBJECT_POST
} from '../../tools/utilities/RightsManager'; } from '../../utils/tools/RightsManager';
const express = require('express'); const express = require('express');
const router = express.Router(); const router = express.Router();
const multer = require('multer'); const multer = require('multer');
const md = require('markdown-it')('commonmark'); const md = require('markdown-it')('commonmark');
const fs = require('fs-extra'); 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();
const uploadPath = const uploadPath =
@ -36,6 +35,7 @@ var storage = multer.diskStorage({
cb(null, splice[0]); cb(null, splice[0]);
} }
}); });
var feature_upload = multer({ var feature_upload = multer({
storage: storage storage: storage
}).array('feature_image'); }).array('feature_image');
@ -45,99 +45,9 @@ var post_upload = multer({
//** SYNC POSTS */ //** SYNC POSTS */
router.post('/sync', (req, res) => { router.post('/sync', (req, res) => {
let payload = req.body; 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) { router.get('/json/:filter?', function(req, res) {
var filter = req.params.filter; 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 POST IMAGE

View file

@ -1,16 +1,15 @@
import DateUtils from '../../tools/utilities/DateUtils'; import DateUtils from '../../utils/tools/DateUtils';
import * as DataEvent from '../../tools/events/DataEvent'; import * as DataEvent from '../../utils/events/DataEvent';
import RightsManager, { import RightsManager, {
TASK_CREATE, TASK_CREATE,
TASK_UPDATE, TASK_UPDATE,
OBJECT_POST, OBJECT_POST,
OBJECT_SETTINGS OBJECT_SETTINGS
} from '../../tools/utilities/RightsManager'; } from '../../utils/tools/RightsManager';
const express = require('express'); const express = require('express');
const router = express.Router(); const router = express.Router();
const multer = require('multer'); const multer = require('multer');
const fs = require('fs-extra'); 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();
const uploadPath = const uploadPath =
@ -40,7 +39,6 @@ var background_upload = multer({
//** SYNC POSTS */ //** SYNC POSTS */
router.post('/sync', (req, res) => { router.post('/sync', (req, res) => {
let payload = req.body; let payload = req.body;
Models.User.findById(req.session.user.id).then(user => {
if (rightsManager.check(user.role, OBJECT_SETTINGS, TASK_UPDATE)) { if (rightsManager.check(user.role, OBJECT_SETTINGS, TASK_UPDATE)) {
fs.readJson('config/site-settings.json') fs.readJson('config/site-settings.json')
.then(obj => { .then(obj => {
@ -90,7 +88,6 @@ router.post('/sync', (req, res) => {
}); });
} }
}); });
});
router.get('/nav', function(req, res) { router.get('/nav', function(req, res) {
fs.readJson('config/site-settings.json') fs.readJson('config/site-settings.json')
@ -110,7 +107,6 @@ router.get('/nav', function(req, res) {
router.post('/nav-sync', (req, res) => { router.post('/nav-sync', (req, res) => {
let payload = req.body; let payload = req.body;
Models.User.findById(req.session.user.id).then(user => {
if (rightsManager.check(user.role, OBJECT_SETTINGS, TASK_UPDATE)) { if (rightsManager.check(user.role, OBJECT_SETTINGS, TASK_UPDATE)) {
fs.readJson('config/site-settings.json') fs.readJson('config/site-settings.json')
.then(obj => { .then(obj => {
@ -134,7 +130,6 @@ router.post('/nav-sync', (req, res) => {
}); });
} }
}); });
});
/*** /***
UPLOAD AVATAR UPLOAD AVATAR
@ -145,7 +140,6 @@ router.post('/add-avatar', function(req, res) {
return res.json({ return res.json({
message: 'You need to be logged in, champ.' 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)) { if (rightsManager.check(user.role, OBJECT_POST, TASK_CREATE)) {
avatar_upload(req, res, function(err) { avatar_upload(req, res, function(err) {
if (err) { if (err) {
@ -176,7 +170,6 @@ router.post('/add-avatar', function(req, res) {
}); });
} }
}); });
});
/*** /***
UPLOAD FEATURE BACKGROUND UPLOAD FEATURE BACKGROUND
*/ */
@ -186,7 +179,6 @@ router.post('/add-feature-background', function(req, res) {
return res.json({ return res.json({
message: 'You need to be logged in, champ.' 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)) { if (rightsManager.check(user.role, OBJECT_POST, TASK_CREATE)) {
background_upload(req, res, function(err) { background_upload(req, res, function(err) {
if (err) { if (err) {
@ -208,5 +200,4 @@ router.post('/add-feature-background', function(req, res) {
}); });
} }
}); });
});
module.exports = router; module.exports = router;

View file

@ -41,11 +41,11 @@ app.use(
); );
app.use(flash()); app.use(flash());
//sections //sections
var front = require('./routes/front/index')(session); //var front = require('./routes/front/index')(session);
var back = require('./routes/back/index'); var dash = require('./routes/dash/index');
var postDashboard = require('./routes/back/dash_posts'); var postDashboard = require('./routes/dash/posts');
var settingsDashboard = require('./routes/back/dash_settings'); var settingsDashboard = require('./routes/dash/settings');
var navDashboard = require('./routes/back/dash_nav'); var navDashboard = require('./routes/dash/nav');
//api //api
var postLibrary = require('./api/content/posts'); var postLibrary = require('./api/content/posts');
var settings = require('./api/content/settings'); var settings = require('./api/content/settings');
@ -58,8 +58,8 @@ var auth = require('./api/v1/auth');
app.use('/api/mail', mailer); app.use('/api/mail', mailer);
app.use('/api/v1/auth', auth); app.use('/api/v1/auth', auth);
// PAGES // PAGES
app.use('/', front); //app.use('/', front);
app.use('/@/dashboard', back); app.use('/@/dashboard', dash);
app.use('/@/dashboard/posts', postDashboard); app.use('/@/dashboard/posts', postDashboard);
app.use('/@/dashboard/settings', settingsDashboard); app.use('/@/dashboard/settings', settingsDashboard);
app.use('/@/dashboard/navigation', navDashboard); app.use('/@/dashboard/navigation', navDashboard);

View file

@ -1,4 +1,4 @@
import DateUtils from '../../tools/utilities/DateUtils'; import DateUtils from '../../utils/tools/DateUtils';
var express = require('express'); var express = require('express');
var router = express.Router(); var router = express.Router();
var hljs = require('highlight.js/lib/highlight'); var hljs = require('highlight.js/lib/highlight');
@ -12,8 +12,10 @@ const dateUtils = new DateUtils();
router.get('/list/:filter?/:page?', function(req, res) { router.get('/list/:filter?/:page?', function(req, res) {
var pageNum = req.params.page; var pageNum = req.params.page;
var filter = req.params.filter; var filter = req.params.filter;
if (pageNum == '' || pageNum == null) pageNum = 1; if (pageNum == '' || pageNum == null) pageNum = 1;
if (filter == '' || filter == null) filter = 'all'; if (filter == '' || filter == null) filter = 'all';
/*
if (req.session.user) { if (req.session.user) {
.then(() => { .then(() => {
@ -25,6 +27,7 @@ router.get('/list/:filter?/:page?', function(req, res) {
} else { } else {
res.redirect('/@/dashboard'); res.redirect('/@/dashboard');
} }
*/
}); });
//-------------------------- //--------------------------
// BLOG POST ADD DISPLAY // BLOG POST ADD DISPLAY