ContentController.js 728 B

123456789101112131415161718192021222324
  1. import Path from 'node:path'
  2. import send from 'send'
  3. import Settings from '@overleaf/settings'
  4. import OutputCacheManager from './OutputCacheManager.js'
  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. export default { getPdfRange }