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.5 KiB

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