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.

76 lines
2.0 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 if(post.clear_cache)
  34. {
  35. require("../../sites/blog.js").clearCache();
  36. require("../../includes/includes.js").clearCache();
  37. }
  38. else if(post.git_pull)
  39. {
  40. const execSync = require('child_process').execSync;
  41. code = execSync('git pull')
  42. }
  43. else
  44. {
  45. resolve("");
  46. }
  47. });
  48. };
  49. module.exports=
  50. {
  51. /**
  52. *
  53. * @param postData
  54. * @return {*}
  55. */
  56. main: function(postData)
  57. {
  58. return new Promise(function(resolve, reject)
  59. {
  60. Promise.all([utils.include("./admin/posts/newPost.html"), processPost(postData)]).then(function(html)
  61. {
  62. resolve(html.join(''));
  63. }).catch(function(error)
  64. {
  65. reject(error);
  66. })
  67. });
  68. }
  69. };