2020-02-17 12:34:21 -05:00
|
|
|
/* eslint-disable
|
|
|
|
camelcase,
|
|
|
|
no-unused-vars,
|
|
|
|
*/
|
|
|
|
// TODO: This file was created by bulk-decaffeinate.
|
|
|
|
// Fix any style issues and re-enable lint.
|
2020-02-17 12:34:04 -05:00
|
|
|
/*
|
|
|
|
* decaffeinate suggestions:
|
|
|
|
* DS102: Remove unnecessary code created because of implicit returns
|
|
|
|
* DS103: Rewrite code to no longer use __guard__
|
|
|
|
* DS207: Consider shorter variations of null checks
|
|
|
|
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
|
|
|
|
*/
|
2020-02-17 12:34:28 -05:00
|
|
|
let UpdateTrimmer
|
|
|
|
const MongoManager = require('./MongoManager')
|
|
|
|
const WebApiManager = require('./WebApiManager')
|
2021-12-14 08:00:35 -05:00
|
|
|
const logger = require('@overleaf/logger')
|
2014-03-28 12:01:34 -04:00
|
|
|
|
2020-02-17 12:34:28 -05:00
|
|
|
module.exports = UpdateTrimmer = {
|
|
|
|
shouldTrimUpdates(project_id, callback) {
|
|
|
|
if (callback == null) {
|
2021-10-27 05:49:18 -04:00
|
|
|
callback = function () {}
|
2020-02-17 12:34:28 -05:00
|
|
|
}
|
2021-07-13 07:04:43 -04:00
|
|
|
return MongoManager.getProjectMetaData(
|
|
|
|
project_id,
|
|
|
|
function (error, metadata) {
|
|
|
|
if (error != null) {
|
|
|
|
return callback(error)
|
|
|
|
}
|
|
|
|
if (metadata != null ? metadata.preserveHistory : undefined) {
|
|
|
|
return callback(null, false)
|
|
|
|
} else {
|
|
|
|
return WebApiManager.getProjectDetails(
|
|
|
|
project_id,
|
|
|
|
function (error, details) {
|
|
|
|
if (error != null) {
|
|
|
|
return callback(error)
|
|
|
|
}
|
2022-05-16 08:38:18 -04:00
|
|
|
logger.debug({ project_id, details }, 'got details')
|
2021-07-13 07:04:43 -04:00
|
|
|
if (
|
|
|
|
__guard__(
|
|
|
|
details != null ? details.features : undefined,
|
|
|
|
x => x.versioning
|
|
|
|
)
|
|
|
|
) {
|
|
|
|
return MongoManager.setProjectMetaData(
|
|
|
|
project_id,
|
|
|
|
{ preserveHistory: true },
|
|
|
|
function (error) {
|
|
|
|
if (error != null) {
|
|
|
|
return callback(error)
|
|
|
|
}
|
|
|
|
return MongoManager.upgradeHistory(
|
|
|
|
project_id,
|
|
|
|
function (error) {
|
|
|
|
if (error != null) {
|
|
|
|
return callback(error)
|
|
|
|
}
|
|
|
|
return callback(null, false)
|
|
|
|
}
|
|
|
|
)
|
2020-02-17 12:34:28 -05:00
|
|
|
}
|
2021-07-13 07:04:43 -04:00
|
|
|
)
|
|
|
|
} else {
|
|
|
|
return callback(null, true)
|
2020-02-17 12:34:28 -05:00
|
|
|
}
|
2021-07-13 07:04:43 -04:00
|
|
|
}
|
|
|
|
)
|
|
|
|
}
|
2020-02-17 12:34:28 -05:00
|
|
|
}
|
2021-07-13 07:04:43 -04:00
|
|
|
)
|
|
|
|
},
|
2020-02-17 12:34:28 -05:00
|
|
|
}
|
2020-02-17 12:34:04 -05:00
|
|
|
|
|
|
|
function __guard__(value, transform) {
|
2020-02-17 12:34:28 -05:00
|
|
|
return typeof value !== 'undefined' && value !== null
|
|
|
|
? transform(value)
|
|
|
|
: undefined
|
|
|
|
}
|