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.

45 lines
1.2 KiB

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