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.

55 lines
1.6 KiB

  1. const utils = require('../utils/utils.js');
  2. const sql = require('../utils/sql');
  3. const qs = require('querystring');
  4. var Promise = require('promise');
  5. module.exports=
  6. {
  7. /**
  8. *
  9. * @param res
  10. * @param postData
  11. * @return {*}
  12. */
  13. main: function(res, postData)
  14. {
  15. utils.include(res, "./admin/newPost.html");
  16. return this.processPost(res, postData);
  17. },
  18. /**
  19. *
  20. * @param res
  21. * @param postData
  22. * @return {*|Promise}
  23. */
  24. processPost: function(res, postData)
  25. {
  26. return new Promise(function(resolve, reject)
  27. {
  28. var post = qs.parse(postData);
  29. if(post.add_post_name)
  30. {
  31. var urls = post.add_post_name;
  32. urls = urls.split(" ").join("-");
  33. urls =urls.toLowerCase();
  34. var q = "insert into posts (category_id, picture_url, published, name, url) values ";
  35. q += "('" + post.add_post_category + "', '" + post.add_post_picture +
  36. "', '" + post.add_post_date + "', '" + post.add_post_name + "', '" + urls + "')";
  37. sql.insert(q).then(function()
  38. {
  39. var map = require('../utils/generateSiteMap');
  40. map.main();
  41. resolve();
  42. })
  43. }
  44. else
  45. {
  46. resolve(postData);
  47. }
  48. });
  49. }
  50. };