Personal blog written from scratch using Node.js, Bootstrap, and MySQL. https://jrtechs.net
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

54 lines
1.5 KiB

const utils = require('../utils/utils.js');
const sql = require('../utils/sql');
const qs = require('querystring');
var Promise = require('promise');
module.exports=
{
/**
*
* @param res
* @param postData
* @return {*}
*/
main: function(res, postData)
{
utils.include(res, "./admin/newPost.html");
return this.processPost(res, postData);
},
/**
*
* @param res
* @param postData
* @return {*|Promise}
*/
processPost: function(res, postData)
{
return new Promise(function(resolve, reject)
{
var post = qs.parse(postData);
if(post.add_post_name)
{
var urls = post.add_post_name;
urls = urls.split(" ").join("-");
urls =urls.toLowerCase();
var q = "insert into posts (category_id, picture_url, published, name, url) values ";
q += "('" + post.add_post_category + "', '" + post.add_post_picture +
"', '" + post.add_post_date + "', '" + post.add_post_name + "', '" + urls + "')";
sql.insert(q).then(function()
{
resolve();
})
}
else
{
resolve(postData);
}
});
}
};