Functions for communicating with the Google Drive API. This file abstracts just the few key ways that Lurch wants to talk to a user's Google Drive, plus the few Google-owned popup windows that may need to be presented, and exposes them in a small API that makes it easier than making raw gapi calls.
The app will not import this module directly, but will instead import the Google Drive UI module, which uses this one under the hood.
Source
Methods
listFilesFromFolder(folderId) → {Promise}
This function retrieves a list of all files in a given Google Drive folder that are of the MIME type used by this app (text/html). The files may be fetched in multiple pages, but this function fetches all necessary pages and passes the concatenated files list to its promise resolution function.
Parameters
-
folderId
string
the folder whose contents should be listed
Returns
-
Promise
a promise that resolves when the full list of files has been fetched, passing the array of filenames to the resolve function, or rejects if an error occurs during the reading process
Source
readFileFromDrive(fileId) → {Promise}
Read a file from the current user's Google Drive. The client must pass a file ID, which can be obtained by allowing the user to select a file from their drive, using a function such as showOpenFilePicker().
Parameters
-
fileId
string
a file ID from Google Drive
Returns
-
Promise
a promise that resolves if the file can be read, passing a response object whose
body
field contains the file's contents, or that rejects if the file cannot be read
Source
showOpenFilePicker() → {Promise}
Show the user a file picker designed by Google, showing all text/html files in their Google Drive. The user may navigate among folders to choose files. If they select one, the resulting promise resolves with that file's ID.
See
- showFileOpenDialog()
- showSaveFolderPicker()
- readFileFromDrive()
Returns
-
Promise
a promise that resolves with the selected file ID if the user chooses one, or never resolves if they cancel
Source
showSaveFolderPicker() → {Promise}
Show the user a folder picker designed by Google, allowing the user to pick a folder (other than the root folder) from their Google Drive.
See
- showOpenFilePicker()
- showFileOpenDialog()
- writeNewFileToDrive()
Returns
-
Promise
a promise that resolves with the selected folder ID if the user chooses one, or never resolves if they cancel
Source
updateFileInDrive(filename, folderId, content) → {Promise}
Update an existing file in the user's Google Drive by replacing its old content with new content. The client must pass a file ID plus the new content to put into the file. To get a file ID, use a function such as showOpenFilePicker().
If you want to create a new file, use writeNewFileToDrive() instead.
This function always creates files with MIME type text/html, because that is the MIME type we are currently using for files created by the Lurch app.
Parameters
-
filename
string
the name of the new file to create
-
folderId
string
a folder ID from Google Drive
-
content
string
the data to write into the new file
Returns
-
Promise
a promise that resolves once the file is created, or rejects with an error message if the write attempt fails
Source
writeNewFileToDrive(filename, folderId, content) → {Promise}
Write a new file to the current user's Google Drive. The client must pass a filename and folder ID, along with the content they want in the file. Note that in Google Drive, unlike many filesystems, you can have multiple files with the same name in the same folder, so this function always creates a new file. To get a folder ID, use a function such as showSaveFolderPicker()
If you want to update/overwrite an existing file, use updateFileInDrive() instead.
This function always creates files with MIME type text/html, because that is the MIME type we are currently using for files created by the Lurch app.
Parameters
-
filename
string
the name of the new file to create
-
folderId
string
a folder ID from Google Drive
-
content
string
the data to write into the new file
Returns
-
Promise
a promise that resolves once the file is created, or rejects with an error message if the write attempt fails