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.

66 lines
1.6 KiB

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