From 183d455f06de8e690bf73fdba1a9db05b41c9173 Mon Sep 17 00:00:00 2001 From: tonyOreglia Date: Tue, 11 Jul 2017 17:10:27 +1000 Subject: [PATCH 1/6] Update upload.js added the key supportsTeamDrives: True --- lib/commands/upload.js | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/commands/upload.js b/lib/commands/upload.js index 21c53b5..8cdd12d 100755 --- a/lib/commands/upload.js +++ b/lib/commands/upload.js @@ -42,6 +42,7 @@ function sendToGoogle(files, id) { var drive = google.drive({ version: 'v2', auth: auth }); var options = { fileId: id, + supportsTeamDrives: true, media: { mimeType: 'application/vnd.google-apps.script+json', body: JSON.stringify({ files: files }) From 1c33a73d0e9b041b3aff3de26db2f0a2b06cfa1d Mon Sep 17 00:00:00 2001 From: tonyOreglia Date: Tue, 11 Jul 2017 17:28:00 +1000 Subject: [PATCH 2/6] Update gapps add teamdrive option --- bin/gapps | 1 + 1 file changed, 1 insertion(+) diff --git a/bin/gapps b/bin/gapps index d340154..cc2e772 100755 --- a/bin/gapps +++ b/bin/gapps @@ -24,6 +24,7 @@ program program .command('upload') + .option('-t, --teamdrive') .description('Upload back to an Apps Script project in Google Drive. Run from root of project directory') .alias('push') .action(require(commands + '/upload')); From 5d9a3f0faa978d36f04c32a27c920f1c1211b9bc Mon Sep 17 00:00:00 2001 From: tonyOreglia Date: Tue, 11 Jul 2017 17:55:57 +1000 Subject: [PATCH 3/6] Update README.md --- README.md | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/README.md b/README.md index 80f7396..c0aa785 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,25 @@ +The branch works for scripts sitting in a Team Drive by adding the parameter supportsTeamDrives to the upload request. + +* Moving the script to a team drive causes https://github.com/danthareja/node-google-apps-script to fail uploading +* This may be because the update command wants a parameter `supportTeamDrives` set to true, see https://developers.google.com/apis-explorer/?hl=en_US#p/drive/v3/drive.files.update and https://developers.google.com/drive/v3/reference/files/update +* https://developers.google.com/drive/v3/web/enable-teamdrives : “If your application isn't affected by the behavioral differences, then you only need to include thesupportsTeamDrives=true query parameter in requests. This is an acknowledgement that the application is aware of behavioral differences of files contained in Team Drives.” +* Adding `supportsTeamDrives: true` to + ```return authenticate() + .then(function(auth) { + var drive = google.drive({ version: 'v2', auth: auth }); + var options = { + fileId: id, + supportsTeamDrives: true, + media: { + mimeType: 'application/vnd.google-apps.script+json', + body: JSON.stringify({ files: files }) + } + }; +``` +fixes the problem for a team drive + + + # gapps (Google Apps Script) >The easiest way to develop Google Apps Script projects From e3875cd619b7a92fa72616f1d1157847ea3ae663 Mon Sep 17 00:00:00 2001 From: tonyOreglia Date: Tue, 11 Jul 2017 17:58:23 +1000 Subject: [PATCH 4/6] Update README.md --- README.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/README.md b/README.md index c0aa785..fd0861a 100644 --- a/README.md +++ b/README.md @@ -14,8 +14,7 @@ The branch works for scripts sitting in a Team Drive by adding the parameter sup mimeType: 'application/vnd.google-apps.script+json', body: JSON.stringify({ files: files }) } - }; -``` + }; ``` fixes the problem for a team drive From f85070523834a7c3f86188d20ef4a67be2ffdb4f Mon Sep 17 00:00:00 2001 From: tonyOreglia Date: Tue, 11 Jul 2017 17:58:57 +1000 Subject: [PATCH 5/6] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index fd0861a..f72887a 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ The branch works for scripts sitting in a Team Drive by adding the parameter supportsTeamDrives to the upload request. * Moving the script to a team drive causes https://github.com/danthareja/node-google-apps-script to fail uploading -* This may be because the update command wants a parameter `supportTeamDrives` set to true, see https://developers.google.com/apis-explorer/?hl=en_US#p/drive/v3/drive.files.update and https://developers.google.com/drive/v3/reference/files/update +* This is because the update command wants a parameter `supportTeamDrives` set to true, see https://developers.google.com/apis-explorer/?hl=en_US#p/drive/v3/drive.files.update and https://developers.google.com/drive/v3/reference/files/update * https://developers.google.com/drive/v3/web/enable-teamdrives : “If your application isn't affected by the behavioral differences, then you only need to include thesupportsTeamDrives=true query parameter in requests. This is an acknowledgement that the application is aware of behavioral differences of files contained in Team Drives.” * Adding `supportsTeamDrives: true` to ```return authenticate() From 2c02460e35b2b3e331b0db8ebe0da9b54206ce64 Mon Sep 17 00:00:00 2001 From: Tony Oreglia Date: Thu, 21 Sep 2017 09:49:37 +1000 Subject: [PATCH 6/6] added --teamdrive option --- bin/gapps | 1 + lib/commands/upload.js | 15 ++++++++++----- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/bin/gapps b/bin/gapps index d340154..cc2e772 100755 --- a/bin/gapps +++ b/bin/gapps @@ -24,6 +24,7 @@ program program .command('upload') + .option('-t, --teamdrive') .description('Upload back to an Apps Script project in Google Drive. Run from root of project directory') .alias('push') .action(require(commands + '/upload')); diff --git a/lib/commands/upload.js b/lib/commands/upload.js index 8cdd12d..5441111 100755 --- a/lib/commands/upload.js +++ b/lib/commands/upload.js @@ -7,7 +7,8 @@ var defaults = require('../defaults'); var manifestor = require('../manifestor'); var authenticate = require('../authenticate'); -module.exports = function upload() { +module.exports = function upload(options) { + // console.log(options) console.log('Pushing back up to Google Drive...'); var fileId; // Hold in closure to avoid promise nesting @@ -21,7 +22,7 @@ module.exports = function upload() { return manifestor.build(externalFiles); }) .then(function(files) { - return sendToGoogle(files, fileId); + return sendToGoogle(files, fileId, options.teamdrive); }) .then(function() { console.log('The latest files were successfully uploaded to your Apps Script project.'.green); @@ -31,7 +32,7 @@ module.exports = function upload() { }); }; -function sendToGoogle(files, id) { +function sendToGoogle(files, id, supportsTeamDrives) { if (!files.length) { console.log('No Files to upload.'.red); throw 'manifest file length is 0'; @@ -39,16 +40,20 @@ function sendToGoogle(files, id) { return authenticate() .then(function(auth) { - var drive = google.drive({ version: 'v2', auth: auth }); var options = { fileId: id, - supportsTeamDrives: true, media: { mimeType: 'application/vnd.google-apps.script+json', body: JSON.stringify({ files: files }) } }; + if (supportsTeamDrives) { + console.log('teamdrive=true') + options.supportsTeamDrives = true; + } + + var drive = google.drive({ version: 'v2', auth: auth }); return Promise.promisify(drive.files.update)(options) .catch(function(err) { console.log('An error occured while running upload command: '.red + err.message);