2018-02-14 10:12:46 -05:00
|
|
|
AuthenticationController = require '../Authentication/AuthenticationController'
|
|
|
|
EditorController = require '../Editor/EditorController'
|
|
|
|
|
|
|
|
module.exports = LinkedFilesController = {
|
|
|
|
Agents: {
|
|
|
|
url: require('./UrlAgent')
|
|
|
|
}
|
|
|
|
|
|
|
|
createLinkedFile: (req, res, next) ->
|
|
|
|
{project_id} = req.params
|
|
|
|
{name, provider, data, parent_folder_id} = req.body
|
|
|
|
user_id = AuthenticationController.getLoggedInUserId(req)
|
|
|
|
|
|
|
|
if !LinkedFilesController.Agents.hasOwnProperty(provider)
|
|
|
|
return res.send(400)
|
|
|
|
Agent = LinkedFilesController.Agents[provider]
|
|
|
|
|
|
|
|
linkedFileData = Agent.sanitizeData(data)
|
|
|
|
linkedFileData.provider = provider
|
|
|
|
Agent.writeIncomingFileToDisk project_id, linkedFileData, user_id, (error, fsPath) ->
|
2018-02-16 12:13:26 -05:00
|
|
|
if error?
|
|
|
|
return Agent.handleError(error, req, res, next)
|
2018-02-14 10:12:46 -05:00
|
|
|
EditorController.upsertFile project_id, parent_folder_id, name, fsPath, linkedFileData, "upload", user_id, (error) ->
|
|
|
|
return next(error) if error?
|
|
|
|
res.send(204) # created
|
|
|
|
}
|