diff --git a/src/services/providers/googleDriveProvider.js b/src/services/providers/googleDriveProvider.js index df5d5418..c747bfb0 100644 --- a/src/services/providers/googleDriveProvider.js +++ b/src/services/providers/googleDriveProvider.js @@ -127,6 +127,7 @@ export default providerRegistry.register({ providerUtils.serializeContent(content), undefined, syncLocation.driveFileId, + undefined, ifNotTooLate, ) .then(driveFile => ({ diff --git a/src/services/providers/googleDriveWorkspaceProvider.js b/src/services/providers/googleDriveWorkspaceProvider.js index 8356f2b2..7fcf5d17 100644 --- a/src/services/providers/googleDriveWorkspaceProvider.js +++ b/src/services/providers/googleDriveWorkspaceProvider.js @@ -260,7 +260,7 @@ export default providerRegistry.register({ // If change is on a data item if (change.file.parents[0] === workspace.dataFolderId) { - // Data item has a JSON as a filename + // Data item has a JSON filename try { change.item = JSON.parse(change.file.name); } catch (e) { @@ -316,6 +316,7 @@ export default providerRegistry.register({ // Build sync data change.syncData = { id: change.fileId, + parentIds: change.file.parents, itemId: change.item.id, type: change.item.type, hash: change.item.hash, @@ -363,6 +364,7 @@ export default providerRegistry.register({ undefined, undefined, syncData && syncData.id, + syncData && syncData.parentIds, ifNotTooLate, ); } @@ -379,6 +381,7 @@ export default providerRegistry.register({ undefined, item.type === 'folder' ? googleHelper.folderMimeType : undefined, syncData && syncData.id, + syncData && syncData.parentIds, ifNotTooLate, ); }) @@ -464,6 +467,7 @@ export default providerRegistry.register({ providerUtils.serializeContent(content), undefined, syncData.id, + undefined, ifNotTooLate, ); } @@ -483,6 +487,7 @@ export default providerRegistry.register({ providerUtils.serializeContent(content), undefined, undefined, + undefined, ifNotTooLate, ) .then((file) => { @@ -529,6 +534,7 @@ export default providerRegistry.register({ JSON.stringify(item), undefined, syncData && syncData.id, + syncData && syncData.parentIds, ifNotTooLate, ) .then(file => store.dispatch('data/patchSyncData', { diff --git a/src/services/providers/helpers/googleHelper.js b/src/services/providers/helpers/googleHelper.js index 3efafb96..83119d91 100644 --- a/src/services/providers/helpers/googleHelper.js +++ b/src/services/providers/helpers/googleHelper.js @@ -74,6 +74,7 @@ export default { media = null, mediaType = null, fileId = null, + oldParents = null, ifNotTooLate = cb => res => cb(res), ) { return Promise.resolve() @@ -83,12 +84,22 @@ export default { method: 'POST', url: 'https://www.googleapis.com/drive/v3/files', }; + const params = { + supportsTeamDrives: true, + }; const metadata = { name, appProperties }; if (fileId) { options.method = 'PATCH'; options.url = `https://www.googleapis.com/drive/v3/files/${fileId}`; + if (parents && oldParents) { + params.addParents = parents + .filter(parent => oldParents.indexOf(parent) === -1) + .join(','); + params.removeParents = oldParents + .filter(parent => parents.indexOf(parent) === -1) + .join(','); + } } else if (parents) { - // Parents field is not patchable metadata.parents = parents; } if (media) { @@ -109,8 +120,8 @@ export default { return this.request(refreshedToken, { ...options, params: { + ...params, uploadType: 'multipart', - supportsTeamDrives: true, }, headers: { 'Content-Type': `multipart/mixed; boundary="${boundary}"`, @@ -124,9 +135,7 @@ export default { return this.request(refreshedToken, { ...options, body: metadata, - params: { - supportsTeamDrives: true, - }, + params, }).then(res => res.body); })); }, @@ -399,7 +408,17 @@ export default { return getPage(startPageToken); }); }, - uploadFile(token, name, parents, appProperties, media, mediaType, fileId, ifNotTooLate) { + uploadFile( + token, + name, + parents, + appProperties, + media, + mediaType, + fileId, + oldParents, + ifNotTooLate, + ) { return this.refreshToken(token, getDriveScopes(token)) .then(refreshedToken => this.uploadFileInternal( refreshedToken, @@ -409,6 +428,7 @@ export default { media, mediaType, fileId, + oldParents, ifNotTooLate, )); }, @@ -422,6 +442,7 @@ export default { media, undefined, fileId, + undefined, ifNotTooLate, )); },