diff --git a/admin/addCategory.js b/admin/addCategory.js index e4d2283..9ff6318 100644 --- a/admin/addCategory.js +++ b/admin/addCategory.js @@ -71,6 +71,7 @@ var processPost = function(res, postData) }); }; + module.exports= { main: function(res, postData) diff --git a/downloads/downloads.js b/downloads/downloads.js index aee0448..b6b71d5 100644 --- a/downloads/downloads.js +++ b/downloads/downloads.js @@ -13,6 +13,13 @@ const sql = require('../utils/sql'); module.exports= { + /** + * TODO + * @param res + * @param requestURL + * @param request + * @returns {*|Promise} + */ main: function(res, requestURL, request) { res.setHeader('Content-disposition', 'attachment; filename=dramaticpenguin.MOV'); diff --git a/posts/category.js b/posts/category.js index f64fff4..cbc22da 100644 --- a/posts/category.js +++ b/posts/category.js @@ -3,7 +3,13 @@ const sql = require('../utils/sql'); const utils = require('../utils/utils.js'); - +/** + * Renders all posts in a single category + * + * @param result + * @param resultURL + * @returns {*} + */ var renderPosts = function(result, resultURL) { var splitURL = resultURL.split("/"); diff --git a/posts/homePage.js b/posts/homePage.js index 5f2e554..e33644b 100644 --- a/posts/homePage.js +++ b/posts/homePage.js @@ -6,7 +6,11 @@ const Promise = require('promise'); const postRenderer = require('../posts/singlePost.js'); - +/**Renders each recent post for the homepage of the website + * + * @param result + * @returns {*|Promise} + */ var renderRecentPosts = function(result) { return new Promise(function(resolve, reject) diff --git a/server.js b/server.js index 12810c6..cc87937 100644 --- a/server.js +++ b/server.js @@ -14,10 +14,8 @@ var express = require("express"); var session = require('express-session'); const includes = require('./includes/includes.js'); -// + const utils = require('./utils/utils.js'); -// -// var forceSsl = require('express-force-ssl'); var map = require('./utils/generateSiteMap.js'); map.main(); @@ -26,6 +24,10 @@ var app = express(); app.use(session({ secret: utils.getFileLine('../session_secret'), cookie: { maxAge: 6000000 }})); + +/** + * Parses the request url and calls correct JS files + */ app.use(function(request, res) { var q = url.parse(request.url, true); @@ -40,10 +42,6 @@ app.use(function(request, res) { includes.sendCSS(res, filename) } - // else if(filename.includes(/download/)) - // { - // require("./downloads/downloads.js").main(res, filename, request); - // } else { var file = ""; @@ -78,9 +76,4 @@ app.use(function(request, res) }) } }); - -//https.createServer(options, app).listen(443); - http.createServer(app).listen(8080); - -//app.use(forceSsl); \ No newline at end of file diff --git a/sidebar/categoriesSideBar.js b/sidebar/categoriesSideBar.js index d5ce1cd..fb2eb93 100644 --- a/sidebar/categoriesSideBar.js +++ b/sidebar/categoriesSideBar.js @@ -30,7 +30,6 @@ module.exports= res.write(""); resolve(); }) - }); } }; diff --git a/sidebar/popularPosts.js b/sidebar/popularPosts.js index ee29702..f27d874 100644 --- a/sidebar/popularPosts.js +++ b/sidebar/popularPosts.js @@ -3,15 +3,20 @@ const sql = require('../utils/sql'); module.exports= { + /**Renders the popular posts sidebar. + * + * @param res + * @returns {*|Promise} + */ main: function(res) { console.log("sidebar called"); return new Promise(function(resolve, reject) { - res.write("
"); - res.write("

Popular Posts

"); + res.write("
" + + "

Popular Posts

"); res.write("
"); @@ -21,12 +26,12 @@ module.exports= { console.log(cat); - res.write("" + p.name + "
"); - + res.write("" + p.name + "
"); }); res.write("
"); resolve(); - }) + }); }); } }; \ No newline at end of file diff --git a/sidebar/recentPosts.js b/sidebar/recentPosts.js index 79c7df7..8d2cd12 100644 --- a/sidebar/recentPosts.js +++ b/sidebar/recentPosts.js @@ -3,6 +3,11 @@ const sql = require('../utils/sql'); module.exports= { + /** Renders the the recent post sidebar. + * + * @param res + * @returns {*|Promise} + */ main: function(res) { return new Promise(function(resolve, reject) @@ -10,7 +15,8 @@ module.exports= res.write("
"); - res.write("

Recent Posts

"); + res.write("
" + + "

Recent Posts

"); res.write("
"); @@ -19,12 +25,12 @@ module.exports= posts.forEach(function(p) { var url = '/' + p.category + '/' + p.url; - res.write("" + p.name + "
"); + res.write("" + p.name + "
"); }); res.write("
"); resolve(); }) - }); } }; \ No newline at end of file diff --git a/sidebar/sidebar.js b/sidebar/sidebar.js index 58215ad..62ef9b7 100644 --- a/sidebar/sidebar.js +++ b/sidebar/sidebar.js @@ -3,6 +3,12 @@ var Promise = require('promise'); module.exports= { + /** Method which renders the entire sidebar through calling + * appropriate widget js files. + * + * @param res + * @returns {*|Promise} + */ main: function(res) { return new Promise(function(resolve, reject) @@ -14,7 +20,8 @@ module.exports= return require("../sidebar/recentPosts.js").main(res); }).then(function() { - return require("../sidebar/categoriesSideBar.js").main(res); + return require("../sidebar/categoriesSideBar.js") + .main(res); }).then(function() { res.write(""); diff --git a/utils/generateSiteMap.js b/utils/generateSiteMap.js index f98c80c..6022378 100644 --- a/utils/generateSiteMap.js +++ b/utils/generateSiteMap.js @@ -4,7 +4,6 @@ const sql = require('../utils/sql'); module.exports= { - main: function() { sql.getSiteMap().then(function(result) diff --git a/utils/sql.js b/utils/sql.js index 4cb6030..7f53bcb 100644 --- a/utils/sql.js +++ b/utils/sql.js @@ -81,7 +81,8 @@ module.exports= return new Promise(function(resolve, reject) { - fetch("select * from posts where post_id='" + id + "' limit 1").then(function(post) + fetch("select * from posts where post_id='" + id + "' limit 1") + .then(function(post) { resolve(post[0]); }).catch(function(error) @@ -174,6 +175,10 @@ module.exports= }, + /** + * Fetches the recent posts from the database. + * @returns {Array} + */ getRecentPostSQL: function() { return fetch("select * from posts order by post_id desc limit 10"); @@ -221,7 +226,10 @@ module.exports= }, - + /** + * TODO + * @returns {*|Promise} + */ getPopularPosts: function() { return new Promise(function(resolve, reject) @@ -311,6 +319,12 @@ module.exports= + categoryId + "'"); }, + + /**TODO work on website downloads + * + * @param downloadURL + * @returns {Array} + */ getDownload: function(downloadURL) { var cleanD = sanitizer.sanitize(downloadURL); @@ -318,6 +332,12 @@ module.exports= return fetch(q); }, + /** + * Based on the post data submitted by the user this function updates + * the information on the post in the database + * @param postData + * @returns {*|the} + */ editPost: function(postData) { var url = postData.edit_name_new.split(" ").join("-").toLowerCase(); diff --git a/utils/utils.js b/utils/utils.js index be877a4..7116124 100644 --- a/utils/utils.js +++ b/utils/utils.js @@ -108,6 +108,12 @@ module.exports= }); }, + /** + * Displays 404 error to user + * + * @param result + * @returns {*} + */ print404: function(result) { return this.include(result, "includes/404.html");