Merge pull request #20067 from overleaf/jpa-fix-old-blob-download

[web] project-history expects history-v1 id in blob requests

GitOrigin-RevId: d9170a12fc6070811c188b346dbac32accabbfd7
This commit is contained in:
Jakob Ackermann 2024-08-22 11:43:55 +02:00 committed by Copybot
parent 0346ba2698
commit 989c48978a
4 changed files with 30 additions and 5 deletions

View file

@ -20,10 +20,10 @@ import { pipeline } from 'stream'
const ONE_DAY_IN_SECONDS = 24 * 60 * 60 const ONE_DAY_IN_SECONDS = 24 * 60 * 60
export function getProjectBlob(req, res, next) { export function getProjectBlob(req, res, next) {
const projectId = req.params.project_id const historyId = req.params.history_id
const blobHash = req.params.hash const blobHash = req.params.hash
HistoryStoreManager.getProjectBlobStream( HistoryStoreManager.getProjectBlobStream(
projectId, historyId,
blobHash, blobHash,
(err, stream) => { (err, stream) => {
if (err != null) { if (err != null) {

View file

@ -183,7 +183,7 @@ export function initialize(app) {
HttpController.forceDebugProject HttpController.forceDebugProject
) )
app.get('/project/:project_id/blob/:hash', HttpController.getProjectBlob) app.get('/project/:history_id/blob/:hash', HttpController.getProjectBlob)
app.get('/status/failures', HttpController.getFailures) app.get('/status/failures', HttpController.getFailures)

View file

@ -92,9 +92,10 @@ describe('HttpController', function () {
beforeEach(function () { beforeEach(function () {
this.blobHash = 'abcd' this.blobHash = 'abcd'
this.stream = {} this.stream = {}
this.historyId = 1337
this.HistoryStoreManager.getProjectBlobStream.yields(null, this.stream) this.HistoryStoreManager.getProjectBlobStream.yields(null, this.stream)
this.HttpController.getProjectBlob( this.HttpController.getProjectBlob(
{ params: { project_id: this.projectId, hash: this.blobHash } }, { params: { history_id: this.historyId, hash: this.blobHash } },
this.res, this.res,
this.next this.next
) )
@ -102,7 +103,7 @@ describe('HttpController', function () {
it('should get a blob stream', function () { it('should get a blob stream', function () {
this.HistoryStoreManager.getProjectBlobStream this.HistoryStoreManager.getProjectBlobStream
.calledWith(this.projectId, this.blobHash) .calledWith(this.historyId, this.blobHash)
.should.equal(true) .should.equal(true)
this.pipeline.should.have.been.calledWith(this.stream, this.res) this.pipeline.should.have.been.calledWith(this.stream, this.res)
}) })

View file

@ -38,6 +38,30 @@ module.exports = HistoryController = {
}) })
}, },
getBlob(req, res, next) {
const { project_id: projectId, blob } = req.params
ProjectGetter.getProject(
projectId,
{ 'overleaf.history.id': true },
(err, project) => {
if (err) return next(err)
const url = new URL(settings.apis.project_history.url)
url.pathname = `/project/${project.overleaf.history.id}/blob/${blob}`
pipeline(request(url.href), res, err => {
// If the downstream request is cancelled, we get an
// ERR_STREAM_PREMATURE_CLOSE.
if (err && err.code !== 'ERR_STREAM_PREMATURE_CLOSE') {
logger.warn({ url, err }, 'history API error')
next(err)
}
})
}
)
},
proxyToHistoryApiAndInjectUserDetails(req, res, next) { proxyToHistoryApiAndInjectUserDetails(req, res, next) {
const userId = SessionManager.getLoggedInUserId(req.session) const userId = SessionManager.getLoggedInUserId(req.session)
const url = settings.apis.project_history.url + req.url const url = settings.apis.project_history.url + req.url