ClsiStateManager.coffee 995 B

123456789101112131415161718192021222324252627
  1. Settings = require "settings-sharelatex"
  2. logger = require "logger-sharelatex"
  3. crypto = require "crypto"
  4. # The "state" of a project is a hash of the relevant attributes in the
  5. # project object in this case we only need the rootFolder.
  6. #
  7. # The idea is that it will change if any doc or file is
  8. # created/renamed/deleted, and also if the content of any file (not
  9. # doc) changes.
  10. #
  11. # When the hash changes the full set of files on the CLSI will need to
  12. # be updated. If it doesn't change then we can overwrite changed docs
  13. # in place on the clsi, getting them from the docupdater.
  14. #
  15. # The docupdater is responsible for setting the key in redis, and
  16. # unsetting it if it removes any documents from the doc updater.
  17. buildState = (project) ->
  18. json = JSON.stringify(project.rootFolder)
  19. return crypto.createHash('sha1').update(json, 'utf8').digest('hex')
  20. module.exports = ClsiStateManager =
  21. computeHash: (project, callback = (err, hash) ->) ->
  22. hash = buildState(project)
  23. callback(null, hash)