mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-11-15 06:33:55 +01:00
Accept ordered doc and file updates
Add an `updates` parameter to the project update endpoint. It can be used instead of `docUpdates` and `fileUpdates` to provide a single list of updates in the order they should be processed.
This commit is contained in:
@@ -330,19 +330,23 @@ function updateProject(req, res, next) {
|
||||
userId,
|
||||
docUpdates,
|
||||
fileUpdates,
|
||||
updates,
|
||||
version
|
||||
} = req.body
|
||||
logger.log(
|
||||
{ projectId, docUpdates, fileUpdates, version },
|
||||
{ projectId, updates, docUpdates, fileUpdates, version },
|
||||
'updating project via http'
|
||||
)
|
||||
|
||||
const allUpdates = _mergeUpdates(
|
||||
docUpdates || [],
|
||||
fileUpdates || [],
|
||||
updates || []
|
||||
)
|
||||
ProjectManager.updateProjectWithLocks(
|
||||
projectId,
|
||||
projectHistoryId,
|
||||
userId,
|
||||
docUpdates,
|
||||
fileUpdates,
|
||||
allUpdates,
|
||||
version,
|
||||
(error) => {
|
||||
timer.done()
|
||||
@@ -412,3 +416,23 @@ function flushQueuedProjects(req, res, next) {
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Merge updates from the previous project update interface (docUpdates +
|
||||
* fileUpdates) and the new update interface (updates).
|
||||
*/
|
||||
function _mergeUpdates(docUpdates, fileUpdates, updates) {
|
||||
const mergedUpdates = []
|
||||
for (const update of docUpdates) {
|
||||
const type = update.docLines != null ? 'add-doc' : 'rename-doc'
|
||||
mergedUpdates.push({ type, ...update })
|
||||
}
|
||||
for (const update of fileUpdates) {
|
||||
const type = update.url != null ? 'add-file' : 'rename-file'
|
||||
mergedUpdates.push({ type, ...update })
|
||||
}
|
||||
for (const update of updates) {
|
||||
mergedUpdates.push(update)
|
||||
}
|
||||
return mergedUpdates
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user