HistoryStoreClient.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. /* eslint-disable
  2. camelcase,
  3. no-unused-vars,
  4. */
  5. // TODO: This file was created by bulk-decaffeinate.
  6. // Fix any style issues and re-enable lint.
  7. /*
  8. * decaffeinate suggestions:
  9. * DS102: Remove unnecessary code created because of implicit returns
  10. * DS207: Consider shorter variations of null checks
  11. * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
  12. */
  13. import { expect } from 'chai'
  14. import request from 'request'
  15. import Settings from '@overleaf/settings'
  16. export function getLatestContent(ol_project_id, callback) {
  17. if (callback == null) {
  18. callback = function () {}
  19. }
  20. return request.get(
  21. {
  22. url: `${Settings.overleaf.history.host}/projects/${ol_project_id}/latest/content`,
  23. auth: {
  24. user: Settings.overleaf.history.user,
  25. pass: Settings.overleaf.history.pass,
  26. sendImmediately: true,
  27. },
  28. },
  29. (error, res, body) => {
  30. if (res.statusCode < 200 || res.statusCode >= 300) {
  31. callback(
  32. new Error(
  33. `history store a non-success status code: ${res.statusCode}`
  34. )
  35. )
  36. }
  37. return callback(error, JSON.parse(body))
  38. }
  39. )
  40. }