ContentController.js 743 B

123456789101112131415161718192021222324
  1. const Path = require('path')
  2. const send = require('send')
  3. const Settings = require('settings-sharelatex')
  4. const OutputCacheManager = require('./OutputCacheManager')
  5. const ONE_DAY_S = 24 * 60 * 60
  6. const ONE_DAY_MS = ONE_DAY_S * 1000
  7. function getPdfRange(req, res, next) {
  8. const { projectId, userId, contentId, hash } = req.params
  9. const perUserDir = userId ? `${projectId}-${userId}` : projectId
  10. const path = Path.join(
  11. Settings.path.outputDir,
  12. perUserDir,
  13. OutputCacheManager.CONTENT_SUBDIR,
  14. contentId,
  15. hash
  16. )
  17. res.setHeader('cache-control', `public, max-age=${ONE_DAY_S}`)
  18. res.setHeader('expires', new Date(Date.now() + ONE_DAY_MS).toUTCString())
  19. send(req, path).pipe(res)
  20. }
  21. module.exports = { getPdfRange }