2014-02-12 05:23:40 -05:00
|
|
|
ProjectEntityHandler = require "../Project/ProjectEntityHandler"
|
2018-02-01 10:31:42 -05:00
|
|
|
ProjectEntityUpdateHandler = require "../Project/ProjectEntityUpdateHandler"
|
2014-02-12 05:23:40 -05:00
|
|
|
logger = require("logger-sharelatex")
|
|
|
|
|
2014-05-08 08:42:30 -04:00
|
|
|
module.exports =
|
2014-02-12 05:23:40 -05:00
|
|
|
getDocument: (req, res, next = (error) ->) ->
|
|
|
|
project_id = req.params.Project_id
|
|
|
|
doc_id = req.params.doc_id
|
2015-12-18 08:36:25 -05:00
|
|
|
plain = req?.query?.plain == 'true'
|
2014-02-12 05:23:40 -05:00
|
|
|
logger.log doc_id:doc_id, project_id:project_id, "receiving get document request from api (docupdater)"
|
2017-09-28 10:01:45 -04:00
|
|
|
ProjectEntityHandler.getDoc project_id, doc_id, {pathname: true}, (error, lines, rev, version, ranges, pathname) ->
|
2014-02-12 05:23:40 -05:00
|
|
|
if error?
|
|
|
|
logger.err err:error, doc_id:doc_id, project_id:project_id, "error finding element for getDocument"
|
|
|
|
return next(error)
|
2015-12-18 08:36:25 -05:00
|
|
|
if plain
|
|
|
|
res.type "text/plain"
|
|
|
|
res.send lines.join('\n')
|
|
|
|
else
|
|
|
|
res.type "json"
|
|
|
|
res.send JSON.stringify {
|
|
|
|
lines: lines
|
2016-11-29 12:16:56 -05:00
|
|
|
version: version
|
2016-12-08 09:09:06 -05:00
|
|
|
ranges: ranges
|
2017-09-28 10:01:45 -04:00
|
|
|
pathname: pathname
|
2015-12-18 08:36:25 -05:00
|
|
|
}
|
2014-02-12 05:23:40 -05:00
|
|
|
|
|
|
|
setDocument: (req, res, next = (error) ->) ->
|
|
|
|
project_id = req.params.Project_id
|
|
|
|
doc_id = req.params.doc_id
|
2016-12-08 09:09:06 -05:00
|
|
|
{lines, version, ranges} = req.body
|
2014-02-12 05:23:40 -05:00
|
|
|
logger.log doc_id:doc_id, project_id:project_id, "receiving set document request from api (docupdater)"
|
2018-02-01 10:31:42 -05:00
|
|
|
ProjectEntityUpdateHandler.updateDocLines project_id, doc_id, lines, version, ranges, (error) ->
|
2014-02-12 05:23:40 -05: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 11:22:00 -05:00
|
|
|
logger.log doc_id:doc_id, project_id:project_id, "finished receiving set document request from api (docupdater)"
|
2015-07-08 11:56:38 -04:00
|
|
|
res.sendStatus 200
|