2019-05-29 05:21:06 -04:00
|
|
|
let HistoryController
|
2020-08-19 05:11:32 -04:00
|
|
|
const OError = require('@overleaf/o-error')
|
2019-05-29 05:21:06 -04:00
|
|
|
const async = require('async')
|
|
|
|
const logger = require('logger-sharelatex')
|
|
|
|
const request = require('request')
|
2021-07-07 05:38:56 -04:00
|
|
|
const settings = require('@overleaf/settings')
|
2021-07-28 04:51:20 -04:00
|
|
|
const SessionManager = require('../Authentication/SessionManager')
|
2020-08-12 10:17:50 -04:00
|
|
|
const UserGetter = require('../User/UserGetter')
|
2019-05-29 05:21:06 -04:00
|
|
|
const Errors = require('../Errors/Errors')
|
|
|
|
const HistoryManager = require('./HistoryManager')
|
|
|
|
const ProjectDetailsHandler = require('../Project/ProjectDetailsHandler')
|
|
|
|
const ProjectEntityUpdateHandler = require('../Project/ProjectEntityUpdateHandler')
|
|
|
|
const RestoreManager = require('./RestoreManager')
|
2020-08-03 07:34:04 -04:00
|
|
|
const { pipeline } = require('stream')
|
2019-05-29 05:21:06 -04:00
|
|
|
|
|
|
|
module.exports = HistoryController = {
|
|
|
|
selectHistoryApi(req, res, next) {
|
2020-11-30 08:02:12 -05:00
|
|
|
const { Project_id: projectId } = req.params
|
2019-05-29 05:21:06 -04:00
|
|
|
// find out which type of history service this project uses
|
2021-04-14 09:17:21 -04:00
|
|
|
ProjectDetailsHandler.getDetails(projectId, function (err, project) {
|
2020-11-30 08:02:12 -05:00
|
|
|
if (err) {
|
2019-05-29 05:21:06 -04:00
|
|
|
return next(err)
|
|
|
|
}
|
2020-11-30 08:02:12 -05:00
|
|
|
const history = project.overleaf && project.overleaf.history
|
|
|
|
if (history && history.id && history.display) {
|
2019-05-29 05:21:06 -04:00
|
|
|
req.useProjectHistory = true
|
|
|
|
} else {
|
|
|
|
req.useProjectHistory = false
|
|
|
|
}
|
2020-11-30 08:02:12 -05:00
|
|
|
next()
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|
|
|
|
},
|
|
|
|
|
|
|
|
ensureProjectHistoryEnabled(req, res, next) {
|
2020-11-30 08:02:12 -05:00
|
|
|
if (req.useProjectHistory) {
|
|
|
|
next()
|
2019-05-29 05:21:06 -04:00
|
|
|
} else {
|
2020-11-30 08:02:12 -05:00
|
|
|
res.sendStatus(404)
|
2019-05-29 05:21:06 -04:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
proxyToHistoryApi(req, res, next) {
|
2021-07-28 04:51:20 -04:00
|
|
|
const userId = SessionManager.getLoggedInUserId(req.session)
|
2019-05-29 05:21:06 -04:00
|
|
|
const url =
|
|
|
|
HistoryController.buildHistoryServiceUrl(req.useProjectHistory) + req.url
|
|
|
|
|
|
|
|
const getReq = request({
|
|
|
|
url,
|
|
|
|
method: req.method,
|
|
|
|
headers: {
|
2021-04-27 03:52:58 -04:00
|
|
|
'X-User-Id': userId,
|
|
|
|
},
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|
|
|
|
getReq.pipe(res)
|
2021-04-14 09:17:21 -04:00
|
|
|
getReq.on('error', function (err) {
|
2020-11-30 08:02:12 -05:00
|
|
|
logger.warn({ url, err }, 'history API error')
|
|
|
|
next(err)
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|
|
|
|
},
|
|
|
|
|
|
|
|
proxyToHistoryApiAndInjectUserDetails(req, res, next) {
|
2021-07-28 04:51:20 -04:00
|
|
|
const userId = SessionManager.getLoggedInUserId(req.session)
|
2019-05-29 05:21:06 -04:00
|
|
|
const url =
|
|
|
|
HistoryController.buildHistoryServiceUrl(req.useProjectHistory) + req.url
|
2020-11-30 08:02:12 -05:00
|
|
|
HistoryController._makeRequest(
|
2019-05-29 05:21:06 -04:00
|
|
|
{
|
|
|
|
url,
|
|
|
|
method: req.method,
|
|
|
|
json: true,
|
|
|
|
headers: {
|
2021-04-27 03:52:58 -04:00
|
|
|
'X-User-Id': userId,
|
|
|
|
},
|
2019-05-29 05:21:06 -04:00
|
|
|
},
|
2021-04-14 09:17:21 -04:00
|
|
|
function (err, body) {
|
2020-11-30 08:02:12 -05:00
|
|
|
if (err) {
|
|
|
|
return next(err)
|
2019-05-29 05:21:06 -04:00
|
|
|
}
|
2021-04-14 09:17:21 -04:00
|
|
|
HistoryManager.injectUserDetails(body, function (err, data) {
|
2020-11-30 08:02:12 -05:00
|
|
|
if (err) {
|
|
|
|
return next(err)
|
2019-05-29 05:21:06 -04:00
|
|
|
}
|
2020-11-30 08:02:12 -05:00
|
|
|
res.json(data)
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|
|
|
|
}
|
|
|
|
)
|
|
|
|
},
|
|
|
|
|
|
|
|
buildHistoryServiceUrl(useProjectHistory) {
|
|
|
|
// choose a history service, either document-level (trackchanges)
|
|
|
|
// or project-level (project_history)
|
|
|
|
if (useProjectHistory) {
|
|
|
|
return settings.apis.project_history.url
|
|
|
|
} else {
|
|
|
|
return settings.apis.trackchanges.url
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
resyncProjectHistory(req, res, next) {
|
2020-11-30 08:02:12 -05:00
|
|
|
const projectId = req.params.Project_id
|
2021-04-14 09:17:21 -04:00
|
|
|
ProjectEntityUpdateHandler.resyncProjectHistory(projectId, function (err) {
|
2020-11-30 08:02:12 -05:00
|
|
|
if (err instanceof Errors.ProjectHistoryDisabledError) {
|
2019-05-29 05:21:06 -04:00
|
|
|
return res.sendStatus(404)
|
|
|
|
}
|
2020-11-30 08:02:12 -05:00
|
|
|
if (err) {
|
|
|
|
return next(err)
|
2019-05-29 05:21:06 -04:00
|
|
|
}
|
2020-11-30 08:02:12 -05:00
|
|
|
res.sendStatus(204)
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|
|
|
|
},
|
|
|
|
|
|
|
|
restoreFileFromV2(req, res, next) {
|
2020-11-30 08:02:12 -05:00
|
|
|
const { project_id: projectId } = req.params
|
2019-05-29 05:21:06 -04:00
|
|
|
const { version, pathname } = req.body
|
2021-07-28 04:51:20 -04:00
|
|
|
const userId = SessionManager.getLoggedInUserId(req.session)
|
2020-11-30 08:02:12 -05:00
|
|
|
RestoreManager.restoreFileFromV2(
|
|
|
|
userId,
|
|
|
|
projectId,
|
2019-05-29 05:21:06 -04:00
|
|
|
version,
|
|
|
|
pathname,
|
2021-04-14 09:17:21 -04:00
|
|
|
function (err, entity) {
|
2020-11-30 08:02:12 -05:00
|
|
|
if (err) {
|
|
|
|
return next(err)
|
2019-05-29 05:21:06 -04:00
|
|
|
}
|
2020-11-30 08:02:12 -05:00
|
|
|
res.json({
|
2019-05-29 05:21:06 -04:00
|
|
|
type: entity.type,
|
2021-04-27 03:52:58 -04:00
|
|
|
id: entity._id,
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|
|
|
|
}
|
|
|
|
)
|
|
|
|
},
|
|
|
|
|
|
|
|
restoreDocFromDeletedDoc(req, res, next) {
|
2020-11-30 08:02:12 -05:00
|
|
|
const { project_id: projectId, doc_id: docId } = req.params
|
2019-05-29 05:21:06 -04:00
|
|
|
const { name } = req.body
|
2021-07-28 04:51:20 -04:00
|
|
|
const userId = SessionManager.getLoggedInUserId(req.session)
|
2019-05-29 05:21:06 -04:00
|
|
|
if (name == null) {
|
|
|
|
return res.sendStatus(400) // Malformed request
|
|
|
|
}
|
2020-11-30 08:02:12 -05:00
|
|
|
RestoreManager.restoreDocFromDeletedDoc(
|
|
|
|
userId,
|
|
|
|
projectId,
|
|
|
|
docId,
|
2019-05-29 05:21:06 -04:00
|
|
|
name,
|
2020-11-30 08:02:12 -05:00
|
|
|
(err, doc) => {
|
|
|
|
if (err) return next(err)
|
2019-11-04 04:49:58 -05:00
|
|
|
res.json({
|
2021-04-27 03:52:58 -04:00
|
|
|
doc_id: doc._id,
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|
|
|
|
}
|
|
|
|
)
|
|
|
|
},
|
|
|
|
|
|
|
|
getLabels(req, res, next) {
|
2020-11-30 08:02:12 -05:00
|
|
|
const projectId = req.params.Project_id
|
|
|
|
HistoryController._makeRequest(
|
2019-05-29 05:21:06 -04:00
|
|
|
{
|
|
|
|
method: 'GET',
|
2020-11-30 08:02:12 -05:00
|
|
|
url: `${settings.apis.project_history.url}/project/${projectId}/labels`,
|
2021-04-27 03:52:58 -04:00
|
|
|
json: true,
|
2019-05-29 05:21:06 -04:00
|
|
|
},
|
2021-04-14 09:17:21 -04:00
|
|
|
function (err, labels) {
|
2020-11-30 08:02:12 -05:00
|
|
|
if (err) {
|
|
|
|
return next(err)
|
2019-05-29 05:21:06 -04:00
|
|
|
}
|
2020-08-12 10:17:50 -04:00
|
|
|
HistoryController._enrichLabels(labels, (err, labels) => {
|
|
|
|
if (err) {
|
|
|
|
return next(err)
|
|
|
|
}
|
2020-11-30 08:02:12 -05:00
|
|
|
res.json(labels)
|
2020-08-12 10:17:50 -04:00
|
|
|
})
|
2019-05-29 05:21:06 -04:00
|
|
|
}
|
|
|
|
)
|
|
|
|
},
|
|
|
|
|
|
|
|
createLabel(req, res, next) {
|
2020-11-30 08:02:12 -05:00
|
|
|
const projectId = req.params.Project_id
|
2019-05-29 05:21:06 -04:00
|
|
|
const { comment, version } = req.body
|
2021-07-28 04:51:20 -04:00
|
|
|
const userId = SessionManager.getLoggedInUserId(req.session)
|
2020-11-30 08:02:12 -05:00
|
|
|
HistoryController._makeRequest(
|
2019-05-29 05:21:06 -04:00
|
|
|
{
|
|
|
|
method: 'POST',
|
2020-12-15 05:23:54 -05:00
|
|
|
url: `${settings.apis.project_history.url}/project/${projectId}/user/${userId}/labels`,
|
2021-04-27 03:52:58 -04:00
|
|
|
json: { comment, version },
|
2019-05-29 05:21:06 -04:00
|
|
|
},
|
2021-04-14 09:17:21 -04:00
|
|
|
function (err, label) {
|
2020-11-30 08:02:12 -05:00
|
|
|
if (err) {
|
|
|
|
return next(err)
|
2019-05-29 05:21:06 -04:00
|
|
|
}
|
2020-08-12 10:17:50 -04:00
|
|
|
HistoryController._enrichLabel(label, (err, label) => {
|
|
|
|
if (err) {
|
|
|
|
return next(err)
|
|
|
|
}
|
2020-11-30 08:02:12 -05:00
|
|
|
res.json(label)
|
2020-08-12 10:17:50 -04:00
|
|
|
})
|
|
|
|
}
|
|
|
|
)
|
|
|
|
},
|
|
|
|
|
|
|
|
_enrichLabel(label, callback) {
|
|
|
|
if (!label.user_id) {
|
|
|
|
return callback(null, label)
|
|
|
|
}
|
|
|
|
UserGetter.getUser(
|
|
|
|
label.user_id,
|
|
|
|
{ first_name: 1, last_name: 1, email: 1 },
|
|
|
|
(err, user) => {
|
|
|
|
if (err) {
|
|
|
|
return callback(err)
|
|
|
|
}
|
|
|
|
const newLabel = Object.assign({}, label)
|
|
|
|
newLabel.user_display_name = HistoryController._displayNameForUser(user)
|
|
|
|
callback(null, newLabel)
|
|
|
|
}
|
|
|
|
)
|
|
|
|
},
|
|
|
|
|
|
|
|
_enrichLabels(labels, callback) {
|
|
|
|
if (!labels || !labels.length) {
|
|
|
|
return callback(null, [])
|
|
|
|
}
|
|
|
|
const uniqueUsers = new Set(labels.map(label => label.user_id))
|
|
|
|
|
|
|
|
// For backwards compatibility expect missing user_id fields
|
|
|
|
uniqueUsers.delete(undefined)
|
|
|
|
|
|
|
|
if (!uniqueUsers.size) {
|
|
|
|
return callback(null, labels)
|
|
|
|
}
|
|
|
|
|
|
|
|
UserGetter.getUsers(
|
|
|
|
Array.from(uniqueUsers),
|
|
|
|
{ first_name: 1, last_name: 1, email: 1 },
|
2021-04-14 09:17:21 -04:00
|
|
|
function (err, rawUsers) {
|
2020-08-12 10:17:50 -04:00
|
|
|
if (err) {
|
|
|
|
return callback(err)
|
|
|
|
}
|
|
|
|
const users = new Map(rawUsers.map(user => [String(user._id), user]))
|
|
|
|
|
|
|
|
labels.forEach(label => {
|
|
|
|
const user = users.get(label.user_id)
|
|
|
|
if (!user) return
|
|
|
|
label.user_display_name = HistoryController._displayNameForUser(user)
|
|
|
|
})
|
|
|
|
callback(null, labels)
|
2019-05-29 05:21:06 -04:00
|
|
|
}
|
|
|
|
)
|
|
|
|
},
|
|
|
|
|
2020-08-12 10:17:50 -04:00
|
|
|
_displayNameForUser(user) {
|
|
|
|
if (user == null) {
|
|
|
|
return 'Anonymous'
|
|
|
|
}
|
2020-11-30 08:02:12 -05:00
|
|
|
if (user.name) {
|
2020-08-12 10:17:50 -04:00
|
|
|
return user.name
|
|
|
|
}
|
|
|
|
let name = [user.first_name, user.last_name]
|
|
|
|
.filter(n => n != null)
|
|
|
|
.join(' ')
|
|
|
|
.trim()
|
|
|
|
if (name === '') {
|
|
|
|
name = user.email.split('@')[0]
|
|
|
|
}
|
2020-11-30 08:02:12 -05:00
|
|
|
if (!name) {
|
2020-08-12 10:17:50 -04:00
|
|
|
return '?'
|
|
|
|
}
|
|
|
|
return name
|
|
|
|
},
|
|
|
|
|
2019-05-29 05:21:06 -04:00
|
|
|
deleteLabel(req, res, next) {
|
2020-11-30 08:02:12 -05:00
|
|
|
const { Project_id: projectId, label_id: labelId } = req.params
|
2021-07-28 04:51:20 -04:00
|
|
|
const userId = SessionManager.getLoggedInUserId(req.session)
|
2020-11-30 08:02:12 -05:00
|
|
|
HistoryController._makeRequest(
|
2019-05-29 05:21:06 -04:00
|
|
|
{
|
|
|
|
method: 'DELETE',
|
2021-04-27 03:52:58 -04:00
|
|
|
url: `${settings.apis.project_history.url}/project/${projectId}/user/${userId}/labels/${labelId}`,
|
2019-05-29 05:21:06 -04:00
|
|
|
},
|
2021-04-14 09:17:21 -04:00
|
|
|
function (err) {
|
2020-11-30 08:02:12 -05:00
|
|
|
if (err) {
|
|
|
|
return next(err)
|
2019-05-29 05:21:06 -04:00
|
|
|
}
|
2020-11-30 08:02:12 -05:00
|
|
|
res.sendStatus(204)
|
2019-05-29 05:21:06 -04:00
|
|
|
}
|
|
|
|
)
|
|
|
|
},
|
|
|
|
|
|
|
|
_makeRequest(options, callback) {
|
2021-04-14 09:17:21 -04:00
|
|
|
return request(options, function (err, response, body) {
|
2020-11-30 08:02:12 -05:00
|
|
|
if (err) {
|
|
|
|
return callback(err)
|
2019-05-29 05:21:06 -04:00
|
|
|
}
|
|
|
|
if (response.statusCode >= 200 && response.statusCode < 300) {
|
2020-11-30 08:02:12 -05:00
|
|
|
callback(null, body)
|
2019-05-29 05:21:06 -04:00
|
|
|
} else {
|
2020-11-30 08:02:12 -05:00
|
|
|
err = new Error(
|
2019-05-29 05:21:06 -04:00
|
|
|
`history api responded with non-success code: ${response.statusCode}`
|
|
|
|
)
|
2020-11-30 08:02:12 -05:00
|
|
|
callback(err)
|
2019-05-29 05:21:06 -04:00
|
|
|
}
|
|
|
|
})
|
|
|
|
},
|
|
|
|
|
|
|
|
downloadZipOfVersion(req, res, next) {
|
2020-11-30 08:02:12 -05:00
|
|
|
const { project_id: projectId, version } = req.params
|
2021-04-14 09:17:21 -04:00
|
|
|
ProjectDetailsHandler.getDetails(projectId, function (err, project) {
|
2020-11-30 08:02:12 -05:00
|
|
|
if (err) {
|
2019-05-29 05:21:06 -04:00
|
|
|
return next(err)
|
|
|
|
}
|
2020-11-30 08:02:12 -05:00
|
|
|
const v1Id =
|
|
|
|
project.overleaf &&
|
|
|
|
project.overleaf.history &&
|
|
|
|
project.overleaf.history.id
|
|
|
|
if (v1Id == null) {
|
|
|
|
logger.error(
|
|
|
|
{ projectId, version },
|
2019-05-29 05:21:06 -04:00
|
|
|
'got request for zip version of non-v1 history project'
|
|
|
|
)
|
|
|
|
return res.sendStatus(402)
|
|
|
|
}
|
2020-11-30 08:02:12 -05:00
|
|
|
HistoryController._pipeHistoryZipToResponse(
|
|
|
|
v1Id,
|
2019-05-29 05:21:06 -04:00
|
|
|
version,
|
|
|
|
`${project.name} (Version ${version})`,
|
2020-08-03 07:34:04 -04:00
|
|
|
req,
|
2019-05-29 05:21:06 -04:00
|
|
|
res,
|
|
|
|
next
|
|
|
|
)
|
|
|
|
})
|
|
|
|
},
|
|
|
|
|
2020-11-30 08:02:12 -05:00
|
|
|
_pipeHistoryZipToResponse(v1ProjectId, version, name, req, res, next) {
|
2020-08-03 07:34:04 -04:00
|
|
|
if (req.aborted) {
|
|
|
|
// client has disconnected -- skip project history api call and download
|
|
|
|
return
|
|
|
|
}
|
2019-05-29 05:21:06 -04:00
|
|
|
// increase timeout to 6 minutes
|
|
|
|
res.setTimeout(6 * 60 * 1000)
|
2020-12-15 05:23:54 -05:00
|
|
|
const url = `${settings.apis.v1_history.url}/projects/${v1ProjectId}/version/${version}/zip`
|
2019-05-29 05:21:06 -04:00
|
|
|
const options = {
|
|
|
|
auth: {
|
|
|
|
user: settings.apis.v1_history.user,
|
2021-04-27 03:52:58 -04:00
|
|
|
pass: settings.apis.v1_history.pass,
|
2019-05-29 05:21:06 -04:00
|
|
|
},
|
|
|
|
json: true,
|
|
|
|
method: 'post',
|
2021-04-27 03:52:58 -04:00
|
|
|
url,
|
2019-05-29 05:21:06 -04:00
|
|
|
}
|
2021-04-14 09:17:21 -04:00
|
|
|
request(options, function (err, response, body) {
|
2019-05-29 05:21:06 -04:00
|
|
|
if (err) {
|
2020-08-19 05:11:32 -04:00
|
|
|
OError.tag(err, 'history API error', {
|
2020-11-30 08:02:12 -05:00
|
|
|
v1ProjectId,
|
2021-04-27 03:52:58 -04:00
|
|
|
version,
|
2020-08-19 05:11:32 -04:00
|
|
|
})
|
2019-05-29 05:21:06 -04:00
|
|
|
return next(err)
|
|
|
|
}
|
2021-09-07 04:29:14 -04:00
|
|
|
if (response.statusCode !== 200) {
|
|
|
|
if (response.statusCode === 404) {
|
|
|
|
return next(new Errors.NotFoundError('zip not found'))
|
|
|
|
} else {
|
|
|
|
return next(
|
|
|
|
new OError('Error while getting zip for download', {
|
|
|
|
v1ProjectId,
|
|
|
|
statusCode: response.statusCode,
|
|
|
|
})
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
2020-08-03 07:34:04 -04:00
|
|
|
if (req.aborted) {
|
|
|
|
// client has disconnected -- skip delayed s3 download
|
|
|
|
return
|
|
|
|
}
|
2021-09-07 04:29:14 -04:00
|
|
|
if (!body.zipUrl) {
|
|
|
|
return next(
|
|
|
|
new OError('Missing zipUrl, cannot fetch zip file', {
|
|
|
|
v1ProjectId,
|
|
|
|
body,
|
|
|
|
statusCode: response.statusCode,
|
|
|
|
})
|
|
|
|
)
|
|
|
|
}
|
2019-05-29 05:21:06 -04:00
|
|
|
let retryAttempt = 0
|
|
|
|
let retryDelay = 2000
|
|
|
|
// retry for about 6 minutes starting with short delay
|
2020-11-30 08:02:12 -05:00
|
|
|
async.retry(
|
2019-05-29 05:21:06 -04:00
|
|
|
40,
|
|
|
|
callback =>
|
2021-04-14 09:17:21 -04:00
|
|
|
setTimeout(function () {
|
2020-08-03 07:34:04 -04:00
|
|
|
if (req.aborted) {
|
|
|
|
// client has disconnected -- skip s3 download
|
|
|
|
return callback() // stop async.retry loop
|
|
|
|
}
|
|
|
|
|
2019-05-29 05:21:06 -04:00
|
|
|
// increase delay by 1 second up to 10
|
|
|
|
if (retryDelay < 10000) {
|
|
|
|
retryDelay += 1000
|
|
|
|
}
|
|
|
|
retryAttempt++
|
|
|
|
const getReq = request({
|
|
|
|
url: body.zipUrl,
|
2021-04-27 03:52:58 -04:00
|
|
|
sendImmediately: true,
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|
2020-08-03 07:34:04 -04:00
|
|
|
const abortS3Request = () => getReq.abort()
|
|
|
|
req.on('aborted', abortS3Request)
|
|
|
|
res.on('timeout', abortS3Request)
|
|
|
|
function cleanupAbortTrigger() {
|
|
|
|
req.off('aborted', abortS3Request)
|
|
|
|
res.off('timeout', abortS3Request)
|
|
|
|
}
|
2021-04-14 09:17:21 -04:00
|
|
|
getReq.on('response', function (response) {
|
2019-05-29 05:21:06 -04:00
|
|
|
if (response.statusCode !== 200) {
|
2020-08-03 07:34:04 -04:00
|
|
|
cleanupAbortTrigger()
|
2019-05-29 05:21:06 -04:00
|
|
|
return callback(new Error('invalid response'))
|
|
|
|
}
|
|
|
|
// pipe also proxies the headers, but we want to customize these ones
|
|
|
|
delete response.headers['content-disposition']
|
|
|
|
delete response.headers['content-type']
|
|
|
|
res.status(response.statusCode)
|
|
|
|
res.setContentDisposition('attachment', {
|
2021-04-27 03:52:58 -04:00
|
|
|
filename: `${name}.zip`,
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|
|
|
|
res.contentType('application/zip')
|
2020-08-03 07:34:04 -04:00
|
|
|
pipeline(response, res, err => {
|
|
|
|
if (err) {
|
|
|
|
logger.warn(
|
2020-11-30 08:02:12 -05:00
|
|
|
{ err, v1ProjectId, version, retryAttempt },
|
2020-08-03 07:34:04 -04:00
|
|
|
'history s3 proxying error'
|
|
|
|
)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
callback()
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|
2021-04-14 09:17:21 -04:00
|
|
|
getReq.on('error', function (err) {
|
2019-07-01 09:48:09 -04:00
|
|
|
logger.warn(
|
2020-11-30 08:02:12 -05:00
|
|
|
{ err, v1ProjectId, version, retryAttempt },
|
2019-05-29 05:21:06 -04:00
|
|
|
'history s3 download error'
|
|
|
|
)
|
2020-08-03 07:34:04 -04:00
|
|
|
cleanupAbortTrigger()
|
2020-11-30 08:02:12 -05:00
|
|
|
callback(err)
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|
|
|
|
}, retryDelay),
|
2021-04-14 09:17:21 -04:00
|
|
|
function (err) {
|
2019-05-29 05:21:06 -04:00
|
|
|
if (err) {
|
2020-08-19 05:11:32 -04:00
|
|
|
OError.tag(err, 'history s3 download failed', {
|
2020-11-30 08:02:12 -05:00
|
|
|
v1ProjectId,
|
2020-08-19 05:11:32 -04:00
|
|
|
version,
|
2021-04-27 03:52:58 -04:00
|
|
|
retryAttempt,
|
2020-08-19 05:11:32 -04:00
|
|
|
})
|
2020-11-30 08:02:12 -05:00
|
|
|
next(err)
|
2019-05-29 05:21:06 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
)
|
|
|
|
})
|
2021-04-27 03:52:58 -04:00
|
|
|
},
|
2019-05-29 05:21:06 -04:00
|
|
|
}
|