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.

34 lines
1.2 KiB

  1. const utils = require('../utils/utils.js');
  2. const crypto = require('crypto');
  3. module.exports=
  4. {
  5. /**Sends the user an image from the specified fileName.
  6. *
  7. * @param result
  8. * @param fileName
  9. */
  10. main: function(result, fileName, cache)
  11. {
  12. //result.contentType = 'image/png';
  13. var img = cache.get(fileName);
  14. if(img == null)
  15. {
  16. utils.include("." + fileName).then(function(content)
  17. {
  18. var eTag = crypto.createHash('md5').update(content).digest('hex');
  19. result.writeHead(200, {'Content-Type': 'image/png', 'Cache-Control': 'public, max-age=2678400', 'ETag': '"' + eTag + '"'});
  20. result.write(content);
  21. result.end();
  22. cache.put(content);
  23. });
  24. }
  25. else
  26. {
  27. var eTag = crypto.createHash('md5').update(img).digest('hex');
  28. result.writeHead(200, {'Content-Type': 'image/png', 'Cache-Control': 'public, max-age=2678400', 'ETag': '"' + eTag + '"'});
  29. result.write(img);
  30. result.end();
  31. }
  32. }
  33. };