DocstoreClient.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. /* eslint-disable
  2. camelcase,
  3. handle-callback-err,
  4. no-unused-vars,
  5. */
  6. // TODO: This file was created by bulk-decaffeinate.
  7. // Fix any style issues and re-enable lint.
  8. /*
  9. * decaffeinate suggestions:
  10. * DS102: Remove unnecessary code created because of implicit returns
  11. * DS207: Consider shorter variations of null checks
  12. * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
  13. */
  14. let DocstoreClient
  15. const request = require('request').defaults({ jar: false })
  16. const { db, ObjectId } = require('../../../../app/js/mongojs')
  17. const settings = require('settings-sharelatex')
  18. const DocArchiveManager = require('../../../../app/js/DocArchiveManager.js')
  19. module.exports = DocstoreClient = {
  20. createDoc(project_id, doc_id, lines, version, ranges, callback) {
  21. if (callback == null) {
  22. callback = function (error) {}
  23. }
  24. return DocstoreClient.updateDoc(
  25. project_id,
  26. doc_id,
  27. lines,
  28. version,
  29. ranges,
  30. callback
  31. )
  32. },
  33. getDoc(project_id, doc_id, qs, callback) {
  34. if (callback == null) {
  35. callback = function (error, res, body) {}
  36. }
  37. return request.get(
  38. {
  39. url: `http://localhost:${settings.internal.docstore.port}/project/${project_id}/doc/${doc_id}`,
  40. json: true,
  41. qs
  42. },
  43. callback
  44. )
  45. },
  46. getAllDocs(project_id, callback) {
  47. if (callback == null) {
  48. callback = function (error, res, body) {}
  49. }
  50. return request.get(
  51. {
  52. url: `http://localhost:${settings.internal.docstore.port}/project/${project_id}/doc`,
  53. json: true
  54. },
  55. callback
  56. )
  57. },
  58. getAllRanges(project_id, callback) {
  59. if (callback == null) {
  60. callback = function (error, res, body) {}
  61. }
  62. return request.get(
  63. {
  64. url: `http://localhost:${settings.internal.docstore.port}/project/${project_id}/ranges`,
  65. json: true
  66. },
  67. callback
  68. )
  69. },
  70. updateDoc(project_id, doc_id, lines, version, ranges, callback) {
  71. if (callback == null) {
  72. callback = function (error, res, body) {}
  73. }
  74. return request.post(
  75. {
  76. url: `http://localhost:${settings.internal.docstore.port}/project/${project_id}/doc/${doc_id}`,
  77. json: {
  78. lines,
  79. version,
  80. ranges
  81. }
  82. },
  83. callback
  84. )
  85. },
  86. deleteDoc(project_id, doc_id, callback) {
  87. if (callback == null) {
  88. callback = function (error, res, body) {}
  89. }
  90. return request.del(
  91. {
  92. url: `http://localhost:${settings.internal.docstore.port}/project/${project_id}/doc/${doc_id}`
  93. },
  94. callback
  95. )
  96. },
  97. archiveAllDoc(project_id, callback) {
  98. if (callback == null) {
  99. callback = function (error, res, body) {}
  100. }
  101. return request.post(
  102. {
  103. url: `http://localhost:${settings.internal.docstore.port}/project/${project_id}/archive`
  104. },
  105. callback
  106. )
  107. },
  108. destroyAllDoc(project_id, callback) {
  109. if (callback == null) {
  110. callback = function (error, res, body) {}
  111. }
  112. return request.post(
  113. {
  114. url: `http://localhost:${settings.internal.docstore.port}/project/${project_id}/destroy`
  115. },
  116. callback
  117. )
  118. },
  119. getS3Doc(project_id, doc_id, callback) {
  120. if (callback == null) {
  121. callback = function (error, res, body) {}
  122. }
  123. const options = DocArchiveManager.buildS3Options(project_id + '/' + doc_id)
  124. options.json = true
  125. return request.get(options, callback)
  126. }
  127. }