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.

57 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. 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. /**
  12. * TODO
  13. * @param res
  14. * @param requestURL
  15. * @param request
  16. * @returns {*|Promise}
  17. */
  18. main: function(res, requestURL, request)
  19. {
  20. res.setHeader('Content-disposition', 'attachment; filename=dramaticpenguin.MOV');
  21. return new Promise(function(resolve, reject)
  22. {
  23. var urlSplit = requestURL.split("/");
  24. console.log(urlSplit);
  25. if(urlSplit.length == 3 || urlSplit.length == 4)
  26. {
  27. sql.getDownload(urlSplit[2]).then(function(result)
  28. {
  29. console.log(result);
  30. if(result.length == 1)
  31. {
  32. var file = './downloads/content/' + result[0].file;
  33. res.download(file);
  34. }
  35. else
  36. {
  37. utils.print404(res).then(function()
  38. {
  39. resolve();
  40. })
  41. }
  42. });
  43. }
  44. else
  45. {
  46. utils.print404(res).then(function()
  47. {
  48. resolve();
  49. })
  50. }
  51. });
  52. }
  53. };