overleaf/services/web/app/coffee/Features/LinkedFiles/LinkedFilesController.coffee

26 lines
957 B
CoffeeScript
Raw Normal View History

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) ->
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
}