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.

53 lines
1.0 KiB

  1. "use strict";
  2. var express = require('express');
  3. var router = express.Router();
  4. var _ = require('lodash');
  5. var validPathRe = new RegExp("^([a-z0-9\\/-]+\\.[a-z0-9]+)$");
  6. var validPathThumbsRe = new RegExp("^([0-9]+\\.png)$");
  7. // ==========================================
  8. // SERVE UPLOADS FILES
  9. // ==========================================
  10. router.get('/t/*', (req, res, next) => {
  11. let fileName = req.params[0];
  12. if(!validPathThumbsRe.test(fileName)) {
  13. return res.sendStatus(404).end();
  14. }
  15. //todo: Authentication-based access
  16. res.sendFile(fileName, {
  17. root: lcdata.getThumbsPath(),
  18. dotfiles: 'deny'
  19. }, (err) => {
  20. if (err) {
  21. res.status(err.status).end();
  22. }
  23. });
  24. });
  25. router.get('/*', (req, res, next) => {
  26. let fileName = req.params[0];
  27. if(!validPathRe.test(fileName)) {
  28. return res.sendStatus(404).end();
  29. }
  30. //todo: Authentication-based access
  31. res.sendFile(fileName, {
  32. root: git.getRepoPath() + '/uploads/',
  33. dotfiles: 'deny'
  34. }, (err) => {
  35. if (err) {
  36. res.status(err.status).end();
  37. }
  38. });
  39. });
  40. module.exports = router;