started removing all postgress dependencies

This commit is contained in:
Ro 2019-11-10 12:07:29 -08:00
parent 255c70d403
commit 327cb7a25d
14 changed files with 8 additions and 623 deletions

View file

@ -2,7 +2,6 @@ const express = require('express');
const router = express.Router(); const router = express.Router();
const bCrypt = require('bcrypt-nodejs'); const bCrypt = require('bcrypt-nodejs');
const jwt = require('jsonwebtoken'); const jwt = require('jsonwebtoken');
const Models = require('../../models');
/** /**
* Get Auth Status * Get Auth Status
@ -22,6 +21,7 @@ router.get('/', function(req, res) {
* Login Member and return token * Login Member and return token
*/ */
router.post('/login', function(req, res) { router.post('/login', function(req, res) {
/**
Models.User.findOne({ Models.User.findOne({
where: { where: {
handle: req.body.handle handle: req.body.handle
@ -49,6 +49,7 @@ router.post('/login', function(req, res) {
message: 'NOT FOUND, HAWS' message: 'NOT FOUND, HAWS'
}); });
}); });
**/
}); });
//router.post('/logout', function(req, res) {}); //router.post('/logout', function(req, res) {});

View file

@ -1,37 +0,0 @@
module.exports = function(sequelize, DataTypes) {
var FreshPost = sequelize.define(
'FreshPost',
{
post: {
type: DataTypes.JSONB
}
},
{
timestamps: false,
// don't delete database entries but set the newly added attribute deletedAt
// to the current date (when deletion was done). paranoid will only work if
// timestamps are enabled
paranoid: false,
// don't use camelcase for automatically added attributes but underscore style
// so updatedAt will be updated_at
underscored: true,
// disable the modification of table names; By default, sequelize will automatically
// transform all passed model names (first parameter of define) into plural.
// if you don't want that, set the following
freezeTableName: false,
// define the table's name
tableName: 'FreshPosts',
// Enable optimistic locking. When enabled, sequelize will add a version count attriubte
// to the model and throw an OptimisticLockingError error when stale instances are saved.
// Set to true or a string with the attribute name you want to use to enable.
version: false
}
);
return FreshPost;
};

View file

@ -1,84 +0,0 @@
module.exports = function (sequelize, DataTypes) {
var Post = sequelize.define('Post', {
uuid: {
type: DataTypes.STRING(50),
unique: true,
allowNull: false
},
title: {
type: DataTypes.STRING(500),
allowNull: true
},
slug: {
type: DataTypes.STRING(500),
unique: false,
allowNull: true
},
tags: {
type: DataTypes.STRING(2000),
unique: false,
allowNull: true
},
entry_html: {
type: DataTypes.TEXT,
unique: false,
allowNull: true
},
entry_plaintext: {
type: DataTypes.TEXT,
unique: false,
allowNull: true
},
feature_image: {
type: DataTypes.STRING,
unique: false,
allowNull: true
},
page: {
type: DataTypes.BOOLEAN,
unique: false,
allowNull: true
},
featured: {
type: DataTypes.BOOLEAN,
unique: false,
allowNull: true
},
author_id: {
type: DataTypes.INTEGER,
unique: false,
allowNull: true
},
origin_date: {
type: DataTypes.INTEGER,
unique: false,
allowNull: true
}
}, {
timestamps: true,
// don't delete database entries but set the newly added attribute deletedAt
// to the current date (when deletion was done). paranoid will only work if
// timestamps are enabled
paranoid: true,
// don't use camelcase for automatically added attributes but underscore style
// so updatedAt will be updated_at
underscored: true,
// disable the modification of table names; By default, sequelize will automatically
// transform all passed model names (first parameter of define) into plural.
// if you don't want that, set the following
freezeTableName: false,
// define the table's name
tableName: 'Posts',
// Enable optimistic locking. When enabled, sequelize will add a version count attriubte
// to the model and throw an OptimisticLockingError error when stale instances are saved.
// Set to true or a string with the attribute name you want to use to enable.
version: true
});
return Post;
};

