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.

50 lines
1.3 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. if(urlSplit.length == 2 || urlSplit.length == 4)
  25. {
  26. sql.getDownload(urlSplit[1]).then(function(result)
  27. {
  28. if(result.length == 1)
  29. {
  30. const file = './blogContent/downloads/' +
  31. result[0].file;
  32. res.download(file);
  33. }
  34. else
  35. {
  36. utils.print404(res);
  37. }
  38. });
  39. }
  40. else
  41. {
  42. utils.print404(res);
  43. }
  44. });
  45. }
  46. };