ExportsController.coffee 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. ExportsHandler = require("./ExportsHandler")
  2. AuthenticationController = require("../Authentication/AuthenticationController")
  3. logger = require("logger-sharelatex")
  4. module.exports =
  5. exportProject: (req, res) ->
  6. {project_id, brand_variation_id} = req.params
  7. user_id = AuthenticationController.getLoggedInUserId(req)
  8. export_params = {
  9. project_id: project_id,
  10. brand_variation_id: brand_variation_id,
  11. user_id: user_id
  12. }
  13. if req.body && req.body.firstName && req.body.lastName
  14. export_params.first_name = req.body.firstName.trim()
  15. export_params.last_name = req.body.lastName.trim()
  16. ExportsHandler.exportProject export_params, (err, export_data) ->
  17. return next(err) if err?
  18. logger.log
  19. user_id:user_id
  20. project_id: project_id
  21. brand_variation_id:brand_variation_id
  22. export_v1_id:export_data.v1_id
  23. "exported project"
  24. res.send export_v1_id: export_data.v1_id
  25. exportStatus: (req, res) ->
  26. {export_id} = req.params
  27. ExportsHandler.fetchExport export_id, (err, export_json) ->
  28. return next(err) if err?
  29. parsed_export = JSON.parse(export_json)
  30. json = {
  31. status_summary: parsed_export.status_summary,
  32. status_detail: parsed_export.status_detail
  33. }
  34. res.send export_json: json
  35. exportZip: (req, res) ->
  36. {export_id} = req.params
  37. AuthenticationController.getLoggedInUserId(req)
  38. ExportsHandler.fetchZip export_id, (err, export_zip_url) ->
  39. return err if err?
  40. res.redirect export_zip_url