diff --git a/picker/code.gs b/picker/code.gs index 3346d4214..3c0c363a4 100644 --- a/picker/code.gs +++ b/picker/code.gs @@ -36,11 +36,18 @@ function showPicker() { .setSandboxMode(HtmlService.SandboxMode.IFRAME); SpreadsheetApp.getUi().showModalDialog(html, "Select a file"); } +// Ensure the Drive API is enabled. +if (!Drive) { + throw new Error('Please enable the Drive advanced service.'); +} + /** * Checks that the file can be accessed. + * @param {string} fileId The ID of the file. + * @return {Object} The file resource. */ function getFile(fileId) { - return Drive.Files.get(fileId, { fields: "*" }); + return Drive.Files.get(fileId, {fields: '*'}); } /** diff --git a/picker/dialog.html b/picker/dialog.html index 9d85af9eb..a694d015e 100644 --- a/picker/dialog.html +++ b/picker/dialog.html @@ -109,12 +109,27 @@ } } + /** + * @typedef {Object} PickerResponse + * @property {string} action + * @property {PickerDocument[]} docs + */ + + /** + * @typedef {Object} PickerDocument + * @property {string} id + * @property {string} name + * @property {string} mimeType + * @property {string} url + * @property {string} lastEditedUtc + */ + /** * A callback function that extracts the chosen document's metadata from the * response object. For details on the response object, see * https://developers.google.com/picker/reference/picker.responseobject * - * @param {object} data The response object. + * @param {PickerResponse} data The response object. */ function pickerCallback(data) { const action = data[google.picker.Response.ACTION]; @@ -128,7 +143,7 @@ /** * Handles `"PICKED"` responsed from the Google Picker. * - * @param {object} data The response object. + * @param {PickerResponse} data The response object. */ function handlePicked(data) { const doc = data[google.picker.Response.DOCUMENTS][0];