View file

@ -1,55 +0,0 @@
module.exports = function (sequelize, DataTypes) {
var User = sequelize.define('User', {
avatar: {
type: DataTypes.STRING,
unique: false,
allowNull: true
},
handle: {
type: DataTypes.STRING,
unique: true,
allowNull: true
},
email: {
type: DataTypes.STRING,
unique: false,
allowNull: true
},
role: {
type: DataTypes.STRING,
unique: false,
allowNull: true
},
password: {
type: DataTypes.STRING,
unique: true,
allowNull: false
}
}, {
timestamps: true,
// don't delete database entries but set the newly added attribute deletedAt
// to the current date (when deletion was done). paranoid will only work if
// timestamps are enabled
paranoid: true,
// don't use camelcase for automatically added attributes but underscore style
// so updatedAt will be updated_at
underscored: true,
// disable the modification of table names; By default, sequelize will automatically
// transform all passed model names (first parameter of define) into plural.
// if you don't want that, set the following
freezeTableName: false,
// define the table's name
tableName: 'Users',
// Enable optimistic locking. When enabled, sequelize will add a version count attriubte
// to the model and throw an OptimisticLockingError error when stale instances are saved.
// Set to true or a string with the attribute name you want to use to enable.
version: true
});
return User;
};

View file

@ -1,36 +0,0 @@
'use strict';
const fs = require('fs');
const path = require('path');
const Sequelize = require('sequelize');
const basename = path.basename(__filename);
const env = process.env.NODE_ENV || 'development';
const config = require(__dirname + '/../../config/config.json')[env];
const db = {};
let sequelize;
if (config.use_env_variable) {
sequelize = new Sequelize(process.env[config.use_env_variable], config);
} else {
sequelize = new Sequelize(config.database, config.username, config.password, config);
}
fs.readdirSync(__dirname)
.filter(file => {
return file.indexOf('.') !== 0 && file !== basename && file.slice(-3) === '.js';
})
.forEach(file => {
const model = sequelize['import'](path.join(__dirname, file));
db[model.name] = model;
});
Object.keys(db).forEach(modelName => {
if (db[modelName].associate) {
db[modelName].associate(db);
}
});
db.sequelize = sequelize;
db.Sequelize = Sequelize;
module.exports = db;

View file

@ -1,6 +1,5 @@
const express = require('express'); const express = require('express');
const router = express.Router(); const router = express.Router();
const Models = require('../../models');
const fs = require('fs-extra'); const fs = require('fs-extra');
const _ = require('lodash'); const _ = require('lodash');
var settings = []; var settings = [];
@ -17,64 +16,6 @@ router.get('/', function(req, res) {
//console.error(err) //console.error(err)
}); });
if (req.session.user) { if (req.session.user) {
Models.User.findById(req.session.user.id).then(() => {
Models.FreshPost.findAll({
order: [['id', 'DESC']]
})
.then(posts => {
let pages = [];
if (settings.menu.length == 0) {
for (let index = 0; index < posts.length; index++) {
let item = posts[index].post;
if (item.page == true || item.page == 'true')
pages.push({
id: posts[index].id,
uuid: posts[index].post.uuid,
title: posts[index].post.title,
slug: posts[index].post.slug
});
}
} else {
let newpages = [];
pages = settings.menu;
for (let index = 0; index < posts.length; index++) {
let item = posts[index].post;
if (item.page == true || item.page == 'true')
newpages.push({
id: posts[index].id,
uuid: posts[index].post.uuid,
title: posts[index].post.title,
slug: posts[index].post.slug
});
}
for (let i = 0; i < newpages.length; i++) {
if (
_.findIndex(pages, function(o) {
return o.id == newpages[i].id;
}) != -1
) {
//console.log("FOUND")
} else {
pages.push({
id: newpages[i].id,
uuid: newpages[i].uuid,
title: newpages[i].title,
slug: newpages[i].slug
});
}
}
}
res.render('dash/navigation', {
pages: pages,
welcome: 'Edit Navigation',
user_status: true,
title: 'Dashboard | Navigation'
});
})
.catch(() => {
//console.log('ERROR', err);
});
});
} else { } else {
res.redirect('/@/dashboard'); res.redirect('/@/dashboard');
} }

