mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
b456ea726d
* wip generate directory for hash content * cleanup, remove console logging * add content caching module * Return PDF stream ranges with compile response * Return the PDF file size in the compile response * PDF range endpoint * [misc] WIP: pdf caching: preserve the m-time on static content files * [misc] WIP: pdf caching: improve browser caching, emit caching headers * [misc] WIP: pdf caching: do not emit very small chunks <1kB * [misc] keep up with moving output files into a separate directory * [OutputCacheManager] add global feature flag for enabling pdf caching * [misc] add contentId into the URL for protecting PDF stream contents * [misc] support PDF stream caching for anonymous users * [misc] add per-request feature flag for enabling PDF stream caching * [misc] enable pdf caching in CI and emit metrics at the end of run * [misc] expose compile stats and timings to the frontend * [misc] log an error in case saving output files fails * [misc] add metrics for pdf bandwidth and pdf caching performance * [misc] add a dark mode to the pdf caching for computing ranges only * [misc] move pdf caching metrics into ContentCacheMetrics * [misc] add a config option for the min chunk size of pdf ranges Co-authored-by: Brian Gough <brian.gough@overleaf.com> Co-authored-by: Eric Mc Sween <eric.mcsween@overleaf.com>
24 lines
743 B
JavaScript
24 lines
743 B
JavaScript
const Path = require('path')
|
|
const send = require('send')
|
|
const Settings = require('settings-sharelatex')
|
|
const OutputCacheManager = require('./OutputCacheManager')
|
|
|
|
const ONE_DAY_S = 24 * 60 * 60
|
|
const ONE_DAY_MS = ONE_DAY_S * 1000
|
|
|
|
function getPdfRange(req, res, next) {
|
|
const { projectId, userId, contentId, hash } = req.params
|
|
const perUserDir = userId ? `${projectId}-${userId}` : projectId
|
|
const path = Path.join(
|
|
Settings.path.outputDir,
|
|
perUserDir,
|
|
OutputCacheManager.CONTENT_SUBDIR,
|
|
contentId,
|
|
hash
|
|
)
|
|
res.setHeader('cache-control', `public, max-age=${ONE_DAY_S}`)
|
|
res.setHeader('expires', new Date(Date.now() + ONE_DAY_MS).toUTCString())
|
|
send(req, path).pipe(res)
|
|
}
|
|
|
|
module.exports = { getPdfRange }
|