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