Google Drive
The google-drive module lets editors search and import files from a linked Google Drive account through Brightspot's federated search, and can keep an imported file in sync with later changes in Drive.
Dependencies
Depends on db-http, Google's Drive API v3 client (com.google.apis:google-api-services-drive), and Google's OAuth2 client libraries for per-user account linking.
Installation
- Maven
- Gradle
- Gradle (Kotlin DSL)
<!-- Requires Brightspot 5.0 or later. -->
<dependency>
<groupId>com.brightspot.dbhttp</groupId>
<artifactId>google-drive</artifactId>
<version>1.0.0</version>
</dependency>
// Requires Brightspot 5.0 or later.
implementation 'com.brightspot.dbhttp:google-drive:1.0.0'
// Requires Brightspot 5.0 or later.
implementation("com.brightspot.dbhttp:google-drive:1.0.0")
API reference
com.psddev.google.drive.GoogleDriveDatabase
Extends HttpDatabase. Excludes folders from both keyword search and the default (no-keyword) browse listing, so an editor can never select a folder as if it were a file. Keyword search uses Drive's full-text query syntax; the no-keyword browse listing supports sorting by name or last-modified date (sorting isn't available together with a keyword, per Google's API).
com.psddev.google.drive.GoogleDriveFile
Extends GoogleExternalItem.
| Field | Type | Description |
|---|---|---|
name | String | The file name. |
fileId | String | The Google Drive file Id. |
description | String | The file description. |
originalFilename | String | The original uploaded file name. |
size | Long | The file size in bytes. |
ownedByMe | Boolean | Whether the linked account owns the file. |
createdTime | Date | When the file was created in Drive. |
modifiedByMe | Boolean | Whether the linked account was the last to modify the file. |
modifiedByMeTime | Date | When the linked account last modified the file. |
modifiedTime | Date | When the file was last modified in Drive. |
lastModifiedBy | String | Who last modified the file in Drive. |
fileExtension | String | The file extension. |
fullFileExtension | String | The full (possibly multi-part) file extension. |
kind | String | The Drive API resource kind. |
mimeType | String | The file's MIME type. |
fileType | String | A human-readable file type label derived from mimeType. |
trashed | Boolean | Whether the file is in the Drive trash. |
trashedTime | Date | When the file was trashed. |
trashingUser | String | Who trashed the file. |
webContentLink | String | A direct download link. |
webViewLink | String | A link to view the file in Drive. |
owners | List<String> | The file's owners in Drive. |
Configuration
The OAuth2 client Id and secret are stored on GoogleDriveSettings, a Modification<CmsTool> shown under Site Settings > Integrations > Google. Each editor additionally links their own Google account before they can search Google Drive.
Registering the OAuth redirect URI in the Google Developer Console is required before linking works. The redirect URI is https://<your-brightspot-host>/googleDriveAuth.
Extending the plugin
The module doesn't ship a content type for imported files. To let editors create a local content record from search results, define a content type and extend UpdatableExternalItemConverter<GoogleDriveFile, T>, implementing both convert (to create the record on import) and update (to apply changes from Drive to an existing record).
Implementing update also enables sync: GoogleDriveSyncable compares the source file's modified time against the time it was last imported, and if the record's content type implements GoogleDriveSyncable, an editor can re-import it—producing a draft with the differences if the record is published, or updating it directly otherwise.