overleaf/services/track-changes/app/coffee/DocArchiveManager.coffee

47 lines
1.5 KiB
CoffeeScript
Raw Normal View History

2015-08-06 10:11:43 -04:00
MongoManager = require "./MongoManager"
2015-08-06 14:46:44 -04:00
MongoAWS = require "./MongoAWS"
2015-08-06 10:11:43 -04:00
logger = require "logger-sharelatex"
_ = require "underscore"
async = require "async"
settings = require("settings-sharelatex")
request = require("request")
crypto = require("crypto")
thirtySeconds = 30 * 1000
module.exports = DocArchiveManager =
archiveAllDocsChanges: (project_id, callback = (error, docs) ->) ->
MongoManager.getProjectsDocs project_id, (error, docs) ->
if error?
return callback(error)
else if !docs?
return callback new Error("No docs for project #{project_id}")
jobs = _.map docs, (doc) ->
(cb)-> DocArchiveManager.archiveDocChanges project_id, doc._id, cb
async.series jobs, callback
archiveDocChanges: (project_id, doc_id, callback)->
2015-08-06 16:09:36 -04:00
MongoManager.getDocChangesCount doc_id, (error, count) ->
if count == 0
callback()
else
MongoAWS.archiveDocHistory project_id, doc_id, (error) ->
logger.log doc_id:doc_id, error: error, "mongoexport"
callback()
unArchiveAllDocsChanges: (project_id, callback = (error, docs) ->) ->
MongoManager.getProjectsDocs project_id, (error, docs) ->
if error?
return callback(error)
else if !docs?
return callback new Error("No docs for project #{project_id}")
jobs = _.map docs, (doc) ->
(cb)-> DocArchiveManager.unArchiveDocChanges project_id, doc._id, cb
async.series jobs, callback
unArchiveDocChanges: (project_id, doc_id, callback)->
MongoAWS.unArchiveDocHistory project_id, doc_id, (error) ->
logger.log doc_id:doc_id, error: error, "mongoimport"
callback()