|
@@ -1,5 +1,4 @@
|
|
|
/* eslint-disable
|
|
/* eslint-disable
|
|
|
- camelcase,
|
|
|
|
|
n/handle-callback-err,
|
|
n/handle-callback-err,
|
|
|
max-len,
|
|
max-len,
|
|
|
no-unused-vars,
|
|
no-unused-vars,
|
|
@@ -27,59 +26,59 @@ request = request.defaults()
|
|
|
settings = require('@overleaf/settings')
|
|
settings = require('@overleaf/settings')
|
|
|
|
|
|
|
|
module.exports = ExportsHandler = {
|
|
module.exports = ExportsHandler = {
|
|
|
- exportProject(export_params, callback) {
|
|
|
|
|
|
|
+ exportProject(exportParams, callback) {
|
|
|
if (callback == null) {
|
|
if (callback == null) {
|
|
|
callback = function () {}
|
|
callback = function () {}
|
|
|
}
|
|
}
|
|
|
return ExportsHandler._buildExport(
|
|
return ExportsHandler._buildExport(
|
|
|
- export_params,
|
|
|
|
|
- function (err, export_data) {
|
|
|
|
|
|
|
+ exportParams,
|
|
|
|
|
+ function (err, exportData) {
|
|
|
if (err != null) {
|
|
if (err != null) {
|
|
|
return callback(err)
|
|
return callback(err)
|
|
|
}
|
|
}
|
|
|
- return ExportsHandler._requestExport(export_data, function (err, body) {
|
|
|
|
|
|
|
+ return ExportsHandler._requestExport(exportData, function (err, body) {
|
|
|
if (err != null) {
|
|
if (err != null) {
|
|
|
return callback(err)
|
|
return callback(err)
|
|
|
}
|
|
}
|
|
|
- export_data.v1_id = body.exportId
|
|
|
|
|
- export_data.message = body.message
|
|
|
|
|
|
|
+ exportData.v1_id = body.exportId
|
|
|
|
|
+ exportData.message = body.message
|
|
|
// TODO: possibly store the export data in Mongo
|
|
// TODO: possibly store the export data in Mongo
|
|
|
- return callback(null, export_data)
|
|
|
|
|
|
|
+ return callback(null, exportData)
|
|
|
})
|
|
})
|
|
|
}
|
|
}
|
|
|
)
|
|
)
|
|
|
},
|
|
},
|
|
|
|
|
|
|
|
- _buildExport(export_params, callback) {
|
|
|
|
|
|
|
+ _buildExport(exportParams, callback) {
|
|
|
if (callback == null) {
|
|
if (callback == null) {
|
|
|
callback = function () {}
|
|
callback = function () {}
|
|
|
}
|
|
}
|
|
|
const {
|
|
const {
|
|
|
- project_id,
|
|
|
|
|
- user_id,
|
|
|
|
|
- brand_variation_id,
|
|
|
|
|
|
|
+ project_id: projectId,
|
|
|
|
|
+ user_id: userId,
|
|
|
|
|
+ brand_variation_id: brandVariationId,
|
|
|
title,
|
|
title,
|
|
|
description,
|
|
description,
|
|
|
author,
|
|
author,
|
|
|
license,
|
|
license,
|
|
|
- show_source,
|
|
|
|
|
- } = export_params
|
|
|
|
|
|
|
+ show_source: showSource,
|
|
|
|
|
+ } = exportParams
|
|
|
const jobs = {
|
|
const jobs = {
|
|
|
project(cb) {
|
|
project(cb) {
|
|
|
- return ProjectGetter.getProject(project_id, cb)
|
|
|
|
|
|
|
+ return ProjectGetter.getProject(projectId, cb)
|
|
|
},
|
|
},
|
|
|
// TODO: when we update async, signature will change from (cb, results) to (results, cb)
|
|
// TODO: when we update async, signature will change from (cb, results) to (results, cb)
|
|
|
rootDoc: [
|
|
rootDoc: [
|
|
|
'project',
|
|
'project',
|
|
|
(results, cb) =>
|
|
(results, cb) =>
|
|
|
ProjectRootDocManager.ensureRootDocumentIsValid(
|
|
ProjectRootDocManager.ensureRootDocumentIsValid(
|
|
|
- project_id,
|
|
|
|
|
|
|
+ projectId,
|
|
|
function (error) {
|
|
function (error) {
|
|
|
if (error != null) {
|
|
if (error != null) {
|
|
|
return callback(error)
|
|
return callback(error)
|
|
|
}
|
|
}
|
|
|
return ProjectLocator.findRootDoc(
|
|
return ProjectLocator.findRootDoc(
|
|
|
- { project: results.project, project_id },
|
|
|
|
|
|
|
+ { project: results.project, project_id: projectId },
|
|
|
cb
|
|
cb
|
|
|
)
|
|
)
|
|
|
}
|
|
}
|
|
@@ -87,19 +86,19 @@ module.exports = ExportsHandler = {
|
|
|
],
|
|
],
|
|
|
user(cb) {
|
|
user(cb) {
|
|
|
return UserGetter.getUser(
|
|
return UserGetter.getUser(
|
|
|
- user_id,
|
|
|
|
|
|
|
+ userId,
|
|
|
{ first_name: 1, last_name: 1, email: 1, overleaf: 1 },
|
|
{ first_name: 1, last_name: 1, email: 1, overleaf: 1 },
|
|
|
cb
|
|
cb
|
|
|
)
|
|
)
|
|
|
},
|
|
},
|
|
|
historyVersion(cb) {
|
|
historyVersion(cb) {
|
|
|
return ProjectHistoryHandler.ensureHistoryExistsForProject(
|
|
return ProjectHistoryHandler.ensureHistoryExistsForProject(
|
|
|
- project_id,
|
|
|
|
|
|
|
+ projectId,
|
|
|
function (error) {
|
|
function (error) {
|
|
|
if (error != null) {
|
|
if (error != null) {
|
|
|
return callback(error)
|
|
return callback(error)
|
|
|
}
|
|
}
|
|
|
- return ExportsHandler._requestVersion(project_id, cb)
|
|
|
|
|
|
|
+ return ExportsHandler._requestVersion(projectId, cb)
|
|
|
}
|
|
}
|
|
|
)
|
|
)
|
|
|
},
|
|
},
|
|
@@ -108,9 +107,9 @@ module.exports = ExportsHandler = {
|
|
|
return async.auto(jobs, function (err, results) {
|
|
return async.auto(jobs, function (err, results) {
|
|
|
if (err != null) {
|
|
if (err != null) {
|
|
|
OError.tag(err, 'error building project export', {
|
|
OError.tag(err, 'error building project export', {
|
|
|
- project_id,
|
|
|
|
|
- user_id,
|
|
|
|
|
- brand_variation_id,
|
|
|
|
|
|
|
+ project_id: projectId,
|
|
|
|
|
+ user_id: userId,
|
|
|
|
|
+ brand_variation_id: brandVariationId,
|
|
|
})
|
|
})
|
|
|
return callback(err)
|
|
return callback(err)
|
|
|
}
|
|
}
|
|
@@ -118,19 +117,19 @@ module.exports = ExportsHandler = {
|
|
|
const { project, rootDoc, user, historyVersion } = results
|
|
const { project, rootDoc, user, historyVersion } = results
|
|
|
if (!rootDoc || rootDoc[1] == null) {
|
|
if (!rootDoc || rootDoc[1] == null) {
|
|
|
err = new OError('cannot export project without root doc', {
|
|
err = new OError('cannot export project without root doc', {
|
|
|
- project_id,
|
|
|
|
|
|
|
+ project_id: projectId,
|
|
|
})
|
|
})
|
|
|
return callback(err)
|
|
return callback(err)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- if (export_params.first_name && export_params.last_name) {
|
|
|
|
|
- user.first_name = export_params.first_name
|
|
|
|
|
- user.last_name = export_params.last_name
|
|
|
|
|
|
|
+ if (exportParams.first_name && exportParams.last_name) {
|
|
|
|
|
+ user.first_name = exportParams.first_name
|
|
|
|
|
+ user.last_name = exportParams.last_name
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- const export_data = {
|
|
|
|
|
|
|
+ const exportData = {
|
|
|
project: {
|
|
project: {
|
|
|
- id: project_id,
|
|
|
|
|
|
|
+ id: projectId,
|
|
|
rootDocPath: rootDoc[1] != null ? rootDoc[1].fileSystem : undefined,
|
|
rootDocPath: rootDoc[1] != null ? rootDoc[1].fileSystem : undefined,
|
|
|
historyId: project.overleaf?.history?.id,
|
|
historyId: project.overleaf?.history?.id,
|
|
|
historyVersion,
|
|
historyVersion,
|
|
@@ -143,11 +142,11 @@ module.exports = ExportsHandler = {
|
|
|
description,
|
|
description,
|
|
|
author,
|
|
author,
|
|
|
license,
|
|
license,
|
|
|
- showSource: show_source,
|
|
|
|
|
|
|
+ showSource,
|
|
|
},
|
|
},
|
|
|
},
|
|
},
|
|
|
user: {
|
|
user: {
|
|
|
- id: user_id,
|
|
|
|
|
|
|
+ id: userId,
|
|
|
firstName: user.first_name,
|
|
firstName: user.first_name,
|
|
|
lastName: user.last_name,
|
|
lastName: user.last_name,
|
|
|
email: user.email,
|
|
email: user.email,
|
|
@@ -155,17 +154,17 @@ module.exports = ExportsHandler = {
|
|
|
v1UserId: user.overleaf != null ? user.overleaf.id : undefined,
|
|
v1UserId: user.overleaf != null ? user.overleaf.id : undefined,
|
|
|
},
|
|
},
|
|
|
destination: {
|
|
destination: {
|
|
|
- brandVariationId: brand_variation_id,
|
|
|
|
|
|
|
+ brandVariationId,
|
|
|
},
|
|
},
|
|
|
options: {
|
|
options: {
|
|
|
callbackUrl: null,
|
|
callbackUrl: null,
|
|
|
}, // for now, until we want v1 to call us back
|
|
}, // for now, until we want v1 to call us back
|
|
|
}
|
|
}
|
|
|
- return callback(null, export_data)
|
|
|
|
|
|
|
+ return callback(null, exportData)
|
|
|
})
|
|
})
|
|
|
},
|
|
},
|
|
|
|
|
|
|
|
- _requestExport(export_data, callback) {
|
|
|
|
|
|
|
+ _requestExport(exportData, callback) {
|
|
|
if (callback == null) {
|
|
if (callback == null) {
|
|
|
callback = function () {}
|
|
callback = function () {}
|
|
|
}
|
|
}
|
|
@@ -173,20 +172,20 @@ module.exports = ExportsHandler = {
|
|
|
{
|
|
{
|
|
|
url: `${settings.apis.v1.url}/api/v1/sharelatex/exports`,
|
|
url: `${settings.apis.v1.url}/api/v1/sharelatex/exports`,
|
|
|
auth: { user: settings.apis.v1.user, pass: settings.apis.v1.pass },
|
|
auth: { user: settings.apis.v1.user, pass: settings.apis.v1.pass },
|
|
|
- json: export_data,
|
|
|
|
|
|
|
+ json: exportData,
|
|
|
timeout: settings.apis.v1.timeout,
|
|
timeout: settings.apis.v1.timeout,
|
|
|
},
|
|
},
|
|
|
function (err, res, body) {
|
|
function (err, res, body) {
|
|
|
if (err != null) {
|
|
if (err != null) {
|
|
|
OError.tag(err, 'error making request to v1 export', {
|
|
OError.tag(err, 'error making request to v1 export', {
|
|
|
- export: export_data,
|
|
|
|
|
|
|
+ export: exportData,
|
|
|
})
|
|
})
|
|
|
return callback(err)
|
|
return callback(err)
|
|
|
} else if (res.statusCode >= 200 && res.statusCode < 300) {
|
|
} else if (res.statusCode >= 200 && res.statusCode < 300) {
|
|
|
return callback(null, body)
|
|
return callback(null, body)
|
|
|
} else {
|
|
} else {
|
|
|
logger.warn(
|
|
logger.warn(
|
|
|
- { export: export_data },
|
|
|
|
|
|
|
+ { export: exportData },
|
|
|
`v1 export returned failure; forwarding: ${body}`
|
|
`v1 export returned failure; forwarding: ${body}`
|
|
|
)
|
|
)
|
|
|
// pass the v1 error along for the publish modal to handle
|
|
// pass the v1 error along for the publish modal to handle
|
|
@@ -197,19 +196,19 @@ module.exports = ExportsHandler = {
|
|
|
)
|
|
)
|
|
|
},
|
|
},
|
|
|
|
|
|
|
|
- _requestVersion(project_id, callback) {
|
|
|
|
|
|
|
+ _requestVersion(projectId, callback) {
|
|
|
if (callback == null) {
|
|
if (callback == null) {
|
|
|
callback = function () {}
|
|
callback = function () {}
|
|
|
}
|
|
}
|
|
|
return request.get(
|
|
return request.get(
|
|
|
{
|
|
{
|
|
|
- url: `${settings.apis.project_history.url}/project/${project_id}/version`,
|
|
|
|
|
|
|
+ url: `${settings.apis.project_history.url}/project/${projectId}/version`,
|
|
|
json: true,
|
|
json: true,
|
|
|
},
|
|
},
|
|
|
function (err, res, body) {
|
|
function (err, res, body) {
|
|
|
if (err != null) {
|
|
if (err != null) {
|
|
|
OError.tag(err, 'error making request to project history', {
|
|
OError.tag(err, 'error making request to project history', {
|
|
|
- project_id,
|
|
|
|
|
|
|
+ project_id: projectId,
|
|
|
})
|
|
})
|
|
|
return callback(err)
|
|
return callback(err)
|
|
|
} else if (res.statusCode >= 200 && res.statusCode < 300) {
|
|
} else if (res.statusCode >= 200 && res.statusCode < 300) {
|
|
@@ -217,7 +216,7 @@ module.exports = ExportsHandler = {
|
|
|
} else {
|
|
} else {
|
|
|
err = new OError(
|
|
err = new OError(
|
|
|
`project history version returned a failure status code: ${res.statusCode}`,
|
|
`project history version returned a failure status code: ${res.statusCode}`,
|
|
|
- { project_id }
|
|
|
|
|
|
|
+ { project_id: projectId }
|
|
|
)
|
|
)
|
|
|
return callback(err)
|
|
return callback(err)
|
|
|
}
|
|
}
|
|
@@ -225,20 +224,20 @@ module.exports = ExportsHandler = {
|
|
|
)
|
|
)
|
|
|
},
|
|
},
|
|
|
|
|
|
|
|
- fetchExport(export_id, callback) {
|
|
|
|
|
|
|
+ fetchExport(exportId, callback) {
|
|
|
if (callback == null) {
|
|
if (callback == null) {
|
|
|
callback = function () {}
|
|
callback = function () {}
|
|
|
}
|
|
}
|
|
|
return request.get(
|
|
return request.get(
|
|
|
{
|
|
{
|
|
|
- url: `${settings.apis.v1.url}/api/v1/sharelatex/exports/${export_id}`,
|
|
|
|
|
|
|
+ url: `${settings.apis.v1.url}/api/v1/sharelatex/exports/${exportId}`,
|
|
|
auth: { user: settings.apis.v1.user, pass: settings.apis.v1.pass },
|
|
auth: { user: settings.apis.v1.user, pass: settings.apis.v1.pass },
|
|
|
timeout: settings.apis.v1.timeout,
|
|
timeout: settings.apis.v1.timeout,
|
|
|
},
|
|
},
|
|
|
function (err, res, body) {
|
|
function (err, res, body) {
|
|
|
if (err != null) {
|
|
if (err != null) {
|
|
|
OError.tag(err, 'error making request to v1 export', {
|
|
OError.tag(err, 'error making request to v1 export', {
|
|
|
- export: export_id,
|
|
|
|
|
|
|
+ export: exportId,
|
|
|
})
|
|
})
|
|
|
return callback(err)
|
|
return callback(err)
|
|
|
} else if (res.statusCode >= 200 && res.statusCode < 300) {
|
|
} else if (res.statusCode >= 200 && res.statusCode < 300) {
|
|
@@ -246,7 +245,7 @@ module.exports = ExportsHandler = {
|
|
|
} else {
|
|
} else {
|
|
|
err = new OError(
|
|
err = new OError(
|
|
|
`v1 export returned a failure status code: ${res.statusCode}`,
|
|
`v1 export returned a failure status code: ${res.statusCode}`,
|
|
|
- { export: export_id }
|
|
|
|
|
|
|
+ { export: exportId }
|
|
|
)
|
|
)
|
|
|
return callback(err)
|
|
return callback(err)
|
|
|
}
|
|
}
|
|
@@ -254,20 +253,20 @@ module.exports = ExportsHandler = {
|
|
|
)
|
|
)
|
|
|
},
|
|
},
|
|
|
|
|
|
|
|
- fetchDownload(export_id, type, callback) {
|
|
|
|
|
|
|
+ fetchDownload(exportId, type, callback) {
|
|
|
if (callback == null) {
|
|
if (callback == null) {
|
|
|
callback = function () {}
|
|
callback = function () {}
|
|
|
}
|
|
}
|
|
|
return request.get(
|
|
return request.get(
|
|
|
{
|
|
{
|
|
|
- url: `${settings.apis.v1.url}/api/v1/sharelatex/exports/${export_id}/${type}_url`,
|
|
|
|
|
|
|
+ url: `${settings.apis.v1.url}/api/v1/sharelatex/exports/${exportId}/${type}_url`,
|
|
|
auth: { user: settings.apis.v1.user, pass: settings.apis.v1.pass },
|
|
auth: { user: settings.apis.v1.user, pass: settings.apis.v1.pass },
|
|
|
timeout: settings.apis.v1.timeout,
|
|
timeout: settings.apis.v1.timeout,
|
|
|
},
|
|
},
|
|
|
function (err, res, body) {
|
|
function (err, res, body) {
|
|
|
if (err != null) {
|
|
if (err != null) {
|
|
|
OError.tag(err, 'error making request to v1 export', {
|
|
OError.tag(err, 'error making request to v1 export', {
|
|
|
- export: export_id,
|
|
|
|
|
|
|
+ export: exportId,
|
|
|
})
|
|
})
|
|
|
return callback(err)
|
|
return callback(err)
|
|
|
} else if (res.statusCode >= 200 && res.statusCode < 300) {
|
|
} else if (res.statusCode >= 200 && res.statusCode < 300) {
|
|
@@ -275,7 +274,7 @@ module.exports = ExportsHandler = {
|
|
|
} else {
|
|
} else {
|
|
|
err = new OError(
|
|
err = new OError(
|
|
|
`v1 export returned a failure status code: ${res.statusCode}`,
|
|
`v1 export returned a failure status code: ${res.statusCode}`,
|
|
|
- { export: export_id }
|
|
|
|
|
|
|
+ { export: exportId }
|
|
|
)
|
|
)
|
|
|
return callback(err)
|
|
return callback(err)
|
|
|
}
|
|
}
|