diff --git a/README.md b/README.md index 80f7396..f72887a 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,24 @@ +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 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() + .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 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 21c53b5..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,7 +40,6 @@ function sendToGoogle(files, id) { return authenticate() .then(function(auth) { - var drive = google.drive({ version: 'v2', auth: auth }); var options = { fileId: id, media: { @@ -48,6 +48,12 @@ function sendToGoogle(files, id) { } }; + 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);