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. /**
  2. Utilities is a node modules created to make tasks like
  3. including html files easier for me programming.
  4. */
  5. //file IO
  6. const utils = require('../utils/utils.js');
  7. //DB query
  8. const sql = require('../utils/sql');
  9. module.exports=
  10. {
  11. /**
  12. * Processes download url and sends download to user if it
  13. * exists in the database.
  14. *
  15. * @param res
  16. * @param requestURL
  17. * @returns {*|Promise}
  18. */
  19. main: function(res, requestURL)
  20. {
  21. return new Promise(function(resolve, reject)
  22. {
  23. const urlSplit = requestURL.split("/");
  24. console.log(urlSplit);
  25. if(urlSplit.length == 3 || urlSplit.length == 4)
  26. {
  27. console.log(urlSplit[2]);
  28. sql.getDownload(urlSplit[2]).then(function(result)
  29. {
  30. console.log(result);
  31. if(result.length == 1)
  32. {
  33. const file = './blogContent/downloads/' +
  34. result[0].file;
  35. res.download(file);
  36. }
  37. else
  38. {
  39. utils.print404(res).then(function()
  40. {
  41. resolve();
  42. })
  43. }
  44. });
  45. }
  46. else
  47. {
  48. utils.print404().then(function(content)
  49. {
  50. resolve(content);
  51. })
  52. }
  53. });
  54. }
  55. };