[web+document-updater] Allow appending to documents (#20745)

Co-authored-by: David Powell <david.powell@overleaf.com>
GitOrigin-RevId: f66283926e7da3edf83ada9316c3a001287e1b42
This commit is contained in:
Mathias Jakobsen
2024-12-12 09:05:31 +00:00
committed by Copybot
co-authored by David Powell
parent 52254b5695
commit 1063dabf33
11 changed files with 649 additions and 12 deletions
@@ -144,6 +144,7 @@ function setDoc(req, res, next) {
source,
userId,
undoing,
true,
(error, result) => {
timer.done()
if (error) {
@@ -155,6 +156,35 @@ function setDoc(req, res, next) {
)
}
function appendToDoc(req, res, next) {
const docId = req.params.doc_id
const projectId = req.params.project_id
const { lines, source, user_id: userId } = req.body
const timer = new Metrics.Timer('http.appendToDoc')
DocumentManager.appendToDocWithLock(
projectId,
docId,
lines,
source,
userId,
(error, result) => {
timer.done()
if (error instanceof Errors.FileTooLargeError) {
logger.warn('refusing to append to file, it would become too large')
return res.sendStatus(422)
}
if (error) {
return next(error)
}
logger.debug(
{ projectId, docId, lines, source, userId },
'appending to doc via http'
)
res.json(result)
}
)
}
function flushDocIfLoaded(req, res, next) {
const docId = req.params.doc_id
const projectId = req.params.project_id
@@ -460,6 +490,7 @@ module.exports = {
peekDoc,
getProjectDocsAndFlushIfOld,
clearProjectState,
appendToDoc,
setDoc,
flushDocIfLoaded,
deleteDoc,