mirror of
https://github.com/overleaf/overleaf.git
synced 2025-04-15 10:06:55 +00:00
Merge pull request #9587 from overleaf/em-dropbox-to-overleaf
Record metadata on Dropbox-to-Overleaf updates GitOrigin-RevId: 34eb774a52d1c683fb1dddecc1c4c646bfc9eb2e
This commit is contained in:
parent
73e8fd115b
commit
76e0265ed7
5 changed files with 48 additions and 16 deletions
|
@ -213,7 +213,7 @@ const EditorController = {
|
|||
userId
|
||||
)
|
||||
}
|
||||
callback(null, doc)
|
||||
callback(null, { doc, folder: lastFolder })
|
||||
}
|
||||
)
|
||||
}
|
||||
|
@ -273,7 +273,7 @@ const EditorController = {
|
|||
linkedFileData,
|
||||
userId
|
||||
)
|
||||
callback(null, newFile)
|
||||
callback(null, { file: newFile, folder: lastFolder })
|
||||
}
|
||||
)
|
||||
}
|
||||
|
|
|
@ -55,9 +55,13 @@ async function mergeUpdate(req, res) {
|
|||
status: 'applied',
|
||||
entityId: metadata.entityId.toString(),
|
||||
entityType: metadata.entityType,
|
||||
folderId: metadata.folderId.toString(),
|
||||
}
|
||||
|
||||
// When the update is a doc edit, the update is merged in docupdater and
|
||||
// doesn't generate a new rev.
|
||||
if (metadata.rev != null) {
|
||||
payload.rev = metadata.rev
|
||||
payload.rev = metadata.rev.toString()
|
||||
}
|
||||
res.json(payload)
|
||||
}
|
||||
|
|
|
@ -75,15 +75,33 @@ async function _mergeUpdate(userId, projectId, path, fsPath, source) {
|
|||
const fileType = await _determineFileType(projectId, path, fsPath)
|
||||
|
||||
if (fileType === 'file') {
|
||||
const file = await _processFile(projectId, fsPath, path, source, userId)
|
||||
return { entityType: 'file', entityId: file._id, rev: file.rev }
|
||||
const { file, folder } = await _processFile(
|
||||
projectId,
|
||||
fsPath,
|
||||
path,
|
||||
source,
|
||||
userId
|
||||
)
|
||||
return {
|
||||
entityType: 'file',
|
||||
entityId: file._id,
|
||||
rev: file.rev,
|
||||
folderId: folder._id,
|
||||
}
|
||||
} else if (fileType === 'doc') {
|
||||
const doc = await _processDoc(projectId, userId, fsPath, path, source)
|
||||
// The doc entry doesn't have a rev. Since the document is set in
|
||||
// docupdater, it's possible that the next rev contains a merge of changes
|
||||
// in Dropbox and changes from docupdater.
|
||||
const metadata = { entityType: 'doc', entityId: doc._id, rev: doc.rev }
|
||||
return metadata
|
||||
const { doc, folder } = await _processDoc(
|
||||
projectId,
|
||||
userId,
|
||||
fsPath,
|
||||
path,
|
||||
source
|
||||
)
|
||||
return {
|
||||
entityType: 'doc',
|
||||
entityId: doc._id,
|
||||
rev: doc.rev,
|
||||
folderId: folder._id,
|
||||
}
|
||||
} else {
|
||||
throw new Error('unrecognized file')
|
||||
}
|
||||
|
@ -119,7 +137,7 @@ async function _processDoc(projectId, userId, fsPath, path, source) {
|
|||
}
|
||||
|
||||
async function _processFile(projectId, fsPath, path, source, userId) {
|
||||
const file = await EditorController.promises.upsertFileWithPath(
|
||||
const { file, folder } = await EditorController.promises.upsertFileWithPath(
|
||||
projectId,
|
||||
path,
|
||||
fsPath,
|
||||
|
@ -127,7 +145,7 @@ async function _processFile(projectId, fsPath, path, source, userId) {
|
|||
source,
|
||||
userId
|
||||
)
|
||||
return file
|
||||
return { file, folder }
|
||||
}
|
||||
|
||||
async function _readFileIntoTextArray(path) {
|
||||
|
|
|
@ -11,6 +11,7 @@ describe('TpdsController', function () {
|
|||
beforeEach(function () {
|
||||
this.metadata = {
|
||||
entityId: ObjectId(),
|
||||
folderId: ObjectId(),
|
||||
entityType: 'doc',
|
||||
rev: 2,
|
||||
}
|
||||
|
@ -69,8 +70,9 @@ describe('TpdsController', function () {
|
|||
expect(payload).to.deep.equal({
|
||||
status: 'applied',
|
||||
entityId: this.metadata.entityId.toString(),
|
||||
folderId: this.metadata.folderId.toString(),
|
||||
entityType: this.metadata.entityType,
|
||||
rev: this.metadata.rev,
|
||||
rev: this.metadata.rev.toString(),
|
||||
})
|
||||
this.TpdsUpdateHandler.promises.newUpdate
|
||||
.calledWith(
|
||||
|
|
|
@ -49,11 +49,19 @@ describe('UpdateMerger :', function () {
|
|||
rev: 6,
|
||||
}
|
||||
|
||||
this.folder = {
|
||||
_id: ObjectId(),
|
||||
}
|
||||
|
||||
this.EditorController = {
|
||||
promises: {
|
||||
deleteEntityWithPath: sinon.stub().resolves(),
|
||||
upsertDocWithPath: sinon.stub().resolves(this.doc),
|
||||
upsertFileWithPath: sinon.stub().resolves(this.file),
|
||||
upsertDocWithPath: sinon
|
||||
.stub()
|
||||
.resolves({ doc: this.doc, folder: this.folder }),
|
||||
upsertFileWithPath: sinon
|
||||
.stub()
|
||||
.resolves({ file: this.file, folder: this.folder }),
|
||||
},
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue