HistoryStoreClient.js 1.1 KB

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