LinkedFilesController.coffee 957 B

1234567891011121314151617181920212223242526
  1. AuthenticationController = require '../Authentication/AuthenticationController'
  2. EditorController = require '../Editor/EditorController'
  3. module.exports = LinkedFilesController = {
  4. Agents: {
  5. url: require('./UrlAgent')
  6. }
  7. createLinkedFile: (req, res, next) ->
  8. {project_id} = req.params
  9. {name, provider, data, parent_folder_id} = req.body
  10. user_id = AuthenticationController.getLoggedInUserId(req)
  11. if !LinkedFilesController.Agents.hasOwnProperty(provider)
  12. return res.send(400)
  13. Agent = LinkedFilesController.Agents[provider]
  14. linkedFileData = Agent.sanitizeData(data)
  15. linkedFileData.provider = provider
  16. Agent.writeIncomingFileToDisk project_id, linkedFileData, user_id, (error, fsPath) ->
  17. if error?
  18. return Agent.handleError(error, req, res, next)
  19. EditorController.upsertFile project_id, parent_folder_id, name, fsPath, linkedFileData, "upload", user_id, (error) ->
  20. return next(error) if error?
  21. res.send(204) # created
  22. }