From 327cb7a25d3f54996f8163e6d0cf0912fb43e881 Mon Sep 17 00:00:00 2001 From: Ro Date: Sun, 10 Nov 2019 12:07:29 -0800 Subject: [PATCH] started removing all postgress dependencies --- brain/api/v1/auth.js | 3 +- brain/models/FreshPosts.js | 37 ---------- brain/models/Post.js | 84 --------------------- brain/models/User.js | 55 -------------- brain/models/index.js | 36 --------- brain/routes/back/dash_nav.js | 59 --------------- brain/routes/back/dash_posts.js | 113 +---------------------------- brain/routes/back/dash_settings.js | 21 ------ brain/routes/back/index.js | 37 +--------- brain/routes/front/fipamo.js | 46 ------------ brain/routes/front/index.js | 17 ----- brain/routes/front/post.js | 68 ----------------- brain/routes/front/work.js | 37 ---------- init.js | 18 +---- 14 files changed, 8 insertions(+), 623 deletions(-) delete mode 100644 brain/models/FreshPosts.js delete mode 100644 brain/models/Post.js delete mode 100644 brain/models/User.js delete mode 100644 brain/models/index.js delete mode 100644 brain/routes/front/fipamo.js delete mode 100644 brain/routes/front/index.js delete mode 100644 brain/routes/front/post.js delete mode 100644 brain/routes/front/work.js diff --git a/brain/api/v1/auth.js b/brain/api/v1/auth.js index f986755..134139e 100644 --- a/brain/api/v1/auth.js +++ b/brain/api/v1/auth.js @@ -2,7 +2,6 @@ const express = require('express'); const router = express.Router(); const bCrypt = require('bcrypt-nodejs'); const jwt = require('jsonwebtoken'); -const Models = require('../../models'); /** * Get Auth Status @@ -22,6 +21,7 @@ router.get('/', function(req, res) { * Login Member and return token */ router.post('/login', function(req, res) { + /** Models.User.findOne({ where: { handle: req.body.handle @@ -49,6 +49,7 @@ router.post('/login', function(req, res) { message: 'NOT FOUND, HAWS' }); }); + **/ }); //router.post('/logout', function(req, res) {}); diff --git a/brain/models/FreshPosts.js b/brain/models/FreshPosts.js deleted file mode 100644 index a23c1fe..0000000 --- a/brain/models/FreshPosts.js +++ /dev/null @@ -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; -}; diff --git a/brain/models/Post.js b/brain/models/Post.js deleted file mode 100644 index 76faa6a..0000000 --- a/brain/models/Post.js +++ /dev/null @@ -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; -}; diff --git a/brain/models/User.js b/brain/models/User.js deleted file mode 100644 index 7ce96b1..0000000 --- a/brain/models/User.js +++ /dev/null @@ -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; -}; diff --git a/brain/models/index.js b/brain/models/index.js deleted file mode 100644 index dcc27cc..0000000 --- a/brain/models/index.js +++ /dev/null @@ -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; diff --git a/brain/routes/back/dash_nav.js b/brain/routes/back/dash_nav.js index 253d232..e4410a9 100644 --- a/brain/routes/back/dash_nav.js +++ b/brain/routes/back/dash_nav.js @@ -1,6 +1,5 @@ const express = require('express'); const router = express.Router(); -const Models = require('../../models'); const fs = require('fs-extra'); const _ = require('lodash'); var settings = []; @@ -17,64 +16,6 @@ router.get('/', function(req, res) { //console.error(err) }); 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 { res.redirect('/@/dashboard'); } diff --git a/brain/routes/back/dash_posts.js b/brain/routes/back/dash_posts.js index 29bc8cf..fd14a9a 100644 --- a/brain/routes/back/dash_posts.js +++ b/brain/routes/back/dash_posts.js @@ -1,12 +1,10 @@ import DateUtils from '../../tools/utilities/DateUtils'; var express = require('express'); var router = express.Router(); -var Models = require('../../models'); var hljs = require('highlight.js/lib/highlight'); var hljs_md = require('highlight.js/lib/languages/markdown'); hljs.registerLanguage('markdown', hljs_md); var Sequelize = require('sequelize'); -const Op = Sequelize.Op; const dateUtils = new DateUtils(); //-------------------------- // POSTS @@ -17,69 +15,7 @@ router.get('/list/:filter?/:page?', function(req, res) { if (pageNum == '' || pageNum == null) pageNum = 1; if (filter == '' || filter == null) filter = 'all'; 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(() => { //console.log(value); }) @@ -118,52 +54,7 @@ router.get('/add/new', function(req, res) { //-------------------------- router.get('/edit/:id', function(req, res) { if (req.session.user) { - Models.FreshPost.findOne({ - 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 { + } else { res.redirect('/@/dashboard'); } }); diff --git a/brain/routes/back/dash_settings.js b/brain/routes/back/dash_settings.js index c374d1e..9b51bbe 100644 --- a/brain/routes/back/dash_settings.js +++ b/brain/routes/back/dash_settings.js @@ -1,7 +1,6 @@ const express = require('express'); const router = express.Router(); const FileHound = require('filehound'); -const Models = require('../../models'); const fs = require('fs-extra'); var settings = []; //-------------------------- @@ -42,26 +41,6 @@ router.get('/', function(req, res) { }); if (req.session.user) { 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 { res.redirect('/@/dashboard'); } diff --git a/brain/routes/back/index.js b/brain/routes/back/index.js index 1385cd9..89e7092 100644 --- a/brain/routes/back/index.js +++ b/brain/routes/back/index.js @@ -1,44 +1,9 @@ const express = require('express'); const router = express.Router(); -const Models = require('../../models'); //-------------------------- // Index //-------------------------- -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); - }); -}); +router.get('/', function(req, res) {}); //-------------------------- // Logout diff --git a/brain/routes/front/fipamo.js b/brain/routes/front/fipamo.js deleted file mode 100644 index 3f366c9..0000000 --- a/brain/routes/front/fipamo.js +++ /dev/null @@ -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; \ No newline at end of file diff --git a/brain/routes/front/index.js b/brain/routes/front/index.js deleted file mode 100644 index e2af40b..0000000 --- a/brain/routes/front/index.js +++ /dev/null @@ -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; -}; diff --git a/brain/routes/front/post.js b/brain/routes/front/post.js deleted file mode 100644 index 257e4c8..0000000 --- a/brain/routes/front/post.js +++ /dev/null @@ -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; diff --git a/brain/routes/front/work.js b/brain/routes/front/work.js deleted file mode 100644 index 7683da1..0000000 --- a/brain/routes/front/work.js +++ /dev/null @@ -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; diff --git a/init.js b/init.js index faebf08..65ec607 100644 --- a/init.js +++ b/init.js @@ -7,7 +7,6 @@ var app = require('./brain/app'); var debug = require('debug')('fipamo:server'); var http = require('http'); -var models = require('./brain/models'); /** * 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. */ -//server.listen(port); -//server.on('error', onError); -//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); -}); +server.listen(port); +server.on('error', onError); +server.on('listening', onListening); /** * Normalize a port into a number, string, or false.