2020-02-16 09:03:03 -05:00
|
|
|
/* eslint-disable
|
|
|
|
camelcase,
|
|
|
|
handle-callback-err,
|
|
|
|
no-unused-vars,
|
|
|
|
*/
|
|
|
|
// TODO: This file was created by bulk-decaffeinate.
|
|
|
|
// Fix any style issues and re-enable lint.
|
2020-02-16 09:03:02 -05:00
|
|
|
/*
|
|
|
|
* decaffeinate suggestions:
|
|
|
|
* DS102: Remove unnecessary code created because of implicit returns
|
|
|
|
* DS207: Consider shorter variations of null checks
|
|
|
|
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
|
|
|
|
*/
|
2020-02-16 09:03:09 -05:00
|
|
|
let DocstoreClient
|
|
|
|
const request = require('request').defaults({ jar: false })
|
|
|
|
const { db, ObjectId } = require('../../../../app/js/mongojs')
|
|
|
|
const settings = require('settings-sharelatex')
|
|
|
|
const DocArchiveManager = require('../../../../app/js/DocArchiveManager.js')
|
2014-04-29 06:49:09 -04:00
|
|
|
|
2020-02-16 09:03:09 -05:00
|
|
|
module.exports = DocstoreClient = {
|
|
|
|
createDoc(project_id, doc_id, lines, version, ranges, callback) {
|
|
|
|
if (callback == null) {
|
|
|
|
callback = function(error) {}
|
|
|
|
}
|
|
|
|
return DocstoreClient.updateDoc(
|
|
|
|
project_id,
|
|
|
|
doc_id,
|
|
|
|
lines,
|
|
|
|
version,
|
|
|
|
ranges,
|
|
|
|
callback
|
|
|
|
)
|
|
|
|
},
|
2014-04-30 08:06:12 -04:00
|
|
|
|
2020-02-16 09:03:09 -05:00
|
|
|
getDoc(project_id, doc_id, qs, callback) {
|
|
|
|
if (callback == null) {
|
|
|
|
callback = function(error, res, body) {}
|
|
|
|
}
|
|
|
|
return request.get(
|
|
|
|
{
|
|
|
|
url: `http://localhost:${settings.internal.docstore.port}/project/${project_id}/doc/${doc_id}`,
|
|
|
|
json: true,
|
|
|
|
qs
|
|
|
|
},
|
|
|
|
callback
|
|
|
|
)
|
|
|
|
},
|
2014-06-06 07:37:42 -04:00
|
|
|
|
2020-02-16 09:03:09 -05:00
|
|
|
getAllDocs(project_id, callback) {
|
|
|
|
if (callback == null) {
|
|
|
|
callback = function(error, res, body) {}
|
|
|
|
}
|
|
|
|
return request.get(
|
|
|
|
{
|
|
|
|
url: `http://localhost:${settings.internal.docstore.port}/project/${project_id}/doc`,
|
|
|
|
json: true
|
|
|
|
},
|
|
|
|
callback
|
|
|
|
)
|
|
|
|
},
|
2014-04-29 06:49:09 -04:00
|
|
|
|
2020-02-16 09:03:09 -05:00
|
|
|
getAllRanges(project_id, callback) {
|
|
|
|
if (callback == null) {
|
|
|
|
callback = function(error, res, body) {}
|
|
|
|
}
|
|
|
|
return request.get(
|
|
|
|
{
|
|
|
|
url: `http://localhost:${settings.internal.docstore.port}/project/${project_id}/ranges`,
|
|
|
|
json: true
|
|
|
|
},
|
|
|
|
callback
|
|
|
|
)
|
|
|
|
},
|
2014-04-30 08:06:12 -04:00
|
|
|
|
2020-02-16 09:03:09 -05:00
|
|
|
updateDoc(project_id, doc_id, lines, version, ranges, callback) {
|
|
|
|
if (callback == null) {
|
|
|
|
callback = function(error, res, body) {}
|
|
|
|
}
|
|
|
|
return request.post(
|
|
|
|
{
|
|
|
|
url: `http://localhost:${settings.internal.docstore.port}/project/${project_id}/doc/${doc_id}`,
|
|
|
|
json: {
|
|
|
|
lines,
|
|
|
|
version,
|
|
|
|
ranges
|
|
|
|
}
|
|
|
|
},
|
|
|
|
callback
|
|
|
|
)
|
|
|
|
},
|
2020-02-16 09:03:02 -05:00
|
|
|
|
2020-02-16 09:03:09 -05:00
|
|
|
deleteDoc(project_id, doc_id, callback) {
|
|
|
|
if (callback == null) {
|
|
|
|
callback = function(error, res, body) {}
|
|
|
|
}
|
|
|
|
return request.del(
|
|
|
|
{
|
|
|
|
url: `http://localhost:${settings.internal.docstore.port}/project/${project_id}/doc/${doc_id}`
|
|
|
|
},
|
|
|
|
callback
|
|
|
|
)
|
|
|
|
},
|
2020-02-16 09:03:02 -05:00
|
|
|
|
2020-02-16 09:03:09 -05:00
|
|
|
archiveAllDoc(project_id, callback) {
|
|
|
|
if (callback == null) {
|
|
|
|
callback = function(error, res, body) {}
|
|
|
|
}
|
|
|
|
return request.post(
|
|
|
|
{
|
|
|
|
url: `http://localhost:${settings.internal.docstore.port}/project/${project_id}/archive`
|
|
|
|
},
|
|
|
|
callback
|
|
|
|
)
|
|
|
|
},
|
2020-02-16 09:03:02 -05:00
|
|
|
|
2020-02-16 09:03:09 -05:00
|
|
|
destroyAllDoc(project_id, callback) {
|
|
|
|
if (callback == null) {
|
|
|
|
callback = function(error, res, body) {}
|
|
|
|
}
|
|
|
|
return request.post(
|
|
|
|
{
|
|
|
|
url: `http://localhost:${settings.internal.docstore.port}/project/${project_id}/destroy`
|
|
|
|
},
|
|
|
|
callback
|
|
|
|
)
|
|
|
|
},
|
2020-02-16 09:03:02 -05:00
|
|
|
|
2020-02-16 09:03:09 -05:00
|
|
|
getS3Doc(project_id, doc_id, callback) {
|
|
|
|
if (callback == null) {
|
|
|
|
callback = function(error, res, body) {}
|
|
|
|
}
|
|
|
|
const options = DocArchiveManager.buildS3Options(project_id + '/' + doc_id)
|
|
|
|
options.json = true
|
|
|
|
return request.get(options, callback)
|
|
|
|
}
|
|
|
|
}
|