View file

@ -1,12 +1,10 @@
import DateUtils from '../../tools/utilities/DateUtils'; import DateUtils from '../../tools/utilities/DateUtils';
var express = require('express'); var express = require('express');
var router = express.Router(); var router = express.Router();
var Models = require('../../models');
var hljs = require('highlight.js/lib/highlight'); var hljs = require('highlight.js/lib/highlight');
var hljs_md = require('highlight.js/lib/languages/markdown'); var hljs_md = require('highlight.js/lib/languages/markdown');
hljs.registerLanguage('markdown', hljs_md); hljs.registerLanguage('markdown', hljs_md);
var Sequelize = require('sequelize'); var Sequelize = require('sequelize');
const Op = Sequelize.Op;
const dateUtils = new DateUtils(); const dateUtils = new DateUtils();
//-------------------------- //--------------------------
// POSTS // POSTS
@ -17,69 +15,7 @@ router.get('/list/:filter?/:page?', function(req, res) {
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) {
Models.FreshPost.findAll({
order: [['id', 'DESC']]
})
.then(function(posts) {
let all = [];
let deleted = [];
let published = [];
let pages = [];
let featured = [];
for (let index = 0; index < posts.length; index++) {
let item = posts[index].post;
if (typeof item.deleted == 'undefined' || item.deleted == false) {
all.push(posts[index]);
if (item.published == 'true') published.push(posts[index]);
if (item.page == 'true') pages.push(posts[index]);
if (item.featured == 'true') featured.push(posts[index]);
} else {
deleted.push(posts[index]);
}
}
var filtered;
switch (filter) {
case 'published':
filtered = published;
break;
case 'deleted':
filtered = deleted;
break;
default:
filtered = all;
break;
}
var count = Math.round(filtered.length / 6);
var pageItems = [];
var itemLimit = 6;
var rangeStart = pageNum * itemLimit - itemLimit;
for (var i = 0; i < itemLimit; i++) {
try {
if (filtered[i + rangeStart].id != null) {
pageItems.push(filtered[i + rangeStart]);
}
} catch (e) {
//console.log("NO POST", e)
}
}
res.render('dash/posts-index', {
title: 'Dashbord | Posts',
mode: 'admin',
welcome: 'Your Posts',
items: pageItems,
page_info: {
all: all.length,
deleted: deleted.length,
published: published.length,
pages: pages.length,
featured: featured.length
},
page_index: pageNum,
page_count: count,
postFilter: filter,
user_status: true
});
})
.then(() => { .then(() => {
//console.log(value); //console.log(value);
}) })
@ -118,52 +54,7 @@ router.get('/add/new', function(req, res) {
//-------------------------- //--------------------------
router.get('/edit/:id', function(req, res) { router.get('/edit/:id', function(req, res) {
if (req.session.user) { if (req.session.user) {
Models.FreshPost.findOne({ } else {
where: {
post: {
[Op.contains]: {
uuid: req.params.id
}
}
}
})
.then(item => {
let featured = 'null';
if (item.post.feature != null || item.post.feature != '')
featured = item.post.feature.substr(8, item.post.feature.length);
let pretty = hljs.highlight('markdown', item.post.plaintext).value;
let sexydate =
dateUtils.getDate('year', item.post.created) +
'-' +
dateUtils.getDate('month', item.post.created) +
'-' +
dateUtils.getDate('day', item.post.created);
res.render('dash/post-edit', {
id: item.id,
title: 'Edit Post',
user_status: true,
welcome: 'Edit Post',
mode: 'admin',
post: item.post,
date: sexydate,
colored: pretty,
html: item.post.plaintext,
feature: featured,
status: [
String(item.post.page),
String(item.post.featured),
String(item.post.published)
],
edit: true
});
})
.then(() => {
//console.log("VALUE: " + value);
})
.catch(() => {
//console.log(err);
});
} else {
res.redirect('/@/dashboard'); res.redirect('/@/dashboard');
} }
}); });

View file

@ -1,7 +1,6 @@
const express = require('express'); const express = require('express');
const router = express.Router(); const router = express.Router();
const FileHound = require('filehound'); const FileHound = require('filehound');
const Models = require('../../models');
const fs = require('fs-extra'); const fs = require('fs-extra');
var settings = []; var settings = [];
//-------------------------- //--------------------------
@ -42,26 +41,6 @@ router.get('/', function(req, res) {
}); });
if (req.session.user) { if (req.session.user) {
let memberInfo = []; let memberInfo = [];
Models.User.findById(req.session.user.id).then(user => {
memberInfo.push({
handle: user.handle,
email: user.email,
avi: user.avatar
});
themes.sort(function(a, b) {
var textA = a.theme.name.toUpperCase();
var textB = b.theme.name.toUpperCase();
return textA < textB ? -1 : textA > textB ? 1 : 0;
});
res.render('dash/settings', {
title: 'Dashboard | Settings',
welcome: 'Your Settings',
user_status: true,
themes: themes,
settings: settings,
member: memberInfo[0]
});
});
} else { } else {
res.redirect('/@/dashboard'); res.redirect('/@/dashboard');
} }

View file

@ -1,44 +1,9 @@
const express = require('express'); const express = require('express');
const router = express.Router(); const router = express.Router();
const Models = require('../../models');
//-------------------------- //--------------------------
// Index // Index
//-------------------------- //--------------------------
router.get('/', function(req, res) { router.get('/', function(req, res) {});
var loggedIn = false;
if (req.session.user) loggedIn = true;
Models.FreshPost.findAll({
order: [['id', 'DESC']]
})
.then(function(posts) {
let title = 'Fipamo Dashboard';
let welcome = '';
!loggedIn
? (welcome = 'Hello.')
: (welcome = 'Welcome back, ' + req.session.user.handle);
let filtered = [];
for (let index = 0; index < posts.length; index++) {
let item = posts[index].post;
if (typeof item.deleted == 'undefined' || item.deleted == false) {
filtered.push(posts[index]);
} else {
continue;
}
}
res.render('dash/index', {
title: title,
welcome: welcome,
user_status: loggedIn,
items: filtered
});
})
.then(() => {
//console.log(value);
})
.catch(() => {
//next(err);
});
});
//-------------------------- //--------------------------
// Logout // Logout

View file

@ -1,46 +0,0 @@
var express = require('express');
var router = express.Router();
var Models = require('../../models');
var config = require('../../../config.json');
router.get('/:page_num?', function (req, res) {
var page_num = req.params.page_num;
var pageNum = page_num;
if (page_num == null)
pageNum = 1
Models.Bookmark.findAll({
order: [['id', 'DESC']]
}).then(function (bookmarks) {
//console.log("num: "+pageNum);
//real page count
var count = Math.floor(bookmarks.length / 10);
var pageItems = [];
var itemLimit = 10;
var rangeStart = (pageNum * itemLimit) - itemLimit;
//console.log("RANGE START "+rangeStart);
for (var i = 0; i < itemLimit; i++) {
try {
if (bookmarks[i + rangeStart].id != null) {
//console.log(bookmarks[i+rangeStart]._id )
pageItems.push(bookmarks[i + rangeStart]);
}
} catch (e) {
//console.log(e)
}
}
//console.log("items count: "+pageItems.length)
res.render(config.theme+'/fipamo', {
theme: config.theme,
title: 'The Twelfth House | Fipamo',
page_index: pageNum,
page_count: Math.round(bookmarks.length / 10),
items: pageItems,
mode: 'bookmarks'
});
}).then(function (value) {
//console.log(value);
}).catch(function (err) {
console.log(err);
})
});
router.get('/:id', function (req, res) {});
module.exports = router;

View file

@ -1,17 +0,0 @@
var express = require('express');
var router = express.Router();
//var Models = require('../../models');
var config = require('../../../config/site-settings.json');
module.exports = function() {
//--------------------------
// Index
//--------------------------
router.get('/:page?', function(req, res) {
res.render(config.theme + '/index', {
theme: config.theme,
title: config.title,
user_status: 'What up, random person'
});
});
return router;
};

View file

@ -1,68 +0,0 @@
var express = require('express');
var router = express.Router();
var Models = require('../../models');
var config = require('../../../config.json');
router.get('/', function(req, res) {
res.redirect('/blog/page/1');
});
router.get('/page/:page_num?', function (req, res) {
var page_num = req.params.page_num;
var pageNum = page_num;
if (page_num == null)
pageNum = 1
Models.Post.findAll({
order: [['id', 'DESC']]
}).then(function (post) {
//console.log("num: "+pageNum);
//real page count
var count = Math.floor(post.length / 6);
var pageItems = [];
var itemLimit = 6;
var rangeStart = (pageNum * itemLimit) - itemLimit;
//console.log("RANGE START "+rangeStart);
for (var i = 0; i < itemLimit; i++) {
try {
if (post[i + rangeStart].id != null) {
pageItems.push(post[i + rangeStart]);
}
} catch (e) {
//console.log(e)
}
}
//console.log("items count: "+pageItems.length)
res.render(config.theme+'/blog', {
theme: config.theme,
title: 'The Twelfth House | Thoughts and Such',
page_index: pageNum,
page_count: Math.round(post.length / 6),
items: pageItems,
mode: 'blog'
});
}).then(function (value) {
//console.log(value);
}).catch(function (err) {
console.log(err);
})
});
router.get('/:id', function(req, res) {
Models.Post.findOne({where:{slug: req.params.id}}).then((post) => {
console.log(post.feature_image)
res.render(config.theme+'/blog-post', {
theme: config.theme,
title: post.title,
entry: post.entry_html,
feature_image: JSON.parse(post.feature_image),
mode:'blog'
});
}).catch((err) => {
console.log(err);
});
});
module.exports = router;

View file

@ -1,37 +0,0 @@
var express = require('express');
var router = express.Router();
var Models = require('../../models');
var config = require('../../../config.json');
router.get('/', function(req, res) {
Models.FolioProject.findAll({order:[['sortIndex', 'DESC']]}).then(projects=> {
res.render(config.theme+'/work', {
theme: config.theme,
title: 'The Twelfth House | Creative Works and Projects',
projects: projects,
mode: 'projects'
});
}).then(function(value) {
//console.log(value);
}).catch(function(err) {
//next(err);
})
});
router.get('/:id', function(req, res) {
Models.FolioProject.findOne({where:{slug: req.params.id}}).then((project) => {
res.render(config.theme+'/work-project', {
title: project.title,
type: project.type,
desc: project.description,
images: JSON.parse(project.images),
mode:'folio',
url:project.url
});
}).catch((err) => {
console.log(err);
});
});
module.exports = router;

18
init.js
View file

@ -7,7 +7,6 @@
var app = require('./brain/app'); var app = require('./brain/app');
var debug = require('debug')('fipamo:server'); var debug = require('debug')('fipamo:server');
var http = require('http'); var http = require('http');
var models = require('./brain/models');
/** /**
* Get port from environment and store in Express. * Get port from environment and store in Express.
@ -25,20 +24,9 @@ var server = http.createServer(app);
* Listen on provided port, on all network interfaces. * Listen on provided port, on all network interfaces.
*/ */
//server.listen(port); server.listen(port);
//server.on('error', onError); server.on('error', onError);
//server.on('listening', onListening); server.on('listening', onListening);
models.sequelize.sync().then(function() {
/**
* Listen on provided port, on all network interfaces.
*/
server.listen(port, function() {
debug('Express server listening on port ' + server.address().port);
});
server.on('error', onError);
server.on('listening', onListening);
});
/** /**
* Normalize a port into a number, string, or false. * Normalize a port into a number, string, or false.