2018-04-13 12:43:21 +00:00
|
|
|
ProjectGetter = require "../Project/ProjectGetter"
|
2018-04-06 13:50:56 +00:00
|
|
|
ProjectLocator = require "../Project/ProjectLocator"
|
2014-02-12 10:23:40 +00:00
|
|
|
ProjectEntityHandler = require "../Project/ProjectEntityHandler"
|
2018-02-01 15:31:42 +00:00
|
|
|
ProjectEntityUpdateHandler = require "../Project/ProjectEntityUpdateHandler"
|
2014-02-12 10:23:40 +00:00
|
|
|
logger = require("logger-sharelatex")
|
|
|
|
|
2014-05-08 12:42:30 +00:00
|
|
|
module.exports =
|
2014-02-12 10:23:40 +00:00
|
|
|
getDocument: (req, res, next = (error) ->) ->
|
|
|
|
project_id = req.params.Project_id
|
|
|
|
doc_id = req.params.doc_id
|
2015-12-18 13:36:25 +00:00
|
|
|
plain = req?.query?.plain == 'true'
|
2014-02-12 10:23:40 +00:00
|
|
|
logger.log doc_id:doc_id, project_id:project_id, "receiving get document request from api (docupdater)"
|
2018-04-13 12:43:21 +00:00
|
|
|
ProjectGetter.getProject project_id, rootFolder: true, overleaf: true, (error, project) ->
|
|
|
|
return next(error) if error?
|
|
|
|
return res.sendStatus(404) if !project?
|
|
|
|
ProjectLocator.findElement {project: project, element_id: doc_id, type: 'doc'}, (error, doc, path) ->
|
2018-04-06 13:50:56 +00:00
|
|
|
if error?
|
2018-04-13 12:43:21 +00:00
|
|
|
logger.err err:error, doc_id:doc_id, project_id:project_id, "error finding element for getDocument"
|
2018-04-06 13:50:56 +00:00
|
|
|
return next(error)
|
2018-04-13 12:43:21 +00:00
|
|
|
ProjectEntityHandler.getDoc project_id, doc_id, (error, lines, rev, version, ranges) ->
|
|
|
|
if error?
|
|
|
|
logger.err err:error, doc_id:doc_id, project_id:project_id, "error finding doc contents for getDocument"
|
|
|
|
return next(error)
|
|
|
|
if plain
|
|
|
|
res.type "text/plain"
|
|
|
|
res.send lines.join('\n')
|
|
|
|
|
|
|
|
else
|
|
|
|
projectHistoryId = project?.overleaf?.history?.id
|
|
|
|
res.type "json"
|
|
|
|
res.send JSON.stringify {
|
|
|
|
lines: lines
|
|
|
|
version: version
|
|
|
|
ranges: ranges
|
|
|
|
pathname: path.fileSystem
|
|
|
|
projectHistoryId: projectHistoryId
|
|
|
|
}
|
2014-02-12 10:23:40 +00:00
|
|
|
|
|
|
|
setDocument: (req, res, next = (error) ->) ->
|
|
|
|
project_id = req.params.Project_id
|
|
|
|
doc_id = req.params.doc_id
|
2016-12-08 14:09:06 +00:00
|
|
|
{lines, version, ranges} = req.body
|
2014-02-12 10:23:40 +00:00
|
|
|
logger.log doc_id:doc_id, project_id:project_id, "receiving set document request from api (docupdater)"
|
2018-02-01 15:31:42 +00:00
|
|
|
ProjectEntityUpdateHandler.updateDocLines project_id, doc_id, lines, version, ranges, (error) ->
|
2014-02-12 10:23:40 +00:00
|
|
|
if error?
|
|
|
|
logger.err err:error, doc_id:doc_id, project_id:project_id, "error finding element for getDocument"
|
|
|
|
return next(error)
|
2014-12-11 16:22:00 +00:00
|
|
|
logger.log doc_id:doc_id, project_id:project_id, "finished receiving set document request from api (docupdater)"
|
2015-07-08 15:56:38 +00:00
|
|
|
res.sendStatus 200
|