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.

55 lines
1.6 KiB

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