mirror of
https://github.com/overleaf/overleaf.git
synced 2025-04-23 06:18:07 +00:00
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:
parent
0346ba2698
commit
989c48978a
4 changed files with 30 additions and 5 deletions
services
project-history
web/app/src/Features/History
|
@ -20,10 +20,10 @@ import { pipeline } from 'stream'
|
|||
const ONE_DAY_IN_SECONDS = 24 * 60 * 60
|
||||
|
||||
export function getProjectBlob(req, res, next) {
|
||||
const projectId = req.params.project_id
|
||||
const historyId = req.params.history_id
|
||||
const blobHash = req.params.hash
|
||||
HistoryStoreManager.getProjectBlobStream(
|
||||
projectId,
|
||||
historyId,
|
||||
blobHash,
|
||||
(err, stream) => {
|
||||
if (err != null) {
|
||||
|
|
|
@ -183,7 +183,7 @@ export function initialize(app) {
|
|||
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)
|
||||
|
||||
|
|
|
@ -92,9 +92,10 @@ describe('HttpController', function () {
|
|||
beforeEach(function () {
|
||||
this.blobHash = 'abcd'
|
||||
this.stream = {}
|
||||
this.historyId = 1337
|
||||
this.HistoryStoreManager.getProjectBlobStream.yields(null, this.stream)
|
||||
this.HttpController.getProjectBlob(
|
||||
{ params: { project_id: this.projectId, hash: this.blobHash } },
|
||||
{ params: { history_id: this.historyId, hash: this.blobHash } },
|
||||
this.res,
|
||||
this.next
|
||||
)
|
||||
|
@ -102,7 +103,7 @@ describe('HttpController', function () {
|
|||
|
||||
it('should get a blob stream', function () {
|
||||
this.HistoryStoreManager.getProjectBlobStream
|
||||
.calledWith(this.projectId, this.blobHash)
|
||||
.calledWith(this.historyId, this.blobHash)
|
||||
.should.equal(true)
|
||||
this.pipeline.should.have.been.calledWith(this.stream, this.res)
|
||||
})
|
||||
|
|
|
@ -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) {
|
||||
const userId = SessionManager.getLoggedInUserId(req.session)
|
||||
const url = settings.apis.project_history.url + req.url
|
||||
|
|
Loading…
Add table
Reference in a new issue