2014-04-29 06:49:09 -04:00
|
|
|
request = require("request").defaults(jar: false)
|
|
|
|
{db, ObjectId} = require("../../../../app/js/mongojs")
|
2015-06-01 17:24:40 -04:00
|
|
|
settings = require("settings-sharelatex")
|
2015-06-02 18:24:45 -04:00
|
|
|
DocArchiveManager = require("../../../../app/js/DocArchiveManager.js")
|
2014-04-29 06:49:09 -04:00
|
|
|
|
|
|
|
module.exports = DocstoreClient =
|
2014-04-30 08:06:12 -04:00
|
|
|
|
2016-12-05 09:21:49 -05:00
|
|
|
createDoc: (project_id, doc_id, lines, version, ranges, callback = (error) ->) ->
|
|
|
|
DocstoreClient.updateDoc project_id, doc_id, lines, version, ranges, callback
|
2014-06-06 07:37:42 -04:00
|
|
|
|
2015-02-03 09:05:08 -05:00
|
|
|
getDoc: (project_id, doc_id, qs, callback = (error, res, body) ->) ->
|
2014-04-29 06:49:09 -04:00
|
|
|
request.get {
|
2015-06-01 17:24:40 -04:00
|
|
|
url: "http://localhost:#{settings.internal.docstore.port}/project/#{project_id}/doc/#{doc_id}"
|
2014-04-29 06:49:09 -04:00
|
|
|
json: true
|
2015-02-03 09:05:08 -05:00
|
|
|
qs:qs
|
2014-04-29 06:49:09 -04:00
|
|
|
}, callback
|
|
|
|
|
2014-04-30 08:06:12 -04:00
|
|
|
getAllDocs: (project_id, callback = (error, res, body) ->) ->
|
|
|
|
request.get {
|
2015-06-01 17:24:40 -04:00
|
|
|
url: "http://localhost:#{settings.internal.docstore.port}/project/#{project_id}/doc"
|
2014-04-30 08:06:12 -04:00
|
|
|
json: true
|
|
|
|
}, callback
|
|
|
|
|
2016-12-09 09:37:24 -05:00
|
|
|
getAllRanges: (project_id, callback = (error, res, body) ->) ->
|
|
|
|
request.get {
|
|
|
|
url: "http://localhost:#{settings.internal.docstore.port}/project/#{project_id}/ranges"
|
|
|
|
json: true
|
|
|
|
}, callback
|
|
|
|
|
2016-12-05 09:21:49 -05:00
|
|
|
updateDoc: (project_id, doc_id, lines, version, ranges, callback = (error, res, body) ->) ->
|
2014-04-29 06:49:09 -04:00
|
|
|
request.post {
|
2015-06-01 17:24:40 -04:00
|
|
|
url: "http://localhost:#{settings.internal.docstore.port}/project/#{project_id}/doc/#{doc_id}"
|
2014-04-29 06:49:09 -04:00
|
|
|
json:
|
|
|
|
lines: lines
|
2016-11-28 09:55:16 -05:00
|
|
|
version: version
|
2016-12-05 09:21:49 -05:00
|
|
|
ranges: ranges
|
2014-04-29 06:49:09 -04:00
|
|
|
}, callback
|
2014-04-29 11:36:10 -04:00
|
|
|
|
|
|
|
deleteDoc: (project_id, doc_id, callback = (error, res, body) ->) ->
|
|
|
|
request.del {
|
2015-06-01 17:24:40 -04:00
|
|
|
url: "http://localhost:#{settings.internal.docstore.port}/project/#{project_id}/doc/#{doc_id}"
|
2014-06-06 07:37:42 -04:00
|
|
|
}, callback
|
2014-04-29 06:49:09 -04:00
|
|
|
|
2015-06-01 17:24:40 -04:00
|
|
|
archiveAllDoc: (project_id, callback = (error, res, body) ->) ->
|
2015-08-18 08:31:26 -04:00
|
|
|
request.post {
|
2015-08-18 09:10:53 -04:00
|
|
|
url: "http://localhost:#{settings.internal.docstore.port}/project/#{project_id}/archive"
|
2015-08-18 08:31:26 -04:00
|
|
|
}, callback
|
|
|
|
|
2015-08-18 09:10:53 -04:00
|
|
|
|
2015-06-02 18:24:45 -04:00
|
|
|
getS3Doc: (project_id, doc_id, callback = (error, res, body) ->) ->
|
2017-03-30 12:13:43 -04:00
|
|
|
options = DocArchiveManager.buildS3Options(project_id+"/"+doc_id)
|
|
|
|
options.json = true
|
|
|
|
request.get options, callback
|