ExportsController.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. /* eslint-disable
  2. camelcase,
  3. max-len,
  4. */
  5. // TODO: This file was created by bulk-decaffeinate.
  6. // Fix any style issues and re-enable lint.
  7. /*
  8. * decaffeinate suggestions:
  9. * DS102: Remove unnecessary code created because of implicit returns
  10. * DS207: Consider shorter variations of null checks
  11. * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
  12. */
  13. const ExportsHandler = require('./ExportsHandler')
  14. const SessionManager = require('../Authentication/SessionManager')
  15. const logger = require('logger-sharelatex')
  16. module.exports = {
  17. exportProject(req, res, next) {
  18. const { project_id, brand_variation_id } = req.params
  19. const user_id = SessionManager.getLoggedInUserId(req.session)
  20. const export_params = {
  21. project_id,
  22. brand_variation_id,
  23. user_id,
  24. }
  25. if (req.body) {
  26. if (req.body.firstName) {
  27. export_params.first_name = req.body.firstName.trim()
  28. }
  29. if (req.body.lastName) {
  30. export_params.last_name = req.body.lastName.trim()
  31. }
  32. // additional parameters for gallery exports
  33. if (req.body.title) {
  34. export_params.title = req.body.title.trim()
  35. }
  36. if (req.body.description) {
  37. export_params.description = req.body.description.trim()
  38. }
  39. if (req.body.author) {
  40. export_params.author = req.body.author.trim()
  41. }
  42. if (req.body.license) {
  43. export_params.license = req.body.license.trim()
  44. }
  45. if (req.body.showSource != null) {
  46. export_params.show_source = req.body.showSource
  47. }
  48. }
  49. return ExportsHandler.exportProject(
  50. export_params,
  51. function (err, export_data) {
  52. if (err != null) {
  53. if (err.forwardResponse != null) {
  54. logger.log(
  55. { responseError: err.forwardResponse },
  56. 'forwarding response'
  57. )
  58. const statusCode = err.forwardResponse.status || 500
  59. return res.status(statusCode).json(err.forwardResponse)
  60. } else {
  61. return next(err)
  62. }
  63. }
  64. logger.log(
  65. {
  66. user_id,
  67. project_id,
  68. brand_variation_id,
  69. export_v1_id: export_data.v1_id,
  70. },
  71. 'exported project'
  72. )
  73. return res.json({
  74. export_v1_id: export_data.v1_id,
  75. message: export_data.message,
  76. })
  77. }
  78. )
  79. },
  80. exportStatus(req, res) {
  81. const { export_id } = req.params
  82. return ExportsHandler.fetchExport(export_id, function (err, export_json) {
  83. let json
  84. if (err != null) {
  85. json = {
  86. status_summary: 'failed',
  87. status_detail: err.toString,
  88. }
  89. res.json({ export_json: json })
  90. return err
  91. }
  92. const parsed_export = JSON.parse(export_json)
  93. json = {
  94. status_summary: parsed_export.status_summary,
  95. status_detail: parsed_export.status_detail,
  96. partner_submission_id: parsed_export.partner_submission_id,
  97. v2_user_email: parsed_export.v2_user_email,
  98. v2_user_first_name: parsed_export.v2_user_first_name,
  99. v2_user_last_name: parsed_export.v2_user_last_name,
  100. title: parsed_export.title,
  101. token: parsed_export.token,
  102. }
  103. return res.json({ export_json: json })
  104. })
  105. },
  106. exportDownload(req, res, next) {
  107. const { type, export_id } = req.params
  108. SessionManager.getLoggedInUserId(req.session)
  109. return ExportsHandler.fetchDownload(
  110. export_id,
  111. type,
  112. function (err, export_file_url) {
  113. if (err != null) {
  114. return next(err)
  115. }
  116. return res.redirect(export_file_url)
  117. }
  118. )
  119. },
  120. }