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.

59 lines
1.7 KiB

  1. const utils = require('../utils/utils.js');
  2. var Promise = require('promise');
  3. module.exports=
  4. {
  5. main: function(result, fileName, request)
  6. {
  7. return new Promise(function(resolve, reject){
  8. var promiseToGetPost = function(req)
  9. {
  10. return new Promise(function(resolve, reject)
  11. {
  12. if(req.method == 'POST')
  13. {
  14. var body = '';
  15. req.on('data', function (data)
  16. {
  17. body += data;
  18. //Kills request, don't steal my RAM!!
  19. //You can only download so much ram ;)
  20. if (body.length > 1e6)
  21. {
  22. req.connection.destroy();
  23. reject();
  24. }
  25. });
  26. req.on('end', function ()
  27. {
  28. console.log(body);
  29. resolve(body);
  30. });
  31. }
  32. else
  33. {
  34. resolve(0);
  35. }
  36. });
  37. };
  38. var promiseToDisplayContents = function(postData)
  39. {
  40. return require("../admin/addCategory.js").main(result, postData);
  41. };
  42. promiseToGetPost(request).then(function (postData)
  43. {
  44. return promiseToDisplayContents(postData);
  45. }).then(function()
  46. {
  47. resolve();
  48. });
  49. });
  50. }
  51. };